(
tests: Array<Test>,
timings: Array<number>,
{
detectOpenHandles,
maxWorkers,
runInBand,
watch,
watchAll,
workerIdleMemoryLimit,
}: Config.GlobalConfig,
)
| 11 | const SLOW_TEST_TIME = 1000; |
| 12 | |
| 13 | export function shouldRunInBand( |
| 14 | tests: Array<Test>, |
| 15 | timings: Array<number>, |
| 16 | { |
| 17 | detectOpenHandles, |
| 18 | maxWorkers, |
| 19 | runInBand, |
| 20 | watch, |
| 21 | watchAll, |
| 22 | workerIdleMemoryLimit, |
| 23 | }: Config.GlobalConfig, |
| 24 | ): boolean { |
| 25 | // If user asked for run in band, respect that. |
| 26 | // detectOpenHandles makes no sense without runInBand, because it cannot detect leaks in workers |
| 27 | if (runInBand || detectOpenHandles) { |
| 28 | return true; |
| 29 | } |
| 30 | |
| 31 | /* |
| 32 | * If we are using watch/watchAll mode, don't schedule anything in the main |
| 33 | * thread to keep the TTY responsive and to prevent watch mode crashes caused |
| 34 | * by leaks (improper test teardown). |
| 35 | */ |
| 36 | if (watch || watchAll) { |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | /* |
| 41 | * Otherwise, run in band if we only have one test or one worker available. |
| 42 | * Also, if we are confident from previous runs that the tests will finish |
| 43 | * quickly we also run in band to reduce the overhead of spawning workers. |
| 44 | */ |
| 45 | const areFastTests = timings.every(timing => timing < SLOW_TEST_TIME); |
| 46 | const oneWorkerOrLess = maxWorkers <= 1; |
| 47 | const oneTestOrLess = tests.length <= 1; |
| 48 | |
| 49 | return ( |
| 50 | // When specifying a memory limit, workers should be used |
| 51 | workerIdleMemoryLimit === undefined && |
| 52 | (oneWorkerOrLess || |
| 53 | oneTestOrLess || |
| 54 | (tests.length <= 20 && timings.length > 0 && areFastTests)) |
| 55 | ); |
| 56 | } |
no outgoing calls
no test coverage detected