Skip to content

Commit 74fc5eb

Browse files
committed
Fix a flaky test that behaves differently in various situations.
1 parent a94c6d0 commit 74fc5eb

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

e2e/__tests__/circusConcurrent.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*/
7-
import exp = require('constants');
87
import {skipSuiteOnJasmine} from '@jest/test-utils';
98
import runJest, {json as runWithJson} from '../runJest';
109

1110
skipSuiteOnJasmine();
1211

12+
jest.retryTimes(3);
13+
1314
describe('all passing', () => {
1415
it('runs the correct number of tests', () => {
1516
const {json, exitCode} = runWithJson('circus-concurrent', [

packages/jest-worker/src/workers/__tests__/ChildProcessWorker.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ let Worker: typeof import('../ChildProcessWorker').default;
3030
let childProcess: typeof import('child_process');
3131
let forkInterface: ReturnType<typeof childProcess.fork>;
3232
let originalExecArgv: typeof process.execArgv;
33+
let originalForceColor: string | undefined;
3334

3435
const totalmem = jest.spyOn(require('os') as typeof import('os'), 'totalmem');
3536

@@ -42,6 +43,9 @@ class MockedForkInterface extends EventEmitter {
4243
}
4344

4445
beforeEach(() => {
46+
originalForceColor = process.env.FORCE_COLOR;
47+
delete process.env.FORCE_COLOR;
48+
4549
originalExecArgv = process.execArgv;
4650

4751
childProcess = require('child_process') as typeof import('child_process');
@@ -63,6 +67,7 @@ beforeEach(() => {
6367
afterEach(() => {
6468
jest.resetModules();
6569
process.execArgv = originalExecArgv;
70+
process.env.FORCE_COLOR = originalForceColor;
6671
});
6772

6873
it('passes fork options down to child_process.fork, adding the defaults', () => {
@@ -84,7 +89,7 @@ it('passes fork options down to child_process.fork, adding the defaults', () =>
8489
expect(jest.mocked(childProcess.fork).mock.calls[0][0]).toBe(child);
8590
expect(jest.mocked(childProcess.fork).mock.calls[0][2]).toEqual({
8691
cwd: '/tmp', // Overridden default option.
87-
env: {...process.env, FORCE_COLOR: supportsColor.stdout ? '1' : undefined}, // Default option.
92+
env: process.env, // Default option.
8893
execArgv: ['-p'], // Filtered option.
8994
execPath: 'hello', // Added option.
9095
serialization: 'advanced', // Default option.

0 commit comments

Comments
 (0)