1 | ;
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.shouldRunInBand = shouldRunInBand;
|
7 | /**
|
8 | * Copyright (c) Meta Platforms, Inc. and affiliates.
|
9 | *
|
10 | * This source code is licensed under the MIT license found in the
|
11 | * LICENSE file in the root directory of this source tree.
|
12 | */
|
13 |
|
14 | const SLOW_TEST_TIME = 1000;
|
15 | function shouldRunInBand(
|
16 | tests,
|
17 | timings,
|
18 | {
|
19 | detectOpenHandles,
|
20 | maxWorkers,
|
21 | runInBand,
|
22 | watch,
|
23 | watchAll,
|
24 | workerIdleMemoryLimit
|
25 | }
|
26 | ) {
|
27 | // If user asked for run in band, respect that.
|
28 | // detectOpenHandles makes no sense without runInBand, because it cannot detect leaks in workers
|
29 | if (runInBand || detectOpenHandles) {
|
30 | return true;
|
31 | }
|
32 |
|
33 | /*
|
34 | * If we are using watch/watchAll mode, don't schedule anything in the main
|
35 | * thread to keep the TTY responsive and to prevent watch mode crashes caused
|
36 | * by leaks (improper test teardown).
|
37 | */
|
38 | if (watch || watchAll) {
|
39 | return false;
|
40 | }
|
41 |
|
42 | /*
|
43 | * Otherwise, run in band if we only have one test or one worker available.
|
44 | * Also, if we are confident from previous runs that the tests will finish
|
45 | * quickly we also run in band to reduce the overhead of spawning workers.
|
46 | */
|
47 | const areFastTests = timings.every(timing => timing < SLOW_TEST_TIME);
|
48 | const oneWorkerOrLess = maxWorkers <= 1;
|
49 | const oneTestOrLess = tests.length <= 1;
|
50 | return (
|
51 | // When specifying a memory limit, workers should be used
|
52 | !workerIdleMemoryLimit &&
|
53 | (oneWorkerOrLess ||
|
54 | oneTestOrLess ||
|
55 | (tests.length <= 20 && timings.length > 0 && areFastTests))
|
56 | );
|
57 | }
|