lathonez / clicker

Ionic 2 + @angular/cli Seed Project : Angular2 + Typescript + Karma + Protractor + Travis
http://lathonez.com/2018/ionic-2-unit-testing/
MIT License
430 stars 137 forks source link

How to Exclude a folder with typeScript from karma & coverage. #221

Closed FJLopezGarcia closed 7 years ago

FJLopezGarcia commented 7 years ago

Hi, do you know how to Exclude a folder that contains TypeScripts from karma coverage?

lathonez commented 7 years ago

I am AFK this weekend. I don't know if there is a better way than modifying the regexp in src/test.ts (const context).

You could ask on the Ng-cli repo. On Fri, 3 Feb 2017 at 23:00, Javi notifications@github.com wrote:

Hi guys, Do you know how to Exclude some folder with TypeScripts from karma & coverage?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lathonez/clicker/issues/221, or mute the thread https://github.com/notifications/unsubscribe-auth/AG5tSG8i_Z9t--R6zfNysZDgkO-B9mgXks5rYxbZgaJpZM4L2P95 .

emroussel commented 7 years ago

I added this inside remapIstanbulReporter in karma.conf.js to exclude set up files from test coverage

remapIstanbulReporter: {
  remapOptions: {
    exclude: /src\/(mocks.ts|test.ts|polyfills.ts)/
  }
},

You can modify the regex to match the path of the folders you want to exclude.

FJLopezGarcia commented 7 years ago

thanks a lot @lathonez and @emmanuelroussel.

Do you know how to exclude two different paths with regex ?? I need to exclude /src\/(mocks.ts|test.ts|polyfills.ts)/ and two new files (api.ts and CompanyApi.ts) from src/app/common/api/ path.

Thanks a lot for your help!!

emroussel commented 7 years ago

I think you can simply add the rest of the path of api.ts and CompanyApi.ts to the regex like this

/src/(mocks.ts|test.ts|polyfills.ts|app/common/api/api.ts|app/common/api/CompanyApi.ts)/

It gets a bit ugly, but it should work.

emroussel commented 7 years ago

@lathonez would like me to make a PR to exclude test config files from test coverage by default?

lathonez commented 7 years ago

@emmanuelroussel - I would, but it should be a PR to ng-cli not to us:

https://github.com/angular/angular-cli/issues/3356

jquagliatini commented 7 years ago

@filipesilva provided a new syntax for the .angular-cli.json file

angular/angular-cli#4966

  "test": {
    "codeCoverage": {
      "exclude": [
        "src/polyfills.ts",
        "**/test.ts"
      ]
    },
    "karma": {
      "config": "./karma.conf.js"
    }
  },
lathonez commented 7 years ago

@1M0reBug awesome, thanks for the reference.

Reopening to track merging the upstream change.