Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  135] [ 7]  / answers: 1 / hits: 19717  / 7 Years ago, mon, march 6, 2017, 12:00:00

When is it appropriate to use each of --runInBand or --maxWorkers 1 options?



If my intent is to run all tests in sequence (one at a time, in order), which of these is the right option?






Extra detail:



I'm using Jest to test a NodeJs express application, with integration tests hitting the HTTP endpoints via supertest. This may not make any difference to the answer, just mentioning in case it is relevant.



Here's the Jest CLI reference:



https://facebook.github.io/jest/docs/cli.html



Relevant parts:



--maxWorkers=<num>



Alias: -w. Specifies the maximum number of workers the worker-pool will spawn for running tests. This defaults to the number of the cores available on your machine. It may be useful to adjust this in resource limited environments like CIs but the default should be adequate for most use-cases.



--runInBand



Alias: -i. Run all tests serially in the current process, rather than creating a worker pool of child processes that run tests. This can be useful for debugging.


More From » node.js

 Answers
280

There is no difference. Here's the method where it gets read from the args object:



export default function getMaxWorkers(argv: Argv): number {
if (argv.runInBand) {
return 1;
} else if (argv.maxWorkers) {
return parseInt(argv.maxWorkers, 10);
} else {
const cpus = os.cpus().length;
return Math.max(argv.watch ? Math.floor(cpus / 2) : cpus - 1, 1);
}
}


original source code on github


[#58655] Saturday, March 4, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
robinh

Total Points: 371
Total Questions: 105
Total Answers: 89

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
robinh questions
Thu, May 6, 21, 00:00, 3 Years ago
Thu, Jan 7, 21, 00:00, 3 Years ago
Fri, Nov 6, 20, 00:00, 4 Years ago
Sun, Aug 9, 20, 00:00, 4 Years ago
;