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

test262-to-mjsunit

v1.2.0

Published

Converts test262 tests to mjsunit tests

Downloads

17

Readme

Convert test262 tests to mjsunit format

V8 hasn't quite gotten around to letting its contributors write test262 tests directly, as I found out recently. Instead they prefer to check in tests in their custom mjsunit format.

But what if you've already written a bunch of test262 tests? Or what if you want to be a good citizen and contribute to the general cross-browser testing cause that is test262, and yet you'd like to be able to land features in V8? This project will solve your problems, by converting test262-format tests to mjsunit-format tests destined for V8.

Usage

Pass the tests you'd like to convert to the CLI utility. The resulting mjsunit files will be written to standard out.

$ cd Array.prototype.includes
$ test262-to-mjsunit test/*.js > ../v8/test/mjsunit/array-includes.js

Fail-Hard

By default, if test262-to-mjsunit can't convert something, it will output a comment block with an error:

// !!! Test failed to convert:
// Cannot convert negative tests.
// !!!

If you'd rather have it fail, pass the --fail-hard option.

Flags

If you're testing a feature that needs a given V8 flag to run, use the --flags option to make the converter output the appropriate comment:

$ test262-to-mjsunit --flags="--harmony-array-includes" test/*.js > ../v8/test/mjsunit/array-includes.js

Conversion Details

Per-Test Changes

The process of converting to mjsunit consists of these steps:

First, test262-to-mjsunit removes the copyright header and YAML frontmatter. It reuses the description key from the frontmatter to build a header comment for the test.

Then, it wraps the test body in an IIFE.

If the test has the onlyStrict flag set, it prepends "use strict"; to the test body (inside the IIFE).

If the test includes Test262Error.js, it prepends a quick function Test262Error() {}. (This ensures that any assert.throws that are converted to assertThrows work correctly.)

Next, it performs a series of substitutions on the test body (done at the abstract syntax-tree level, so it should be fairly robust):

Finally, it reformats the test to be two-space indents, double quotes, and whatever else Recast does with its default pretty-printer.

Unsupported features

Although there are presumably many features of test262 tests that this converter doesn't yet support, two are caught explicitly as early errors: negative tests and tests that include other files. Both of these are detected via the YAML frontmatter.

If either of these features is used in a test, the resulting output will be a three-line comment with an appropriate error message. For example:

// !!! Test failed to convert:
// Cannot convert tests with includes.
// !!!

(However, there is one exception to the no-includes rule: Test262Error.js, as noted above.)

You can bypass the check for includes via the --ignore-includes option. Presumably in this case you're planning to supply the relevant includes by manually editing the output.

Aggregation

Each test is processed separately according to the above process. Then, they are stitched together with double-newlines between them. The appropriate V8 copyright header is added to the top of the output, and if specified, the appropriate V8 flags comment is added below that.