Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/emmenko/jest-runner-executor
A general purpose executor that allows to run any script as a Jest runner
https://github.com/emmenko/jest-runner-executor
Last synced: 3 months ago
JSON representation
A general purpose executor that allows to run any script as a Jest runner
- Host: GitHub
- URL: https://github.com/emmenko/jest-runner-executor
- Owner: emmenko
- License: mit
- Created: 2019-11-25T13:33:13.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T01:39:29.000Z (about 2 years ago)
- Last Synced: 2024-04-25T11:43:28.264Z (9 months ago)
- Language: JavaScript
- Size: 1.68 MB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Usage
### Install
Install `jest`_(it needs Jest 21+)_ and `jest-runner-executor`
```bash
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`
```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`
```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`](https://facebook.github.io/jest/docs/en/configuration.html#projects-array-string-projectconfig) 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:
```js
// 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`:
```json
{
"jest": {
"projects": [
"/jest.test.config.js",
"/jest.markdown.config.js"
]
}
}
```Or in `jest.config.js`:
```js
module.exports = {
projects: [
'/jest.test.config.js',
'/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`:
```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`:
```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
```bash
yarn test
```## Options
This project uses [cosmiconfig](https://github.com/davidtheclark/cosmiconfig), so you can provide config via:
- a `jest-runner-executor` property in your `package.json`
- a `jest-runner-executor.config.js` JS file
- a `.jest-runner-executorrc` JSON fileIn `package.json`
```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 `` to reference local paths within your repository.or in `jest-runner-executor.config.js`
```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:
```js
// 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:
```js
module.exports = [
{
matchDisplayName: 'markdown',
binaryPath: '/node_modules/.bin/remark',
cliOptions: {
quiet: true,
},
},
];
```