From b13dc053f6b5b35c475d31f7da7cfa6eec8ba156 Mon Sep 17 00:00:00 2001 From: Bob Anderson Date: Sun, 25 Oct 2015 17:25:10 -0400 Subject: [PATCH] Add karma-coverage --- .gitignore | 3 ++- README.md | 9 +++++++++ karma.conf.js | 19 +++++++++++++++++++ package.json | 6 +----- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b702acc68f..de0051d9d0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ logs/* !.gitkeep +build/ node_modules/ bower_components/ tmp .DS_Store -.idea \ No newline at end of file +.idea diff --git a/README.md b/README.md index e7aece1083..11fe7a034b 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,14 @@ predefined script to do this: ``` npm run test-single-run ``` +#### Code Coverage Reports +Unit test coverage reports are automatically generated using the [karma-coverage][karma-coverage] plugin. +This plugin creates an HTML code coverage report with [Istanbul][istanbul] to give you Statement, Branch, +Function, and Line coverage statistics for your tests. + +* the configuration is found at 'karma.conf.js' +* the reports are available under 'build/reports/coverage/' ### End to end testing @@ -293,5 +300,7 @@ For more information on AngularJS please check out http://angularjs.org/ [protractor]: https://github.com/angular/protractor [jasmine]: http://jasmine.github.io [karma]: http://karma-runner.github.io +[karma-coverage]: https://github.com/karma-runner/karma-coverage +[istanbul]: https://github.com/gotwarlost/istanbul [travis]: https://travis-ci.org/ [http-server]: https://github.com/nodeapps/http-server diff --git a/karma.conf.js b/karma.conf.js index 44bb29f1ab..b60d44737f 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -7,6 +7,7 @@ module.exports = function(config){ 'app/bower_components/angular/angular.js', 'app/bower_components/angular-route/angular-route.js', 'app/bower_components/angular-mocks/angular-mocks.js', + 'app/*.js', 'app/components/**/*.js', 'app/view*/**/*.js' ], @@ -21,9 +22,27 @@ module.exports = function(config){ 'karma-chrome-launcher', 'karma-firefox-launcher', 'karma-jasmine', + 'karma-coverage', 'karma-junit-reporter' ], + // coverage reporter generates the coverage + reporters: ['progress', 'coverage'], + + preprocessors: { + // source files, that you want to generate coverage for + // do not include tests or libraries + // these files will be instrumented by Istanbul + 'app/app.js': ['coverage'], + 'app/components/**/!(*_test).js': ['coverage'], + 'app/view*/!(*_test).js': ['coverage'] + }, + + coverageReporter: { + type : 'html', + dir : 'build/reports/coverage/' + }, + junitReporter : { outputFile: 'test_out/unit.xml', suite: 'unit' diff --git a/package.json b/package.json index d0edbc8b61..483c4a0f71 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "jasmine-core": "^2.3.4", "karma": "~0.12", "karma-chrome-launcher": "^0.1.12", + "karma-coverage": "^0.5.3", "karma-firefox-launcher": "^0.1.6", "karma-jasmine": "^0.3.5", "karma-junit-reporter": "^0.2.2", @@ -19,20 +20,15 @@ }, "scripts": { "postinstall": "bower install", - "prestart": "npm install", "start": "http-server -a localhost -p 8000 -c-1", - "pretest": "npm install", "test": "karma start karma.conf.js", "test-single-run": "karma start karma.conf.js --single-run", - "preupdate-webdriver": "npm install", "update-webdriver": "webdriver-manager update", - "preprotractor": "npm run update-webdriver", "protractor": "protractor e2e-tests/protractor.conf.js", - "update-index-async": "node -e \"require('shelljs/global'); sed('-i', /\\/\\/@@NG_LOADER_START@@[\\s\\S]*\\/\\/@@NG_LOADER_END@@/, '//@@NG_LOADER_START@@\\n' + sed(/sourceMappingURL=angular-loader.min.js.map/,'sourceMappingURL=bower_components/angular-loader/angular-loader.min.js.map','app/bower_components/angular-loader/angular-loader.min.js') + '\\n//@@NG_LOADER_END@@', 'app/index-async.html');\"" } }