Angular karma code coverage report folder not generated

10,732

Solution 1

The reason, your code coverage is not generating is that, there are some broken unit tests which stops the generation of the code coverage folder. Even though, it is generates some times, but that also must be taking much time then usual. Follow the below steps, in order to identify and fix the unit tests so that, code-coverage file will generate each time-

  1. Run the tests using npm test.
  2. Open the browser and check the tests, there shouldn't be any broken or failed tests case.
  3. It shouldn't give any console error (Verify on console and fix it.)
  4. Verify that all the unit tests are running and passing successfully. Sometimes it shows passed unit tests, but it gives some popup errors or console errors, so these tests prevents the unit test code coverage generation.

Fix all the tests and it should generate the unit tests code coverage folder everytime.

Solution 2

In my case everything seemed correct, but no coverage files or messages were generated on the console.

What solved the problem was editing angular.json, adding the following key:

projects.ClientApp.test.options.codeCoverage = true;

Solution 3

Generate fresh code coverage folder through following command

node --max_old_space_size=4096 ./node_modules/karma/bin/karma start ./test-config/karma.conf.js --coverage
Share:
10,732
Raj Kumar
Author by

Raj Kumar

Updated on June 21, 2022

Comments

  • Raj Kumar
    Raj Kumar about 2 years

    When I run ng test --code-coverage, The coverage report is sometimes not generating, sometimes it is generating so I'm unable to verify the coverage statement after doing test suites.

    My Karma configuration

    // 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-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'),
          reports: ['html', 'lcovonly'],
          fixWebpackSourcePaths: true
        },
        reporters: ['progress', 'kjhtml'],
        port: 9876,
        colors: true,
        logLevel: config.LOG_INFO,
        autoWatch: true,
        browsers: ['Chrome'],
        singleRun: false
      });
    };
    
  • Raj Kumar
    Raj Kumar almost 5 years
    No,But the test suites are all green only . There is no error or break
  • Raj Kumar
    Raj Kumar almost 5 years
    But i did 'nt check console error , will check again, Thanks,
  • Neeraj Shende
    Neeraj Shende almost 5 years
    Just check on the console, or if you getting error alerts, then resolve all of them. I had the similar issues when fixing them and it had taken me much time to identify the exact problem.
  • Neeraj Shende
    Neeraj Shende almost 5 years
    Also, if it does help then don't forget to vote the answer.
  • Raj Kumar
    Raj Kumar almost 5 years
    Hi , I have got a warning error in console.It looks like you're using ngModel on the same form field as formControlName. Support for using the ngModel input property and ngModelChange event with reactive form directives has been deprecated in Angular v6 and will be removed in Angular v7.
  • Neeraj Shende
    Neeraj Shende almost 5 years
    Try to fix that somehow and you can try with --sourceMap=false option, which will help you to understand error in detail.