package
A simple way of creating a Jest runner
npm install create-jest-runnerGitHub-flavored package documentation.
Across all versions, last 30 days.
870,356 in 30 days
Runtime metadata.
A highly opinionated way for creating Jest Runners
yarn add create-jest-runnercreate-jest-runner takes care of handling the appropriate parallelization and creating a worker farm for your runner.
You simply need two files:
// index.js
const { createJestRunner } = require('create-jest-runner');
module.exports = createJestRunner(require.resolve('./run'));pathToRunFile: path to your run file. This must be an absolute path or a file:// URL.config: Optional argument for configuring the runner.
getExtraOptions: () => object used for passing extra options to the runner. It needs to be a serializable object because it will be send to a different Node process.module.exports = options => {};This file should export a function that receives one parameter with the options
options: { testPath, config, globalConfig }testPath: Path of the file that is going to be testsconfig: Jest Project config used by this fileglobalConfig: Jest global configextraOptions: The return value of the { getExtraOptions } argument of createJestRunner(...) the entry file.You can return one of the following values:
testResult: Needs to be an object of type https://github.com/facebook/jest/blob/4d3c1a187bd429fd8611f6b0f19e4aa486fa2a85/packages/jest-test-result/src/types.ts#L103-L135Promise<testResult|Error>: needs to be of above type.Error: good for reporting system error, not failed tests.This runner "blade-runner" makes sure that these two emojis ⚔️ 🏃 are present in every file
// index.js
const { createJestRunner } = require('create-jest-runner');
module.exports = createJestRunner(require.resolve('./run'));// run.js
const fs = require('fs');
const { pass, fail } = require('create-jest-runner');
/** @type {import('create-jest-runner').RunTest} */
const runTest = ({ testPath }) => {
const start = Date.now();
const contents = fs.readFileSync(testPath, 'utf8');
const end = Date.now();
if (contents.includes('⚔️🏃')) {
return pass({ start, end, test: { path: testPath } });
}
const
yarn create jest-runner my-runner
# Or with npm
npm init jest-runner my-runnerNote: You will have to update the package name in package.json of the generated runner.
Once you have your Jest runner you can add it to your Jest config.
In your package.json
{
"jest": {
"runner": "/path/to/my-runner"
}
}Or in jest.config.js
module.exports = {
runner: '/path/to/my-runner',
};yarn jestrickhanlonii
rickhanlonii@gmail.com
Estimated unpacked size across 15 packages.
3.1 MB
Includes dependencies.
3 direct · 2 outdated