Angular-cli test coverage all files

前端 未结 6 1215
灰色年华
灰色年华 2021-02-07 09:16

I am running the following command to unit test and generate code code coverage report.

ng test --code-coverage

It is writing code coverage re

6条回答
  •  悲&欢浪女
    2021-02-07 10:01

    I've just created karma plugin, which adds all the files in the project to coverage statistic - https://github.com/kopach/karma-sabarivka-reporter.

    To use it → install npm install --save-dev karma-sabarivka-reporter

    And update karma.conf.js like this:

    reporters: [
      // ...
      'sabarivka'
      // ...
    ],
    coverageReporter: {
        include: 'src/**/!(*.spec|*.module|environment*).ts', // glob patter which  matchs all the files you want to be included into the coverage result
        exclude: 'src/main.ts',
        // ...
    },
    

    This solves issue without any other manipulation. Easy to add to existing projects as well as to new ones.

提交回复
热议问题