From 2ae557cd7bb71066f4e4c6b2635d3222fa76aa0e Mon Sep 17 00:00:00 2001 From: WeiAnAn Date: Sun, 8 Dec 2019 03:29:40 +0800 Subject: [PATCH 1/3] assign process.env.JEST_RUN_IN_BAND --- packages/jest-core/src/TestScheduler.ts | 1 + packages/jest-core/src/__tests__/TestScheduler.test.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/packages/jest-core/src/TestScheduler.ts b/packages/jest-core/src/TestScheduler.ts index 58a141136ea4..8224d10d4ccb 100644 --- a/packages/jest-core/src/TestScheduler.ts +++ b/packages/jest-core/src/TestScheduler.ts @@ -88,6 +88,7 @@ export default class TestScheduler { ); const runInBand = shouldRunInBand(tests, timings, this._globalConfig); + process.env.JEST_RUN_IN_BAND = runInBand ? '1' : '0'; const onResult = async (test: TestRunner.Test, testResult: TestResult) => { if (watcher.isInterrupted()) { diff --git a/packages/jest-core/src/__tests__/TestScheduler.test.js b/packages/jest-core/src/__tests__/TestScheduler.test.js index dbbe8c052165..1c6bcba504aa 100644 --- a/packages/jest-core/src/__tests__/TestScheduler.test.js +++ b/packages/jest-core/src/__tests__/TestScheduler.test.js @@ -207,6 +207,7 @@ test('should set runInBand to run in serial', async () => { expect(spyShouldRunInBand).toHaveBeenCalled(); expect(mockParallelRunner.runTests).toHaveBeenCalled(); expect(mockParallelRunner.runTests.mock.calls[0][5].serial).toBeTruthy(); + expect(process.env.JEST_RUN_IN_BAND).toBe('1'); }); test('should set runInBand to not run in serial', async () => { @@ -231,4 +232,5 @@ test('should set runInBand to not run in serial', async () => { expect(spyShouldRunInBand).toHaveBeenCalled(); expect(mockParallelRunner.runTests).toHaveBeenCalled(); expect(mockParallelRunner.runTests.mock.calls[0][5].serial).toBeFalsy(); + expect(process.env.JEST_RUN_IN_BAND).toBe('0'); }); From 1a88295a7ac65ed9729f9b16ec3ce68fa16786e2 Mon Sep 17 00:00:00 2001 From: WeiAnAn Date: Sun, 8 Dec 2019 03:33:54 +0800 Subject: [PATCH 2/3] update cli docs --- docs/CLI.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/CLI.md b/docs/CLI.md index de9bee433d67..f4f212854850 100644 --- a/docs/CLI.md +++ b/docs/CLI.md @@ -248,6 +248,8 @@ Run tests with specified reporters. [Reporter options](configuration#reporters-a Alias: `-i`. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging. +It will set `process.env.JEST_RUN_IN_BAND` to `'1'` + ### `--runTestsByPath` Run only the tests that were specified with their exact paths. From 6d0b59461f1ec37d21195fc98a3f1b667c6eec08 Mon Sep 17 00:00:00 2001 From: WeiAnAn Date: Sun, 8 Dec 2019 03:50:18 +0800 Subject: [PATCH 3/3] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c2faa49d29b..d3d974d4ca08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - `[jest-config]` [**BREAKING**] Set default display name color based on runner ([#8689](https://github.com/facebook/jest/pull/8689)) - `[jest-config]` Merge preset globals with project globals ([#9027](https://github.com/facebook/jest/pull/9027)) - `[jest-core]` Support reporters as default exports ([#9161](https://github.com/facebook/jest/pull/9161)) +- `[jest-core]` Assign `process.env.JEST_RUN_IN_BAND` value. It can be used to check if testing is running serially. ([#9280](https://github.com/facebook/jest/pull/9280)) - `[jest-diff]` Add options for colors and symbols ([#8841](https://github.com/facebook/jest/pull/8841)) - `[jest-diff]` [**BREAKING**] Export as ECMAScript module ([#8873](https://github.com/facebook/jest/pull/8873)) - `[jest-diff]` Add `includeChangeCounts` and rename `Indicator` options ([#8881](https://github.com/facebook/jest/pull/8881))