1
+ const throat = require ( 'throat' ) ;
1
2
const Worker = require ( 'jest-worker' ) . default ;
2
3
3
4
class CancelRun extends Error {
@@ -21,25 +22,28 @@ const createRunner = runPath => {
21
22
forkOptions : { stdio : 'inherit' } ,
22
23
} ) ;
23
24
25
+ const mutex = throat ( this . _globalConfig . maxWorkers ) ;
26
+
24
27
const runTestInWorker = test => {
25
- if ( watcher . isInterrupted ( ) ) {
26
- throw new CancelRun ( ) ;
27
- }
28
+ mutex ( async ( ) => {
29
+ if ( watcher . isInterrupted ( ) ) {
30
+ throw new CancelRun ( ) ;
31
+ }
28
32
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
+ } ;
39
43
40
- return worker . default ( baseOptions ) ;
44
+ return worker . default ( baseOptions ) ;
45
+ } ) ;
41
46
} ) ;
42
- } ;
43
47
44
48
const onError = ( err , test ) => {
45
49
return onFailure ( test , err ) . then ( ( ) => {
0 commit comments