I'm using NX from NRWL with my Angular app and I run the unit tests in my CI using the following command:
nx affected:test --base=main --watch=false --browsers=ChromeHeadlessNoSandbox --codeCoverage --parallel=true --maxParallel=4
when the code coverage requirements are not met the build still passes despite I can clearly see the coverage error in the build log:
07 12 2022 16:06:14.750:ERROR [coverage]: Chrome Headless 106.0.5249.91 (Linux x86_64): Coverage for branches (99.68%) does not meet global threshold (100%)
how can I tell nx to make this command fail as soon as the coverage requirements are not met?
EDIT: even running just one single project's test has the same problem:
nx run one-single-project:test --watch=false --browsers=ChromeHeadlessNoSandbox --codeCoverage=true
If I now echo $? it will be 0 but it should be error instead.
The problem was unrelated to
nx.I figured out after a couple of hours of debugging that it was about
karma-coverageand its config.In my
karma.config.js:More specifically, inside
reportersI had{ type: 'text-summary' }which was missing thefileproperty and for some reasons it failed the coverage check. So the correct way is:{ type: 'text-summary', file: 'coverage.txt' }The full
coverageReporterconfig now looks like this:I believe this is a bug of karma-coverage and I have submitted a fix for it.