Home

Awesome

jest-light-runner

A Jest runner that runs tests directly in bare Node.js, without virtualizing the environment.

Comparison with the default Jest runner

This approach is way faster than the default Jest runner (it more than doubled the speed of Babel's tests suite) and has complete support for the Node.js ESM implementation. However, it doesn't provide support for most of Jest's advanced features.

The lists below are not comprehensive: feel free to start a discussion regarding any other missing Jest feature!

Supported Jest features

Unsupported Jest features

Partially supported features

Usage

After installing jest and jest-light-runner, add it to your Jest config.

In package.json:

{
  "jest": {
    "runner": "jest-light-runner"
  }
}

or in jest.config.js:

module.exports = {
  runner: "jest-light-runner",
};

Using custom Node.js ESM loaders

You can specify custom ESM loaders using Node.js's --loader option. Jest's CLI doesn't allow providing Node.js-specific options, but you can do it by using the NODE_OPTIONS environment variable:

NODE_OPTIONS="--loader ts-node/esm" jest

Or, if you are using cross-env to be able to provide environment variables on multiple OSes:

cross-env NODE_OPTIONS="--loader ts-node/esm" jest

Don't run Node.js directly:

node --loader ts-node/esm ./node_modules/.bin/jest

This will result in ERR_UNKNOWN_FILE_EXTENSION, due to the loader argument not being passed to the sub-processes. This is a known limitation, and ts-node documentation recommends using NODE_OPTIONS.

Source maps support

If you are running transpiled code and you want to load their source maps to map errors to the original code, you can install the source-map-support package and add the following to your Jest configuration:

setupFiles: ["source-map-support/register"];

Stability

This project follows semver, and it's currently in the 0.x release line.

It is used to run tests in the babel/babel and prettier/prettier repositories, but there are no internal tests for the runner itself. I would gladly accept a pull requests adding a test infrastructure!

Donations

If you use this package and it has helped with your tests, please consider sponsoring me on GitHub! You can also donate to Jest on their OpenCollective page.