Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
create-jest-runner
Advanced tools
The create-jest-runner package allows you to create custom Jest test runners. This can be useful for running tests in a specific way, adding custom logic before or after tests, or integrating with other tools.
Creating a Custom Jest Runner
This feature allows you to create a custom Jest runner by using the `createJestRunner` function. You can specify the path to your custom runner logic.
const { createJestRunner } = require('create-jest-runner');
module.exports = createJestRunner(require.resolve('./my-runner'));
Custom Runner Logic
This code sample demonstrates how to implement custom runner logic. The custom runner can use Jest's `runCLI` function to execute tests and return the results.
const { runCLI } = require('jest');
module.exports = async ({ testPath }) => {
const result = await runCLI({ testPath }, [process.cwd()]);
return result;
};
jest-runner-eslint is a Jest runner that allows you to run ESLint as part of your Jest tests. It is similar to create-jest-runner in that it provides a custom runner, but it is specifically designed for linting JavaScript code.
jest-runner-mocha is a Jest runner that allows you to run Mocha tests within a Jest environment. It provides similar functionality to create-jest-runner by enabling custom test execution, but it is tailored for integrating Mocha tests.
jest-runner-tsc is a Jest runner that compiles TypeScript files using the TypeScript compiler (tsc) as part of your Jest tests. It is similar to create-jest-runner in that it provides a custom runner, but it focuses on TypeScript compilation.
A highly opinionated way for creating Jest Runners
yarn add create-jest-runner
create-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.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 errorMessage = 'Company policies require ⚔️ 🏃 in every file';
return fail({
start,
end,
test: { path: testPath, errorMessage, title: 'Check for ⚔️ 🏃' },
});
};
module.exports = runTest;
yarn create jest-runner my-runner
# Or with npm
npm init jest-runner my-runner
Note: 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 jest
FAQs
A simple way of creating a Jest runner
The npm package create-jest-runner receives a total of 117,463 weekly downloads. As such, create-jest-runner popularity was classified as popular.
We found that create-jest-runner demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.