Skip to content

Commit eb655fa

Browse files
authored
Add getExtraOptions to entry file (#12)
* Add getExtraOptions * Update changelog
1 parent e599c0c commit eb655fa

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,41 @@
11
## master
22

3+
### Features
4+
5+
* Add `getExtraOptions` to entry file ([#12](https://github.com/rogeliog/create-jest-runner/pull/12))
6+
7+
### Breaking changes
8+
9+
* Drop Node 4 ([#4](https://github.com/rogeliog/create-jest-runner/pull/4))
10+
311
## 0.3.1
412

513
### Fixes
14+
615
* Use a mutex when running in band as well ([#7](https://github.com/rogeliog/create-jest-runner/pull/7))
716
* Use import/export ([#8](https://github.com/rogeliog/create-jest-runner/pull/8))
817
* Removing un-needed packages ([#1](https://github.com/rogeliog/create-jest-runner/pull/1))
918

1019
## 0.3.0
1120

1221
### Fixes
22+
1323
* Mutex the workers, to behave more like native jest test runs ([#5](https://github.com/rogeliog/create-jest-runner/pull/5))
1424

1525
### Features
26+
1627
* Support serial execution ([#6](https://github.com/rogeliog/create-jest-runner/pull/6))
1728

1829
## O.2.0
1930

2031
### Features
32+
2133
* Add skip functionality
2234

2335
## O.1.1
2436

2537
### Fixes
38+
2639
* TTY support for jest-worker
2740

2841
## 0.1.0

README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ yarn add create-jest-runner
1414

1515
create-jest-runner takes care of handling the appropriate parallelization and creating a worker farm for your runner.
1616

17-
1817
You simply need two files:
18+
1919
* Entry file: Used by Jest as an entrypoint to your runner.
2020
* Run file: Runs once per test file, and it encapsulates the logic of your runner
2121

@@ -27,34 +27,39 @@ const { createJestRunner } = require('create-jest-runner');
2727
module.exports = createJestRunner(require.resolve('./run'));
2828
```
2929

30+
#### createJestRunner(pathToRunFile, config?: { getExtraOptions })
31+
32+
* `pathToRunFile`: path to your run file.
33+
* `config`: Optional argument for configuring the runner.
34+
* `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.
35+
3036
### 2) Create your run file
3137

3238
```js
33-
module.exports = (options) => {
34-
};
39+
module.exports = options => {};
3540
```
3641

3742
### Run File API
3843

3944
This file should export a function that receives one parameter with the options
4045

4146
#### `options: { testPath, config, globalConfig }`
42-
- `testPath`: Path of the file that is going to be tests
43-
- `config`: Jest Project config used by this file
44-
- `globalConfig`: Jest global config
4547

46-
You can return one of the following values:
47-
- `testResult`: Needs to be an object of type https://github.com/facebook/jest/blob/master/types/TestResult.js#L137-L165
48-
- `Promise<testResult|Error>`: needs to be of above type.
49-
- `Error`: good for reporting system error, not failed tests.
48+
* `testPath`: Path of the file that is going to be tests
49+
* `config`: Jest Project config used by this file
50+
* `globalConfig`: Jest global config
51+
* `extraOptions`: The return value of the `{ getExtraOptions }` argument of `createJestRunner(...)` the entry file.
5052

53+
You can return one of the following values:
5154

55+
* `testResult`: Needs to be an object of type https://github.com/facebook/jest/blob/master/types/TestResult.js#L137-L165
56+
* `Promise<testResult|Error>`: needs to be of above type.
57+
* `Error`: good for reporting system error, not failed tests.
5258

5359
## Example of a runner
5460

5561
This runner "blade-runner" makes sure that these two emojis `⚔️ 🏃` are present in every file
5662

57-
5863
```js
5964
// index.js
6065
const { createJestRunner } = require('create-jest-runner');
@@ -83,12 +88,12 @@ module.exports = ({ testPath }) => {
8388
};
8489
```
8590

86-
8791
## Add your runner to Jest config
8892

8993
Once you have your Jest runner you can add it to your Jest config.
9094

9195
In your `package.json`
96+
9297
```json
9398
{
9499
"jest": {
@@ -98,13 +103,15 @@ In your `package.json`
98103
```
99104

100105
Or in `jest.config.js`
106+
101107
```js
102108
module.exports = {
103109
runner: '/path/to/my-runner',
104-
}
110+
};
105111
```
106112

107113
### Run Jest
114+
108115
```bash
109116
yarn jest
110117
```

lib/createJestRunner.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class CancelRun extends Error {
88
}
99
}
1010

11-
const createRunner = runPath => {
11+
const createRunner = (runPath, { getExtraOptions } = {}) => {
1212
class BaseTestRunner {
1313
constructor(globalConfig) {
1414
this._globalConfig = globalConfig;
@@ -63,6 +63,7 @@ const createRunner = runPath => {
6363
? test.context.moduleMap.getRawModuleMap()
6464
: null,
6565
options,
66+
extraOptions: getExtraOptions ? getExtraOptions() : {},
6667
};
6768

6869
if (typeof runner.default === 'function') {
@@ -110,6 +111,7 @@ const createRunner = runPath => {
110111
? test.context.moduleMap.getRawModuleMap()
111112
: null,
112113
options,
114+
extraOptions: getExtraOptions ? getExtraOptions() : {},
113115
};
114116

115117
return worker.default(baseOptions);

0 commit comments

Comments
 (0)