From f74adbb789a09b9e297194bcf78fbbeeb78b301f Mon Sep 17 00:00:00 2001 From: Ran Yitzhaki Date: Fri, 23 Mar 2018 01:20:20 +0200 Subject: [PATCH 1/3] assign process.env.JEST_WORKER_ID=0 when on runInBand mode --- .../src/__tests__/test_runner.test.js | 19 +++++++++++++++++++ packages/jest-runner/src/index.js | 1 + 2 files changed, 20 insertions(+) diff --git a/packages/jest-runner/src/__tests__/test_runner.test.js b/packages/jest-runner/src/__tests__/test_runner.test.js index f05ab6c6dc4d..aa26eba2f969 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 = 0 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('0'); + }); +}); diff --git a/packages/jest-runner/src/index.js b/packages/jest-runner/src/index.js index f4a2ce92c1ab..154d4ff3bb6e 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 = '0'; const mutex = throat(1); return tests.reduce( (promise, test) => From 73ddfac4c82b2dbb127981852be152661a6ed0e6 Mon Sep 17 00:00:00 2001 From: Ran Yitzhaki Date: Fri, 23 Mar 2018 01:29:31 +0200 Subject: [PATCH 2/3] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7b5520066a1..ce074bed6ac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,8 @@ ### Fixes +* `[jest-runner]` Assign `process.env.JEST_WORKER_ID="0"` 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)) From 2772d6bbce38c7998c6f1e8b8c7de5b1fd145ec4 Mon Sep 17 00:00:00 2001 From: Ran Yitzhaki Date: Fri, 23 Mar 2018 01:41:33 +0200 Subject: [PATCH 3/3] change JEST_WORKER_ID in runInBand mode from 0 to 1 --- CHANGELOG.md | 2 +- packages/jest-runner/src/__tests__/test_runner.test.js | 4 ++-- packages/jest-runner/src/index.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce074bed6ac9..016da2e36835 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ ### Fixes -* `[jest-runner]` Assign `process.env.JEST_WORKER_ID="0"` when in runInBand mode +* `[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. diff --git a/packages/jest-runner/src/__tests__/test_runner.test.js b/packages/jest-runner/src/__tests__/test_runner.test.js index aa26eba2f969..ced1c934a8cc 100644 --- a/packages/jest-runner/src/__tests__/test_runner.test.js +++ b/packages/jest-runner/src/__tests__/test_runner.test.js @@ -87,7 +87,7 @@ test('does not inject the rawModuleMap in serial mode', () => { }); }); -test('assign process.env.JEST_WORKER_ID = 0 when in runInBand 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}; @@ -102,6 +102,6 @@ test('assign process.env.JEST_WORKER_ID = 0 when in runInBand mode', () => { {serial: true}, ) .then(() => { - expect(process.env.JEST_WORKER_ID).toBe('0'); + 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 154d4ff3bb6e..2f4dd7243697 100644 --- a/packages/jest-runner/src/index.js +++ b/packages/jest-runner/src/index.js @@ -61,7 +61,7 @@ class TestRunner { onResult: OnTestSuccess, onFailure: OnTestFailure, ) { - process.env.JEST_WORKER_ID = '0'; + process.env.JEST_WORKER_ID = '1'; const mutex = throat(1); return tests.reduce( (promise, test) =>