From 4209c99ddb8e48b6fc914afc51be7ec34e27ca84 Mon Sep 17 00:00:00 2001 From: Leif Wells Date: Tue, 5 Sep 2017 10:48:30 -0400 Subject: [PATCH 1/2] Added coverage per @lathonez --- package.json | 3 +++ test-config/karma.conf.js | 7 ++++++- test-config/webpack.test.js | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 7f7e005..c17d5bb 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "ionic:serve": "ionic-app-scripts serve", "test": "karma start ./test-config/karma.conf.js", "test-ci": "karma start ./test-config/karma.conf.js --single-run", + "test-coverage": "karma start ./test-config/karma.conf.js --coverage", "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" @@ -40,10 +41,12 @@ "@types/node": "^7.0.8", "angular2-template-loader": "^0.6.2", "html-loader": "^0.4.5", + "istanbul-instrumenter-loader": "^3.0.0", "jasmine": "^2.5.3", "jasmine-spec-reporter": "^4.1.0", "karma": "^1.5.0", "karma-chrome-launcher": "^2.0.0", + "karma-coverage-istanbul-reporter": "^1.3.0", "karma-jasmine": "^1.1.0", "karma-jasmine-html-reporter": "^0.2.2", "karma-sourcemap-loader": "^0.3.7", diff --git a/test-config/karma.conf.js b/test-config/karma.conf.js index 1a536be..cf90521 100755 --- a/test-config/karma.conf.js +++ b/test-config/karma.conf.js @@ -44,7 +44,12 @@ module.exports = function(config) { terminal: true }, - reporters: ['kjhtml', 'dots'], + coverageIstanbulReporter: { + reports: [ 'html', 'lcovonly' ], + fixWebpackSourcePaths: true + }, + + reporters: config.coverage ? ['kjhtml', 'dots', 'coverage-istanbul'] : ['kjhtml', 'dots'], port: 9876, colors: true, logLevel: config.LOG_INFO, diff --git a/test-config/webpack.test.js b/test-config/webpack.test.js index 5bf5604..b145db4 100755 --- a/test-config/webpack.test.js +++ b/test-config/webpack.test.js @@ -15,6 +15,15 @@ module.exports = { loader: 'ts-loader' }, 'angular2-template-loader'] }, + { + test: /.+\.ts$/, + exclude: /(index.ts|mocks.ts|\.spec\.ts$)/, + loader: 'istanbul-instrumenter-loader', + enforce: 'post', + query: { + esModules: true + } + }, { test: /\.html$/, loader: 'html-loader?attrs=false' From 036de1ec39af6a7aedae9b4509aaec56771ffb4e Mon Sep 17 00:00:00 2001 From: Leif Wells Date: Tue, 5 Sep 2017 14:02:51 -0400 Subject: [PATCH 2/2] Update README file --- README.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5c905a4..9c98ca4 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,20 @@ Special thanks to all of the contributors. With the exception of the Ionic team' UPDATES: -------- -### **2017-08-26: Update to `ionic-angular` version 3.6.0** +### **2017-09-05: Added Code Coverage Functionality** -We updated the project to `ionic-angular` version `3.6.0`. Developers wishing to use this should also update Ionic CLI for a better experience. With today's update, this project is now at version `0.0.5`. +Thanks to @lathonez, we now have functioning code coverage functionality. With this update, developers can run `npm run test-coverage` which will run the project's unit tests with Karma and produce documentation that gives guidance on how well the project's tests cover the code. + +![Example Image of Completed Code Coverage](https://user-images.githubusercontent.com/1648535/30074946-54a36e50-9241-11e7-9ca8-6263d0353c58.png) + +The documentation is created inside the `/coverage` folder (ignored by git). ## **Also of note:** +### **2017-08-26: Update to `ionic-angular` version 3.6.0** + +We updated the project to `ionic-angular` version `3.6.0`. Developers wishing to use this should also update Ionic CLI for a better experience. With today's update, this project is now at version `0.0.5`. + ## **Added: Fix for assets not being found by Karma** Thanks to [@datencia](https://github.com/datencia) for providing an update to our Karma configuration that properly sets the Karma base path so that image assets can be found during testing. This fix should also work any JSON data files you might want to use for testing. He also provided an image and updated our sample unit test spec file that tests that the image is found.