From 18013b06378c4646258bd8d1e2aa09df2d30f2b2 Mon Sep 17 00:00:00 2001 From: Tynarus Date: Mon, 11 Sep 2017 20:22:55 -0500 Subject: [PATCH] Adding new 'coverage' command to run unit test coverage reporting, reverting 'test' command to run auto-updating chrome test reporter. --- README.md | 1 + config/test/karma.conf.js | 9 ++++----- package.json | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 45b3bce..43d6854 100644 --- a/README.md +++ b/README.md @@ -13,5 +13,6 @@ A basic Angular 4 seed project utilizing the following technologies: * `npm start` - start the development webpack server (access via http://localhost:3000/) * `npm test` - run the project unit tests (*.spec.ts files) +* `npm run coverage` - run the project unit tests one time and print out a coverage report, generated under **/coverage/index.html** * `npm run lint` - run the project linting (will be run every time `npm test` is run) * `npm run build` - generate a production build for the project, which will be inserted into dist/ \ No newline at end of file diff --git a/config/test/karma.conf.js b/config/test/karma.conf.js index 22f1918..162b9f6 100644 --- a/config/test/karma.conf.js +++ b/config/test/karma.conf.js @@ -24,7 +24,8 @@ module.exports = function(config) { require('karma-sourcemap-loader') ], client:{ - clearContext: false + clearContext: false, + args: [ '--coverage', config.coverage ] }, webpack: webpackConfig, coverageIstanbulReporter: { @@ -34,14 +35,12 @@ module.exports = function(config) { exclude: /\*.spec.ts/ } }, - // TODO build flag/param to specify coverage mode - reporters: [ 'progress', /*'kjhtml', */'coverage-istanbul' ], + reporters: config.coverage ? [ 'progress', 'coverage-istanbul' ] : [ 'progress', 'kjhtml' ], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: [ 'Chrome' ], - // TODO coverage param applies to this, too! - singleRun: true + singleRun: config.coverage }); }; \ No newline at end of file diff --git a/package.json b/package.json index aec074c..5926280 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "scripts": { "start": "webpack-dev-server --inline --config config/build/webpack.dev.js --progress --port 3000", "test": "karma start config/test/karma.conf.js", + "coverage": "npm run lint && karma start config/test/karma.conf.js --coverage=true", "lint": "tslint -c config/tslint.json \"src/app/**/*.ts\"", "pretest": "npm run lint", "build": "rimraf dist && webpack --config config/build/webpack.prod.js --progress --profile --bail"