Socket
Book a DemoInstallSign in
Socket

ecma-parser-tests

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ecma-parser-tests

Test cases for ECMAScript parsers

latest
Source
npmnpm
Version
0.1.9
Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

ECMA-262 Parser Tests

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.

DirectoryDescription
passContains syntactically valid ECMAScript programs copied form Test262 repo
earlyContains programs which match the grammar of ECMAScript but which trigger early errors
failContains files which do not match the grammar of ECMAScript
nextContains Stage 3 proposal tests. Separated from Test262. Each of the tests has three sub-directories - pass, fail, early
annexbContains AnnexB tests. Each of the tests has three sub-directories - pass, fail, early

Configure

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: []
}

Keywords

test262

FAQs

Package last updated on 23 Nov 2017

Did you know?

Socket

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.

Install

Related posts