Skip to content

Commit

Permalink
Assign process.env.JEST_WORKER_ID=1 when in runInBand mode (#5860)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranyitz authored and mjesun committed Mar 23, 2018
1 parent 69c11a0 commit 1a487c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

### Fixes

* `[jest-runner]` Assign `process.env.JEST_WORKER_ID="1"` when in runInBand mode
([#5860](https://github.com/facebook/jest/pull/5860))
* `[jest-cli]` Add descriptive error message when trying to use
`globalSetup`/`globalTeardown` file that doesn't export a function.
([#5835](https://github.com/facebook/jest/pull/5835))
Expand Down
19 changes: 19 additions & 0 deletions packages/jest-runner/src/__tests__/test_runner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,22 @@ test('does not inject the rawModuleMap in serial mode', () => {
]);
});
});

test('assign process.env.JEST_WORKER_ID = 1 when in runInBand mode', () => {
const globalConfig = {maxWorkers: 1, watch: false};
const config = {rootDir: '/path/'};
const context = {config};

return new TestRunner(globalConfig)
.runTests(
[{context, path: './file.test.js'}],
new TestWatcher({isWatchMode: globalConfig.watch}),
() => {},
() => {},
() => {},
{serial: true},
)
.then(() => {
expect(process.env.JEST_WORKER_ID).toBe('1');
});
});
1 change: 1 addition & 0 deletions packages/jest-runner/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TestRunner {
onResult: OnTestSuccess,
onFailure: OnTestFailure,
) {
process.env.JEST_WORKER_ID = '1';
const mutex = throat(1);
return tests.reduce(
(promise, test) =>
Expand Down

0 comments on commit 1a487c1

Please sign in to comment.