Skip to content

Commit 3dfc070

Browse files
committed
Merge pull request #19 from FullstackAcademy/test-coverage
Test coverage reporting
2 parents 799ef51 + 978d1a3 commit 3dfc070

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ generated/public
55
node_modules
66
bower_components
77
npm-debug.log
8-
.DS_Store
8+
.DS_Store
9+
coverage/

generated/gulpfile.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ var sourcemaps = require('gulp-sourcemaps');
1616
var eslint = require('gulp-eslint');
1717
var mocha = require('gulp-mocha');
1818
var karma = require('karma').server;
19+
var istanbul = require('gulp-istanbul');
1920

2021
// Development tasks
2122
// --------------------------------------------------------------
@@ -48,9 +49,21 @@ gulp.task('buildJS', ['lintJS'], function () {
4849
.pipe(gulp.dest('./public'));
4950
});
5051

51-
gulp.task('testServerJS', function () {
52-
return gulp.src('./tests/server/**/*.js', {read: false})
53-
.pipe(mocha({reporter: 'spec'}));
52+
gulp.task('testServerJS', function (done) {
53+
gulp.src('./server/**/*.js')
54+
.pipe(istanbul({
55+
includeUntested: true
56+
}))
57+
.pipe(istanbul.hookRequire())
58+
.on('finish', function () {
59+
gulp.src('./tests/server/**/*.js', {read: false})
60+
.pipe(mocha({reporter: 'spec'}))
61+
.pipe(istanbul.writeReports({
62+
dir: './coverage/server/',
63+
reporters: ['html', 'text']
64+
}))
65+
.on('end', done);
66+
});
5467
});
5568

5669
gulp.task('testBrowserJS', function (done) {

generated/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,10 @@
5555
"socket.io": "^1.3.4",
5656
"socket.io-client": "^1.3.5",
5757
"supertest": "^0.15.0"
58+
},
59+
"devDependencies": {
60+
"gulp-istanbul": "^0.9.0",
61+
"karma-coverage": "^0.2.7",
62+
"karma-mocha-reporter": "^1.0.2"
5863
}
5964
}

generated/tests/browser/karma.conf.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,21 @@ module.exports = function (config) {
2323
frameworks: ['mocha', 'chai'],
2424
basePath: path.join(__dirname, '../../'),
2525
files: filesCollection,
26-
exclude: excludeFiles
26+
exclude: excludeFiles,
27+
reporters: ['mocha', 'coverage'],
28+
preprocessors: {
29+
'public/main.js': 'coverage'
30+
},
31+
coverageReporter: {
32+
dir: 'coverage/browser/',
33+
reporters: [{
34+
type: 'text',
35+
subdir: '.'
36+
}, {
37+
type: 'html',
38+
subdir: '.'
39+
}]
40+
}
2741
};
2842

2943
config.set(configObj);

0 commit comments

Comments
 (0)