jest-runner-executor v1.0.0
Usage
Install
Install jest
(it needs Jest 21+) and jest-runner-executor
yarn add --dev jest jest-runner-executor
# or with NPM
npm install --save-dev jest jest-runner-executor
Add it to your Jest config
Standalone
In your package.json
{
"jest": {
"runner": "jest-runner-executor",
"moduleFileExtensions": [
/* whatever file you wish to match */
],
"testMatch": [
/* whatever paths you wish to match */
]
}
}
Or in jest.config.js
module.exports = {
runner: 'jest-runner-executor',
moduleFileExtensions: [
/* whatever file you wish to match */
],
testMatch: [
/* whatever paths you wish to match */
],
};
Please update testMatch
to match your project folder structure.
Alongside other runners
It is recommended to use the projects
configuration option to run multiple Jest runners simultaneously.
If you are using Jest <22.0.5, you can use multiple Jest configuration files and supply the paths to those files in the projects
option. For example:
// jest-test.config.js
module.exports = {
// your Jest test options
displayName: 'test',
};
// jest-executor.config.js
module.exports = {
// your jest-runner-executor options
runner: 'jest-runner-executor',
displayName: 'markdown',
moduleFileExtensions: [
/* whatever file you wish to match */
],
testMatch: [
/* whatever paths you wish to match */
],
};
In your package.json
:
{
"jest": {
"projects": [
"<rootDir>/jest.test.config.js",
"<rootDir>/jest.markdown.config.js"
]
}
}
Or in jest.config.js
:
module.exports = {
projects: [
'<rootDir>/jest.test.config.js',
'<rootDir>/jest.markdown.config.js',
],
};
If you are using Jest >=22.0.5, you can supply an array of project configuration objects instead. In your package.json
:
{
"jest": {
"projects": [
{
"displayName": "test"
},
{
"runner": "jest-runner-executor",
"displayName": "markdown",
"moduleFileExtensions": [
/* whatever file you wish to match */
],
"testMatch": [
/* whatever paths you wish to match */
]
}
]
}
}
Or in jest.config.js
:
module.exports = {
projects: [
{
displayName: 'test',
},
{
runner: 'jest-runner-executor',
displayName: 'markdown',
moduleFileExtensions: [
/* whatever file you wish to match */
],
testMatch: [
/* whatever paths you wish to match */
],
},
],
};
Run Jest
yarn test
Options
This project uses cosmiconfig, so you can provide config via:
- a
jest-runner-executor
property in yourpackage.json
- a
jest-runner-executor.config.js
JS file - a
.jest-runner-executorrc
JSON file
In package.json
{
"jest-runner-executor": {
"binaryPath": "/path/to/file",
"cliOptions": {
// Options here as key-value
}
}
}
The binaryPath
must be an absolute path, or the name of a globally installed binary.
You can also provide a template variable <rootDir>
to reference local paths within your repository.
or in jest-runner-executor.config.js
module.exports = {
binaryPath: '',
cliOptions: {
// Options here as key-value
},
};
cliOptions
All passed options will be normalized and forwarded to the binary.
Multiple executors
You can configure multiple executors to run with this jest runner. In the jest-runner-executor
config file, simply return/export an array of config objects instead of a single one. Important is that each config contains a matchDisplayName
with the reference to the displayName
used in the jest project config.
For example, given some config to lint markdown files:
// jest.markdown.config.js
module.exports = {
runner: 'jest-runner-executor',
displayName: 'markdown',
moduleFileExtensions: ['md'],
testMatch: ['**/*.md'],
};
Then the jest-runner-executor.config.js
should contain an array of configs with the matching display names:
module.exports = [
{
matchDisplayName: 'markdown',
binaryPath: '<rootDir>/node_modules/.bin/remark',
cliOptions: {
quiet: true,
},
},
];
4 years ago