ONOS-6524: Added Code Coverage tools to gulp
When `gulp test` is executed, Karma will now generate an interactive html report for code coverage in each file. The folder can be found in web/gui/src/main/webapp/tests/coverage
Change-Id: I951ac1bea7f3f0ca35deb9cc823bb883bcd9f8a5
diff --git a/.gitignore b/.gitignore
index 307c56c..f7bbf70 100644
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@
web/gui/src/main/webapp/tests/node_modules
web/gui/src/test/_karma/node_modules
web/gui/src/main/webapp/node_modules/
+web/gui/src/main/webapp/tests/coverage
web/gui/src/main/webapp/dist/
npm-debug.log
diff --git a/tools/gui/gulp-tasks/bundles/unit-tests/index.js b/tools/gui/gulp-tasks/bundles/unit-tests/index.js
new file mode 100644
index 0000000..2d0b903
--- /dev/null
+++ b/tools/gui/gulp-tasks/bundles/unit-tests/index.js
@@ -0,0 +1,20 @@
+import gulp from 'gulp';
+import istanbul from 'gulp-istanbul';
+import path from 'path';
+import { Server } from 'karma';
+
+const tests = ['../../web/gui/src/main/webapp/tests/**/*.js'];
+
+const test = () => {
+ new Server({
+ configFile: path.join(__dirname, '../../../../../', '/web/gui/src/main/webapp/tests/karma.conf.js'),
+ singleRun: true
+ }, () => { console.log('done') }).start();
+};
+
+const tasks = () => {
+ gulp.task('pre-test', () => preTest());
+ gulp.task('test', () => test());
+};
+
+export default tasks();
\ No newline at end of file
diff --git a/tools/gui/gulp-tasks/index.js b/tools/gui/gulp-tasks/index.js
index 3bef084..5ac5c83 100644
--- a/tools/gui/gulp-tasks/index.js
+++ b/tools/gui/gulp-tasks/index.js
@@ -1,2 +1,3 @@
export { default as BundleJS } from './bundles/bundle-js';
-export { default as BundleCSS } from './bundles/bundle-css';
\ No newline at end of file
+export { default as BundleCSS } from './bundles/bundle-css';
+export { default as UnitTests } from './bundles/unit-tests';
\ No newline at end of file
diff --git a/tools/gui/gulpfile.babel.js b/tools/gui/gulpfile.babel.js
index 0d39b04..7c5056d 100644
--- a/tools/gui/gulpfile.babel.js
+++ b/tools/gui/gulpfile.babel.js
@@ -2,6 +2,7 @@
import * as Tasks from './gulp-tasks/';
gulp.task('build', ['bundle-css', 'bundle-vendor', 'bundle-js']);
+gulp.task('tests', ['test']);
gulp.task('default', function() {
// Do stuff
diff --git a/tools/gui/package.json b/tools/gui/package.json
index bd76963..8dffa34 100644
--- a/tools/gui/package.json
+++ b/tools/gui/package.json
@@ -16,9 +16,23 @@
"babel-preset-es2015": "^6.24.1",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
+ "gulp-istanbul": "^1.1.2",
+ "gulp-jasmine": "^2.4.2",
+ "gulp-karma": "0.0.5",
"gulp-sourcemaps": "^2.6.0",
"gulp-strip-comments": "^2.4.5",
- "gulp-uglify": "^3.0.0"
+ "gulp-uglify": "^3.0.0",
+ "jasmine-core": "^2.6.4",
+ "karma": "^1.7.0",
+ "karma-babel-preprocessor": "^6.0.1",
+ "karma-chrome-launcher": "^2.2.0",
+ "karma-coverage": "^1.1.1",
+ "karma-jasmine": "^1.1.0",
+ "karma-junit-reporter": "^1.2.0",
+ "karma-mocha-reporter": "^2.2.3",
+ "karma-ng-html2js-preprocessor": "^1.0.0",
+ "karma-phantomjs-launcher": "^1.0.4",
+ "phantomjs": "^2.1.7"
},
"babel": {
"presets": [
diff --git a/web/gui/src/main/webapp/tests/karma.conf.js b/web/gui/src/main/webapp/tests/karma.conf.js
index 265e325..8e9cd39 100644
--- a/web/gui/src/main/webapp/tests/karma.conf.js
+++ b/web/gui/src/main/webapp/tests/karma.conf.js
@@ -56,14 +56,18 @@
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
+ '../app/**/*.js': 'coverage'
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
- reporters: ['mocha'],
-
+ reporters: ['mocha', 'coverage'],
+ coverageReport: {
+ type: 'html',
+ dir : 'coverage/'
+ },
// web server port
port: 9876,