Skip to content

Commit 780c838

Browse files
willsmytheSimenB
authored andcommitted
fix: Windows-specific test timeout issues introduced by Yarn 1.13.0 (jestjs#7838)
1 parent 384a375 commit 780c838

File tree

3 files changed

+30
-44
lines changed

3 files changed

+30
-44
lines changed

.azure-pipelines.yml

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
git config --global core.autocrlf false
1818
git config --global core.symlinks true
1919
displayName: 'Preserve LF endings and symbolic links on check out'
20-
- script: npm install -g [email protected]
2120
- template: .azure-pipelines-steps.yml
2221

2322
- job: macOS

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
/website/translated_docs
2727
/website/i18n/*
2828

29+
/reports/*
30+
2931
coverage
3032
lerna-debug.log
3133
npm-debug.log

e2e/runJest.js

+28-43
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import path from 'path';
1212
import fs from 'fs';
13-
import execa, {sync as spawnSync} from 'execa';
13+
import execa from 'execa';
1414
import {Writable} from 'readable-stream';
1515
import stripAnsi from 'strip-ansi';
1616
import {normalizeIcons} from './Utils';
@@ -20,7 +20,8 @@ const JEST_PATH = path.resolve(__dirname, '../packages/jest-cli/bin/jest.js');
2020
type RunJestOptions = {
2121
nodePath?: string,
2222
skipPkgJsonCheck?: boolean, // don't complain if can't find package.json
23-
stripAnsi?: boolean, // remove colors from stdout and stderr
23+
stripAnsi?: boolean, // remove colors from stdout and stderr,
24+
timeout?: number, // kill the Jest process after X milliseconds
2425
};
2526

2627
// return the result of the spawned process:
@@ -30,6 +31,16 @@ export default function runJest(
3031
dir: string,
3132
args?: Array<string>,
3233
options: RunJestOptions = {},
34+
) {
35+
return normalizeResult(spawnJest(dir, args, options), options);
36+
}
37+
38+
// Spawns Jest and returns either a Promise (if spawnAsync is true) or the completed child process
39+
function spawnJest(
40+
dir: string,
41+
args?: Array<string>,
42+
options: RunJestOptions = {},
43+
spawnAsync: boolean = false,
3344
) {
3445
const isRelative = !path.isAbsolute(dir);
3546

@@ -51,12 +62,23 @@ export default function runJest(
5162

5263
const env = {...process.env, FORCE_COLOR: 0};
5364
if (options.nodePath) env['NODE_PATH'] = options.nodePath;
54-
const result = spawnSync(JEST_PATH, args || [], {
65+
66+
const spawnArgs = [JEST_PATH, ...(args || [])];
67+
const spawnOptions = {
5568
cwd: dir,
5669
env,
5770
reject: false,
58-
});
71+
timeout: options.timeout || 0,
72+
};
5973

74+
return (spawnAsync ? execa : execa.sync)(
75+
process.execPath,
76+
spawnArgs,
77+
spawnOptions,
78+
);
79+
}
80+
81+
function normalizeResult(result, options) {
6082
// For compat with cross-spawn
6183
result.status = result.code;
6284

@@ -101,34 +123,7 @@ export const until = async function(
101123
text: string,
102124
options: RunJestOptions = {},
103125
) {
104-
const isRelative = !path.isAbsolute(dir);
105-
106-
if (isRelative) {
107-
dir = path.resolve(__dirname, dir);
108-
}
109-
110-
const localPackageJson = path.resolve(dir, 'package.json');
111-
if (!options.skipPkgJsonCheck && !fs.existsSync(localPackageJson)) {
112-
throw new Error(
113-
`
114-
Make sure you have a local package.json file at
115-
"${localPackageJson}".
116-
Otherwise Jest will try to traverse the directory tree and find the
117-
the global package.json, which will send Jest into infinite loop.
118-
`,
119-
);
120-
}
121-
122-
const env = {...process.env, FORCE_COLOR: 0};
123-
if (options.nodePath) env['NODE_PATH'] = options.nodePath;
124-
125-
const jestPromise = execa(JEST_PATH, args || [], {
126-
cwd: dir,
127-
env,
128-
reject: false,
129-
// this should never take more than 5-6 seconds, bailout after 30
130-
timeout: 30000,
131-
});
126+
const jestPromise = spawnJest(dir, args, {timeout: 30000, ...options}, true);
132127

133128
jestPromise.stderr.pipe(
134129
new Writable({
@@ -144,15 +139,5 @@ export const until = async function(
144139
}),
145140
);
146141

147-
const result = await jestPromise;
148-
149-
// For compat with cross-spawn
150-
result.status = result.code;
151-
152-
result.stdout = normalizeIcons(result.stdout);
153-
if (options.stripAnsi) result.stdout = stripAnsi(result.stdout);
154-
result.stderr = normalizeIcons(result.stderr);
155-
if (options.stripAnsi) result.stderr = stripAnsi(result.stderr);
156-
157-
return result;
142+
return normalizeResult(await jestPromise, options);
158143
};

0 commit comments

Comments
 (0)