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.

Coverage is Always Zero

See original GitHub issue

I have been trying to add coverage reporting for unit testing of a fresh Angular project for weeks with no success…

Would be great if someone could help me. 🙏

My karma.conf.js:

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-coverage'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, './coverage/TddBdd2020'),
      reports: ['html', 'lcovonly', 'text-summary'],
      fixWebpackSourcePaths: true
    },
    // list of files / patterns to load in the browser
    files: [
      '**/src/**/*.js',
      // 'test/spec/**/*.ts'
    ],
    exclude: ['**/node_modules'],
    preprocessors: {'**src/**/*.ts': ['coverage']},
    reporters: ['coverage-istanbul'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false,
    restartOnFileChange: true,
    verbose: true
  });
};

output:

Screen Shot 2020-03-13 at 10 42 48 PM

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
JimLynchCodescommented, Mar 20, 2020

For anyone else having this problem, I finally figured it out after finding this blog post.

In the end, I was able to use the default karma config file from a fresh ng new scaffold with no changes to the karma file at all.

Just install the dependencies:

npm install karma karma-jasmine karma-chrome-launcher karma-jasmine-html-reporter karma-coverage-istanbul-reporter

And then add the --code-coverage flag when running the tests:

ng test --code-coverage

And now finally, it sees my files. 🎉

Screen Shot 2020-03-19 at 10 12 26 PM

0reactions
johnjbartoncommented, Mar 19, 2020

No, I am saying that you need to add something like karma-coverage to your config.

Read more comments on GitHub >

github_iconTop Results From Across the Web

maven - SonarQube coverage is always 0 - Stack Overflow
As the title suggests, the coverage metric is always appears to be 0 in the SQ report (on my server) despite me having...
Read more >
Code Coverage is showing 0% for java projects - SonarQube
Hi, We have recently upgraded our sonar application from 7.1 to 7.9.6 (LTS in 7.x). We have observed that code coverage is showing...
Read more >
Code Coverage percentage is 0% in SonarQube Dashboard
We are trying to run theCode Coverage Pipeline job in Jenkins then we are getting the below error and the Coverage is showing...
Read more >
Test coverage overview - SonarQube Documentation
Test coverage reports and test execution reports are important metrics in assessing the quality of your code.
Read more >
Test Result and Code Coverage is not showing in SonarQube
0 Votes. Test Result and Code Coverage is not showing in SonarQube ... 2017-07-27T19:06:03.0202938Z 16:06:02.989 Fetching code coverage report information ...
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