Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign process.env.JEST_RUN_IN_BAND value to check if testing is running serially. #9280

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 2 additions & 0 deletions docs/CLI.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions packages/jest-core/src/TestScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 2 additions & 0 deletions packages/jest-core/src/__tests__/TestScheduler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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');
});