diff --git a/CHANGELOG.md b/CHANGELOG.md index d7b5520066a1..016da2e36835 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/packages/jest-runner/src/__tests__/test_runner.test.js b/packages/jest-runner/src/__tests__/test_runner.test.js index f05ab6c6dc4d..ced1c934a8cc 100644 --- a/packages/jest-runner/src/__tests__/test_runner.test.js +++ b/packages/jest-runner/src/__tests__/test_runner.test.js @@ -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'); + }); +}); diff --git a/packages/jest-runner/src/index.js b/packages/jest-runner/src/index.js index f4a2ce92c1ab..2f4dd7243697 100644 --- a/packages/jest-runner/src/index.js +++ b/packages/jest-runner/src/index.js @@ -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) =>