question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Tests no longer failing on code coverage lower than threshold

See original GitHub issue

From @pkspks on May 18, 2018 4:16

Bug Report or Feature Request (mark with an x)

- [x] bug report 
- [ ] feature request

Area

- [x] devkit
- [ ] schematics

Versions

$ npm --version
6.0.1
$ node --version
v10.1.0
$ npm list @angular-devkit/build-angular
.....
`-- @angular-devkit/build-angular@0.6.3

Repro steps

Enable Istanbul code coverage in karma by specifying threshold. e.g. karma.conf.js

    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, 'coverage'),
      reports: ['html', 'lcovonly', 'cobertura'],
      fixWebpackSourcePaths: true,
      thresholds: {
        statements: 98,
        branches: 80,
        functions: 97,
        lines: 98
      }
    },

Then run ng test --code-coverage

The log given by the failure

$ ng test --code-coverage                                                                                                                                                                              
 10% building modules 1/1 modules 0 active(node:11812) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead                                                               
18 05 2018 14:12:50.973:INFO [karma]: Karma v2.0.2 server started at http://0.0.0.0:9876/                                                                                                              
18 05 2018 14:12:50.979:INFO [launcher]: Launching browser Chrome with unlimited concurrency                                                                                                           
18 05 2018 14:12:50.988:INFO [launcher]: Starting browser Chrome                                                                                               18 05 2018 14:13:02.930:INFO [Chrome 66.
3359 (Windows 10 0.0.0)]: Connected on socket xnq32DY33fYmjFJGAAAA with id 69646099                                                                                                                    
.........................................                                                                                                                                                              
Chrome 66.0.3359 (Windows 10 0.0.0): Executed 41 of 41 SUCCESS (0.52 secs / 0.446 secs)                                                                                                                
18 05 2018 14:13:06.579:ERROR [reporter.coverage-istanbul]: Coverage for statements (97.99%) does not meet global threshold (98%)                                                                      
18 05 2018 14:13:06.580:ERROR [reporter.coverage-istanbul]: Coverage for functions (96%) does not meet global threshold (97%)                                                                          
                                                                                                                                                                                                       
---------                                                                                                                                          
$ echo $?                                                                                                                                                                                              
0                                                                                                                                                                                                      

Desired functionality

Mention any other details that might be useful

Exit code should be 1 like it was with Angular 4.

Copied from original issue: angular/devkit#935

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
bhattrupcommented, Mar 14, 2019

I am having the same issue with what i believe is all the latest bits: I am using the --no-watch argument, and I can confirm the karma-coverage-istanbul-reporter is returning exitCode=1 to the karma\lib\server into the disconnectBrowsers() function, but it doesn’t look like the obs.complete() observable is consuming this exitCode.

can you please provide some guidance? i have created new (basically empty) angular library project with: node = v10.15.2; npm = 6.4.1; “@angular-devkit/build-angular”: “~0.13.0”, “@angular/cli”: “~7.3.5”,

PS C:_projects\Web\kinetic-erp> ng test kinetic-erp --no-watch --code-coverage 14 03 2019 16:17:41.619:INFO [karma-server]: Karma v4.0.1 server started at http://0.0.0.0:9876/ 14 03 2019 16:17:41.632:INFO [launcher]: Launching browsers Chrome with concurrency unlimited 14 03 2019 16:17:41.642:INFO [launcher]: Starting browser Chrome 14 03 2019 16:17:50.625:INFO [Chrome 72.0.3626 (Windows 10.0.0)]: Connected on socket QAQfsPPIi19zhkgAAAAA with id 62310915 Chrome 72.0.3626 (Windows 10.0.0): Executed 3 of 3 SUCCESS (0.063 secs / 0.123 secs) TOTAL: 3 SUCCESS TOTAL: 3 SUCCESS 14 03 2019 16:17:54.537:ERROR [reporter.coverage-istanbul]: Coverage for branches (50%) does not meet global threshold (80%) 14 03 2019 16:17:54.539:ERROR [reporter.coverage-istanbul]: Coverage for functions (66.67%) does not meet global threshold (80%) PS C:_projects\Web\kinetic-erp> echo $? True <— it appears on windows, the value here is truthy to indicate success instead of the exitCode

1reaction
ratoaq2commented, Jan 17, 2019

Can I use ~0.8.1 with Angular 6.0.6 or I need to upgrade Angular? It would be nice to know what was the fix because I’m running into the same issue and upgrade Angular is not an option for the moment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest test coverage does not fail when threshold is not met
When running test:coverage the console reports that thresholds were not met, but still returns 0. My understanding from the Jest documentation ...
Read more >
Code Coverage: The Metric That Makes Your Tests Worse.
One way of applying code coverage is by using it in your build script. By having a threshold in your script, you can...
Read more >
How to stop a decrease of code coverage in a pull request
This should, in almost all cases, ensure that coverage on new code is always meeting a certain threshold. As long as that threshold...
Read more >
Enabling Code coverage For Jest - Jon D Jones
You can force Jest to fail a build if the code coverage is below a minimum threshold. My recommendation is to set the...
Read more >
Code Coverage - The metric that can make your tests worse
Teams sometimes calculate code coverage during the build and add a check that fails it when coverage drops below a predetermined threshold.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found