Run Jest test with code coverage in an Angular CLI project

I am unable to get code coverage in the IDE with Jest tests now that we use the Angular CLI.  When creating and running a configuration with coverage through the IDE, I get the error below.


/usr/local/bin/node --require "/Applications/IntelliJ" /Users/REMOVED/dev/code/PROJECT/node_modules/@angular/cli/bin/ng test APPNAME --codeCoverage --colors --reporters "/Applications/IntelliJ" --verbose --coverage --coverageReporters=lcov --coverageDirectory /private/var/folders/ms/50h2z24n0676sj2mmfd632xcl4m20b/T/jest-intellij-coverage-2 --testPathPattern=^/Users/REMOVED/dev/code/PROJECT/apps/APPNAME/src/app/PATH/TO/SPEC/FILE.ts$
Unknown option: '--coverage'

Process finished with exit code 1


This is due to the fact that the `--coverage` parameter for Jest needs to be passed to the Angular CLI as `--codeCoverage`.  Are there any plans to have more integrated Angular CLI run configurations so that we can see line coverage in the IDE?

1 comment
Comment actions Permalink

I don't have issues running Angular Jest tests with coverage:

can you reproduce the issue with a new cli project?

My package.json:

"name": "angular-jest",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
"private": true,
"dependencies": {
"@angular/animations": "~9.1.11",
"@angular/common": "~9.1.11",
"@angular/compiler": "~9.1.11",
"@angular/core": "~9.1.11",
"@angular/forms": "~9.1.11",
"@angular/platform-browser": "~9.1.11",
"@angular/platform-browser-dynamic": "~9.1.11",
"@angular/router": "~9.1.11",
"rxjs": "~6.5.4",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
"devDependencies": {
"@angular-builders/jest": "^9.0.1",
"@angular-devkit/build-angular": "~0.901.8",
"@angular/cli": "~9.1.8",
"@angular/compiler-cli": "~9.1.11",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/jest": "^26.0.0",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
"jest": "^26.0.1",
"protractor": "~7.0.0",
"ts-node": "~8.3.0",
"tslint": "~6.1.0",
"typescript": "~3.8.3"



Please sign in to leave a comment.