afsarkhan10182
afsarkhan10182

Reputation: 2212

Want karma code coverage html without writing --code-coverage

The actual issue is ng command is not working as I am using windows 7.Lets forgot about the ng command issue.

So I am running like npm run ng test.

If I write npm run ng test --code-coverage = true it will run as ng test only.So I need to configure the code coverage (which generate a report and make a directory in which the HTML file is present) in karma configuration file (if possible).

Karma.conf.js:

module.exports = function (config) 
{
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    client:{
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      reports: [ 'html', 'lcovonly' ],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'], // ChromeHeadless
    singleRun: false
  });
};

Upvotes: 1

Views: 424

Answers (1)

Chetan Laddha
Chetan Laddha

Reputation: 1007

Run like npm test -- --cc

here after -- you pass anything will get accepted by the ng command.

Upvotes: 1

Related Questions