I'm using Qunit
framework to test a front-end Web application.
I have a requirement to generate report for code coverage. For that, I'm trying to use istanbul
through a gulp task. My gulpfile.js
looks like:
var gulp = require('gulp'),
qunit = require('gulp-qunit'),
istanbul = require('gulp-istanbul');
gulp.task('test1', function() {
return gulp.src('test/test.html')
.pipe(qunit());
});
gulp.task('test2', function () {
return gulp.src('lib/*.js')
// Covering files
.pipe(istanbul())
// Force `require` to return covered files
.pipe(istanbul.hookRequire());
});
gulp.task('test3', ['test2'], function () {
return gulp.src('test/test.html')
.pipe(qunit())
// Creating the reports after tests ran
.pipe(istanbul.writeReports())
// Enforce a coverage of at least 90%
.pipe(istanbul.enforceThresholds({ thresholds: { global: 90 } }));
});
Running test3
will finish successfully but code coverage is not.
Output for test3
:
[16:34:40] Using gulpfile ~\Documents\...\gulpfile.js
[16:34:40] Starting 'test2'...
[16:34:40] Finished 'test2' after 66 ms
[16:34:40] Starting 'test3'...
[16:34:40] Testing test.html
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|----------------|
=============================== Coverage summary ===============================
Statements : 100% ( 0/0 )
Branches : 100% ( 0/0 )
Functions : 100% ( 0/0 )
Lines : 100% ( 0/0 )
================================================================================
[16:34:46] Finished 'test3' after 5.11 s
[16:34:47] Took 7ms to run 1 tests. 1 passed, 0 failed.
[16:34:47] gulp-qunit: ✔ QUnit assertions all passed in test.html
Am I missing something here?