We migrated our project from jasmine to jest couple month ago and now want to add some coverage in our TeamCity CI server. What we noticed is that for jest on a local dev's machine first run (with coverage) takes about 2-2.5 minutes and all consequent runs take about 20 seconds, but in TeamCity it takes about 6 minutes (with coverage) and only 1:30 without coverage. Is there any way to speed up tests with coverage for TeamCity?
2 Answers
It is an known issue [3] that coverage in jest makes running tests slower. However, there is no explanation what cures the issue. Only tip was to try -i flag on running the tests.
My source [2] tells why that flag improves the efficiency of tests all together. The flag disables multiprocessing and on some machines with limited resources (they say) this speeds up efficiency two fold.
My source [1] also tells the version after 22.4.4 has regression in efficiency (significantly slower than 22.4.4) and that was not fixed until article was written.
Also, they recommend in [1] to use Node but not JSDOM because Node is faster.
So, use:
// package.json
"jest": {
"testEnvironment": "node"
}
Hope these rocket speed your tests and you can taggle the loss of speed via coverage option on.
Sources:
[1] https://itnext.io/how-to-make-your-sluggish-jest-v23-tests-go-faster-1d4f3388bcdd

- 12,730
- 12
- 59
- 99
-
Thanks mico! I've tried both --runInBand and --maxWorkers params but they don't give any improvement. I'll try older version and provide my results here. – TopaZ Dec 11 '19 at 21:08
- Try adding the
dotnet.cli.test.reporting
parameter, which will bring back to the normal running time. - Another possible workaround is to use
vstest
command instead oftest
since it supports more precise test adapter path declaration.

- 27,863
- 13
- 63
- 115
-
Vignesh Kumar A, I don't think dotnet is anyhow relevant to a Jest testing framework (which is Javascript based) Also I don't quite understand what is vstest command. I was unable to find it in Jest documentation. Could you please provide any explanations to the above-mentioned comment? – TopaZ Dec 16 '19 at 00:27
-
Sorry its ny bad, this command will work for Nunit with .net framework. – Vignesh Kumar A Dec 16 '19 at 01:18