Angular-cli: Ignore files/folders from code coverage report

Created on 2 Dec 2016  路  8Comments  路  Source: angular/angular-cli

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
Windows 10

Versions.

Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here:

angular-cli: 1.0.0-beta.19-3
node: 5.10.1
os: win32 x64

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.
N/A

The log given by the failure.

Normally this include a stack trace and some more information.
N/A

Mention any other details that might be useful.

Is there any way to exclude files/folders from test coverage (other than naming them .spec.ts)?
For example if I wanted to put some reusable bits of test code in src/app/common/testing/
* I wouldn't want files included in this directory to be reported on.

Thanks!


Thanks! We'll be in touch soon.

easy (hours) 2 (required) feature

Most helpful comment

With the latest CLI 6+ add excluded files or paths to angular.json -> test -> options like so:

        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "./karma.conf.js",
            "codeCoverageExclude": ["src/testing/**/*"],

I should add, this addition was found by going through the schema

"$schema": "./node_modules/@angular/cli/lib/config/schema.json",

All 8 comments

Just wanted to make sure you all know that upgrading your project to karma-remap-istanbul:^0.3.0 will allow you to use their exclude property.
marcules/karma-remap-istanbul#26

I just tried installing karma-remap-istanbul:^0.3.0 and karma-remap-istanbul:^0.4.0 with no luck at all.
Excluded path includiing '/data/' still in reports.

karma.conf.js:
remapIstanbulReporter: {
remapOptions: {
exclude: '/data/',
},
reports: {
html: 'coverage',
lcovonly: './coverage/coverage.lcov'
}
},

Versions:
angular-cli: 1.0.0-beta.24

Thanks in advance for any ideas or help?

@nestor forgive me but I just want to be sure that you:

  • forced npm to install the new version not just updated the config
  • you are able to exclude something else using the remapOption exclude
  • understand that it will be trying to exclude the string /data/ not the regex pattern which would require you to remove the quotes.

Not totally sure myself how the string implementation works but if everything else checks maybe switch to regex?

HTH

Hi, @dpmorrow, answers follow:

  • I confirm that both version where installed using npm install command, which indeed update the package config once successfully dependency installed, not the opposite.
  • I was able to exclude something once I understood and got a matching filter.
  • Not sure if it it was a question, but the problem is not the exclude or string implementation, the problem is the LCOV input data is not platform independent, which in my case using windows, it uses backslash as path separator in SF values.

After some research look like istanbul generate the LCOV file depending on the platform which add a platfom dependen matching which a worked around using a regexp accepting slash and backslash as separator.

Will need some time to fork istanbul repo and test it under windows locally.

When RC is released you will be able to configure the following section in the .angular-cli.json file:

"test": {
  "codeCoverage": {
    "exclude": ["glob/to/ignore"]
  },
  ...
}

Fixed in master by #4966

With the latest CLI 6+ add excluded files or paths to angular.json -> test -> options like so:

        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "./karma.conf.js",
            "codeCoverageExclude": ["src/testing/**/*"],

I should add, this addition was found by going through the schema

"$schema": "./node_modules/@angular/cli/lib/config/schema.json",

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gotschmarcel picture gotschmarcel  路  3Comments

rajjejosefsson picture rajjejosefsson  路  3Comments

JanStureNielsen picture JanStureNielsen  路  3Comments

IngvarKofoed picture IngvarKofoed  路  3Comments

hartjo picture hartjo  路  3Comments