Skip to content

Commit debe93b

Browse files
test: removed --force-exit option from jest (#2611)
1 parent 5ea478c commit debe93b

File tree

6 files changed

+34
-37
lines changed

6 files changed

+34
-37
lines changed

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
"pretest": "yarn build && yarn lint && yarn prepsuite",
3737
"test": "jest --reporters=default",
3838
"test:smoketests": "nyc node smoketests",
39-
"test:coverage": "nyc --no-clean --require ts-node/register jest --forceExit",
40-
"test:cli": "jest test --reporters=default --forceExit",
41-
"test:packages": "jest packages/ --reporters=default --forceExit",
39+
"test:coverage": "nyc --no-clean --require ts-node/register jest",
40+
"test:cli": "jest test --reporters=default",
41+
"test:packages": "jest packages/ --reporters=default",
4242
"test:ci": "yarn test:cli && yarn test:packages",
4343
"test:watch": "jest test/ packages/ --watch",
4444
"publish:monorepo": "yarn build && lerna version && lerna publish from-git",

test/utils/test-utils.js

+11-14
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ const hyphenToUpperCase = (name) => {
3636
});
3737
};
3838

39+
const processKill = (process) => {
40+
if (isWindows) {
41+
exec('taskkill /pid ' + process.pid + ' /T /F');
42+
} else {
43+
process.kill();
44+
}
45+
};
46+
3947
/**
4048
* Run the webpack CLI for a test case.
4149
*
@@ -84,11 +92,7 @@ const runWatch = (testCase, args = [], options, outputKillStr = /webpack \d+\.\d
8492
const output = chunk.toString('utf8');
8593

8694
if (outputKillStr.test(output)) {
87-
if (isWindows) {
88-
exec('taskkill /pid ' + proc.pid + ' /T /F');
89-
} else {
90-
proc.kill();
91-
}
95+
processKill(proc);
9296
}
9397

9498
callback();
@@ -286,17 +290,9 @@ const readdir = (path) =>
286290

287291
const mkdir = (path) => {
288292
if (fs.existsSync(path)) {
289-
return path;
293+
return;
290294
}
291295

292-
new Promise((resolve) => {
293-
const interval = setInterval(() => {
294-
if (!fs.existsSync(path)) {
295-
clearInterval(interval);
296-
resolve();
297-
}
298-
}, 1000);
299-
});
300296
fs.mkdirSync(path);
301297
};
302298

@@ -329,4 +325,5 @@ module.exports = {
329325
isWebpack5,
330326
isDevServer4,
331327
isWindows,
328+
processKill,
332329
};

test/watch/analyze/analyze-flag.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { runAndGetWatchProc, normalizeStdout } = require('../../utils/test-utils');
3+
const { runAndGetWatchProc, normalizeStdout, processKill } = require('../../utils/test-utils');
44

55
describe('"analyze" option', () => {
66
it('should load webpack-bundle-analyzer plugin with --analyze flag', (done) => {
@@ -12,7 +12,7 @@ describe('"analyze" option', () => {
1212
if (data.includes('Webpack Bundle Analyzer is started at')) {
1313
expect(data).toContain('Webpack Bundle Analyzer is started at');
1414

15-
proc.kill();
15+
processKill(proc);
1616
done();
1717
}
1818
});

test/watch/basic/basic.test.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { run, runAndGetWatchProc, isWebpack5 } = require('../../utils/test-utils');
3+
const { run, runAndGetWatchProc, isWebpack5, processKill } = require('../../utils/test-utils');
44
const { writeFileSync } = require('fs');
55
const { resolve } = require('path');
66

@@ -42,7 +42,7 @@ describe('basic', () => {
4242

4343
modified = true;
4444
} else {
45-
proc.kill();
45+
processKill(proc);
4646
done();
4747
}
4848
}
@@ -75,7 +75,7 @@ describe('basic', () => {
7575

7676
modified = true;
7777
} else {
78-
proc.kill();
78+
processKill(proc);
7979
done();
8080
}
8181
}
@@ -110,7 +110,7 @@ describe('basic', () => {
110110

111111
modified = true;
112112
} else {
113-
proc.kill();
113+
processKill(proc);
114114
done();
115115
}
116116
}
@@ -143,7 +143,7 @@ describe('basic', () => {
143143

144144
modified = true;
145145
} else {
146-
proc.kill();
146+
processKill(proc);
147147
done();
148148
}
149149
}
@@ -174,7 +174,7 @@ describe('basic', () => {
174174
expect(stderr).toContain(`Compiler is using config: '${configPath}'`);
175175
expect(stderr).toContain('Compiler finished');
176176

177-
proc.kill();
177+
processKill(proc);
178178
done();
179179
}
180180
});

test/watch/stdin/stdin.test.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { runAndGetWatchProc } = require('../../utils/test-utils');
1+
const { runAndGetWatchProc, processKill } = require('../../utils/test-utils');
22

33
describe('--watch-options-stdin', () => {
44
it('should stop the process when stdin ends using "--watch" and "--watch-options-stdin" options', (done) => {
@@ -9,7 +9,7 @@ describe('--watch-options-stdin', () => {
99
proc.on('exit', () => {
1010
expect(semaphore).toBe(true);
1111

12-
proc.kill();
12+
processKill(proc);
1313

1414
done();
1515
});
@@ -27,7 +27,7 @@ describe('--watch-options-stdin', () => {
2727
proc.on('exit', () => {
2828
expect(semaphore).toBe(true);
2929

30-
proc.kill();
30+
processKill(proc);
3131

3232
done();
3333
});
@@ -45,7 +45,7 @@ describe('--watch-options-stdin', () => {
4545
proc.on('exit', () => {
4646
expect(semaphore).toBe(true);
4747

48-
proc.kill();
48+
processKill(proc);
4949

5050
done();
5151
});
@@ -63,7 +63,7 @@ describe('--watch-options-stdin', () => {
6363
proc.on('exit', () => {
6464
expect(semaphore).toBe(true);
6565

66-
proc.kill();
66+
processKill(proc);
6767

6868
done();
6969
});
@@ -79,7 +79,7 @@ describe('--watch-options-stdin', () => {
7979

8080
proc.on('exit', () => {
8181
expect(semaphore).toBe(true);
82-
proc.kill();
82+
processKill(proc);
8383
done();
8484
});
8585

@@ -94,7 +94,7 @@ describe('--watch-options-stdin', () => {
9494

9595
proc.on('exit', () => {
9696
expect(semaphore).toBe(true);
97-
proc.kill();
97+
processKill(proc);
9898
done();
9999
});
100100

@@ -109,7 +109,7 @@ describe('--watch-options-stdin', () => {
109109

110110
proc.on('exit', () => {
111111
expect(semaphore).toBe(true);
112-
proc.kill();
112+
processKill(proc);
113113
done();
114114
});
115115

@@ -126,7 +126,7 @@ describe('--watch-options-stdin', () => {
126126
proc.on('exit', () => {
127127
expect(semaphore).toBe(true);
128128

129-
proc.kill();
129+
processKill(proc);
130130

131131
done();
132132
});

test/watch/watch-variable/watch-variable.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { runAndGetWatchProc, isWebpack5 } = require('../../utils/test-utils');
3+
const { runAndGetWatchProc, isWebpack5, processKill } = require('../../utils/test-utils');
44
const { writeFileSync } = require('fs');
55
const { resolve } = require('path');
66

@@ -36,7 +36,7 @@ describe('watch variable', () => {
3636

3737
modified = true;
3838
} else {
39-
proc.kill();
39+
processKill(proc);
4040
done();
4141
}
4242
}
@@ -71,7 +71,7 @@ describe('watch variable', () => {
7171

7272
modified = true;
7373
} else {
74-
proc.kill();
74+
processKill(proc);
7575
done();
7676
}
7777
}

0 commit comments

Comments
 (0)