
Research
Two Malicious Rust Crates Impersonate Popular Logger to Steal Wallet Keys
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
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
The npm package ecma-parser-tests receives a total of 2 weekly downloads. As such, ecma-parser-tests popularity was classified as not popular.
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.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.