npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ecma-parser-tests

v0.1.9

Published

Test cases for ECMAScript parsers

Downloads

46

Readme

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.

| 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 |

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