
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
ecma-parser-tests
Advanced tools
This repository contains a bunch of ECMAScript tests, copied from the Test262 repo and changed so it can be used together
with any ECMAScript parser.
All tests in this repo are up to date with latest ECMAScript specs (ES2017) and it is parser independent.
Note!! Tests for module code are marked with .module.
| Directory | Description |
|---|---|
pass | Contains syntactically valid ECMAScript programs copied form Test262 repo |
early | Contains programs which match the grammar of ECMAScript but which trigger early errors |
fail | Contains files which do not match the grammar of ECMAScript |
next | Contains Stage 3 proposal tests. Separated from Test262. Each of the tests has three sub-directories - pass, fail, early |
annexb | Contains AnnexB tests. Each of the tests has three sub-directories - pass, fail, early |
One way to get the tests running is to follow the example below. In this example Cherow have been used as the ECMAScript parser, but all parsers should work as long as they support the latest ECMAScript features (ES2017).
Note! It's a quick 5 minutes task to get this tests running on your project, but be aware that you would need to create a whitelist to skip tests that your parser doesn't parse correctly.
import { parseScript} from '../../../src/cherow';
import { readdirSync, readFileSync } from 'fs';
import whitelist from './whitelist'; // Your own whitelist file
import * as t from 'assert';
const EcmaParserTestDir = 'node_modules/ecma-parser-tests';
const parse = (src, module) => (module ? parseModule : parseScript)(src);
const isModule = (val) => /\.module\.js/.test(val);
describe('Test262 Parser tests', () => {
describe('Pass', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/pass`)) {
if (whitelist.pass.indexOf(f) !== -1) continue;
it(`Should pass - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/pass/${f}`, 'utf8');
t.doesNotThrow(() => {
parse(passSrc, isModule(f));
});
});
}
});
describe('Fail', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/fail`)) {
if (whitelist.fail.indexOf(f) !== -1) continue;
it(`Should fail on - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/fail/${f}`, 'utf8');
t.throws(() => {
parse(passSrc, isModule(f));
});
});
}
});
describe('Early errors', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/early`)) {
if (whitelist.early.indexOf(f) !== -1) continue;
const passTestFile = `${EcmaParserTestDir}/early/${f}`;
it(`should fail on early error [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/early/${f}`, 'utf8');
t.throws(() => {
parse(passSrc, isModule(f));
});
});
}
});
describe('AnnexB - Pass', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/annexb/pass`)) {
if (whitelist.annexb_pass.indexOf(f) !== -1) continue;
it(`Should pass - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/annexb/pass/${f}`, 'utf8');
t.doesNotThrow(() => {
parse(passSrc, isModule(f));
});
});
}
});
describe('AnnexB - Fail', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/annexb/fail`)) {
if (whitelist.annexb_fail.indexOf(f) !== -1) continue;
it(`Should fail on - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/annexb/fail/${f}`, 'utf8');
t.throws(() => {
parse(passSrc, isModule(f));
});
});
}
});
describe('Next - Pass', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/next/pass`)) {
if (expectations.next_pass.indexOf(f) !== -1) continue;
it(`Should pass - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/next/pass/${f}`, 'utf8');
t.doesNotThrow(() => {
parse(passSrc, /\.module\.js/.test(f));
});
});
}
});
describe('Next - Fail', () => {
for (const f of readdirSync(`${EcmaParserTestDir}/next/fail`)) {
if (whitelist.next_fail.indexOf(f) !== -1) continue;
it(`Should fail on - [${f}]`, () => {
const passSrc = readFileSync(`${EcmaParserTestDir}/next/fail/${f}`, 'utf8');
t.throws(() => {
parse(passSrc, isModule(f));
});
});
}
});
});
Your whitelist:
export default {
pass: [
'1.js' // skips the first passing test
],
fail: [],
early: [],
annexb_pass: [],
annexb_fail: [],
next_pass: [],
next_fail: []
}
FAQs
Test cases for ECMAScript parsers
We found that ecma-parser-tests demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.