Skip to content

Commit aab4220

Browse files
authored
Mutex the test runs
Makes the developer experience a bit nicer, and more like the `jest-runner` itself: https://github.com/facebook/jest/blob/e566a8f4106ac25b008744ffc42204554fd31cf6/packages/jest-runner/src/index.js#L104-L124
1 parent 9f71d95 commit aab4220

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

lib/createJestRunner.js

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const throat = require('throat');
12
const Worker = require('jest-worker').default;
23

34
class CancelRun extends Error {
@@ -21,25 +22,28 @@ const createRunner = runPath => {
2122
forkOptions: { stdio: 'inherit' },
2223
});
2324

25+
const mutex = throat(this._globalConfig.maxWorkers);
26+
2427
const runTestInWorker = test => {
25-
if (watcher.isInterrupted()) {
26-
throw new CancelRun();
27-
}
28+
mutex(async () => {
29+
if (watcher.isInterrupted()) {
30+
throw new CancelRun();
31+
}
2832

29-
return onStart(test).then(() => {
30-
const baseOptions = {
31-
config: test.context.config,
32-
globalConfig: this._globalConfig,
33-
testPath: test.path,
34-
rawModuleMap: watcher.isWatchMode()
35-
? test.context.moduleMap.getRawModuleMap()
36-
: null,
37-
options,
38-
};
33+
return onStart(test).then(() => {
34+
const baseOptions = {
35+
config: test.context.config,
36+
globalConfig: this._globalConfig,
37+
testPath: test.path,
38+
rawModuleMap: watcher.isWatchMode()
39+
? test.context.moduleMap.getRawModuleMap()
40+
: null,
41+
options,
42+
};
3943

40-
return worker.default(baseOptions);
44+
return worker.default(baseOptions);
45+
});
4146
});
42-
};
4347

4448
const onError = (err, test) => {
4549
return onFailure(test, err).then(() => {

0 commit comments

Comments
 (0)