|
| 1 | +const throat = require('throat'); |
1 | 2 | const Worker = require('jest-worker').default;
|
2 | 3 |
|
3 | 4 | class CancelRun extends Error {
|
@@ -89,25 +90,28 @@ const createRunner = runPath => {
|
89 | 90 | forkOptions: { stdio: 'inherit' },
|
90 | 91 | });
|
91 | 92 |
|
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 | + } |
107 | 100 |
|
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 | + }); |
109 | 114 | });
|
110 |
| - }; |
111 | 115 |
|
112 | 116 | const onError = (err, test) => {
|
113 | 117 | return onFailure(test, err).then(() => {
|
|
0 commit comments