Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore files/folders from code coverage report #3356

Closed
k-schneider opened this issue Dec 2, 2016 · 8 comments
Closed

Ignore files/folders from code coverage report #3356

k-schneider opened this issue Dec 2, 2016 · 8 comments
Labels
effort1: easy (hours) feature Issue that requests a new feature P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@k-schneider
Copy link

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.

@hansl hansl added command: test effort1: easy (hours) P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent feature Issue that requests a new feature labels Dec 2, 2016
@dpmorrow
Copy link

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

@Wolfium
Copy link

Wolfium commented Jan 31, 2017

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?

@dpmorrow
Copy link

@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

@Wolfium
Copy link

Wolfium commented Feb 1, 2017

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.

@delasteve
Copy link
Contributor

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"]
  },
  ...
}

@hansl
Copy link
Contributor

hansl commented Feb 23, 2017

Fixed in master by #4966

@hansl hansl closed this as completed Feb 23, 2017
@gregbown
Copy link

gregbown commented May 14, 2018

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",

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
effort1: easy (hours) feature Issue that requests a new feature P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

6 participants