Skip to content

Add Test Coverage #12

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add Test Coverage #12

wants to merge 3 commits into from

Conversation

lathonez
Copy link
Contributor

@lathonez lathonez commented Mar 28, 2017

Followed the instructions on karma-coverage-istanbul-reporter and in particular this example config to add the minimal changes required to get coverage working.

You need an additional webpack loader (istanbul-instrumenter-loader) and to add karma-coverage-istanbul as a reporter.

The reason I've added a separate script in package.json (test-coverage) is that coverage breaks the sourcemaps: angular/angular-cli#1799 - so you don't want to run it all the time. Either that or you need an explicit debug as the ng-cli team did.

@morrisonbrett
Copy link

This is great! I'm using it and once I get it all working, I may submit a PR to your PR.

One thing though - what about custom Mocks? Would be great to have 1 in there as an example template.

@jeffgrady
Copy link

Hey, @lathonez , @morrisonbrett and others... I found this open PR to be incredibly useful in getting test coverage working in my own project.

I noticed it has a merge conflict, and rather than trying to do a PR-for-a-PR, I just wanted to mention I fixed the merge conflict locally and it's not difficult. I did this:

$ git fetch origin pull/12/head:lathonez_coverage_merge_fixes
$ git checkout lathonez_coverage_merge_fixes
$ git rebase -i master
$ git rebase --continue  # it doesn't print the filename of the conflict unless you do this
$ vi package.json

Make your package.json look like this. Just concat the lines together and add a trailing ,:

  "scripts": {
...
    "test": "karma start ./test-config/karma.conf.js",
    "test-ci": "karma start ./test-config/karma.conf.js --single-run",
    "e2e": "npm run e2e-update && npm run e2e-test",
    "e2e-test": "protractor ./test-config/protractor.conf.js",
    "e2e-update": "webdriver-manager update --standalone false --gecko false",
    "test-coverage": "karma start ./test-config/karma.conf.js --coverage"
  },

Then:

$ git add package.json
$ git rebase --continue
$ yarn install
$ npm run test-coverage
$ open coverage/index.html

screen shot 2017-08-24 at 3 52 09 pm

Again, thanks. This was super useful. Saved me a lot of time.

@jeffgrady
Copy link

I think it's worth fixing and merging this PR. If I found it useful, I'm sure others will, too. :)

@huntxiao
Copy link

huntxiao commented Jun 1, 2022

How do I configure it that I can make the test cases displayed on the command terminal but not browser?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants