Skip to content

Commit c0b1f5f

Browse files
authored
Merge pull request #5 from stipsan/patch-1
Mutex the workers, to behave more like native jest test runs
2 parents 62ed157 + efb50e8 commit c0b1f5f

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

lib/createJestRunner.js

Lines changed: 21 additions & 17 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 {
@@ -89,25 +90,28 @@ const createRunner = runPath => {
8990
forkOptions: { stdio: 'inherit' },
9091
});
9192

92-
const runTestInWorker = test => {
93-
if (watcher.isInterrupted()) {
94-
throw new CancelRun();
95-
}
96-
97-
return onStart(test).then(() => {
98-
const baseOptions = {
99-
config: test.context.config,
100-
globalConfig: this._globalConfig,
101-
testPath: test.path,
102-
rawModuleMap: watcher.isWatchMode()
103-
? test.context.moduleMap.getRawModuleMap()
104-
: null,
105-
options,
106-
};
93+
const mutex = throat(this._globalConfig.maxWorkers);
94+
95+
const runTestInWorker = test =>
96+
mutex(() => {
97+
if (watcher.isInterrupted()) {
98+
throw new CancelRun();
99+
}
107100

108-
return worker.default(baseOptions);
101+
return onStart(test).then(() => {
102+
const baseOptions = {
103+
config: test.context.config,
104+
globalConfig: this._globalConfig,
105+
testPath: test.path,
106+
rawModuleMap: watcher.isWatchMode()
107+
? test.context.moduleMap.getRawModuleMap()
108+
: null,
109+
options,
110+
};
111+
112+
return worker.default(baseOptions);
113+
});
109114
});
110-
};
111115

112116
const onError = (err, test) => {
113117
return onFailure(test, err).then(() => {

0 commit comments

Comments
 (0)