I use the following code and It was able to generate the mocha test (suite and tests) report as expected but Im not able to see the mocha test coverage with istanbul what am I missing here?
gulp.task('test', function () {
gulp.src(['./assets/**/js/*.js'])//Here I took it from the repo
.pipe(istanbul())
.pipe(tap(function (f) {
require(f.path);
}))
.on('end', function () {
gulp.src(['test/*spec.js'])//this is the path for my tests
.pipe(mocha({
reporter: 'mochawesome'
}))
.pipe(istanbul.writeReports(
['unit-test-coverage']
));
});
});
the following does not generate anything
.pipe(istanbul.writeReports(
['unit-test-coverage']
));
My project look like following
my app
-server.js
-app.js
-contoller
--file1.js
--file2.js
-test
spec1.js
spec2.js
-gulpfile.js
I use the following https://github.com/SBoudrias/gulp-istanbul and gulp mocha https://www.npmjs.com/package/gulp-mocha
And this is what I got after the code are running
19 passing (15s)
[mochawesome] Report saved to mochawesome-reports/mochawesome.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 )
================================================================================
UPDATE When I do the following it generate an report but the coverge but it seems that the code is not coverage well since I got 100% on of all the tests (I wish :-)) ,any idea what I miss here? since the mocha unit test run well just the code coverage doesnt work well
.pipe(istanbul.writeReports({
dir: './assets/unit-test-coverage',
reporters: ['html'],
reportOpts: {dir: './unit-test-coverage'}
}));
update 2
I build the same in GRUNT (since I was lost here :-( ) and this is working!!!!!
but still I want to make it work in Gulp, please help!
I try to sperate all the dependcies and create this minor gulp file and run just it and still the same issue
This is the new file and I use diffrent technuiqe but same results :(
var gulp = require('gulp');
var istanbul = require('gulp-istanbul');
var mocha = require('gulp-mocha');
gulp.task('pre-test', function () {
return gulp.src(['./assets/**/js/*.js'])
// Covering files
.pipe(istanbul(
{includeUntested: true}
))
.pipe(istanbul.hookRequire());
});
gulp.task('test', ['pre-test'], function () {
return gulp.src(['test/*spec.js'])
.pipe(mocha({
reporter: 'mochawesome'
}))
// Creating the reports after tests ran
.pipe(istanbul.writeReports({
dir: './assets/unit-test-coverage',
reporters: ['html'],
reportOpts: {dir: './unit-test-coverage'}
}))
.pipe(istanbul.enforceThresholds({thresholds: {global: 90}}));
});
gulp.task('default', [ 'test']);
WHAT am I missing here? the test file running OK just the coverage...
As it was in comment.
It seems you don't have assets
folder. Atleast "My project look like following" doesn't have it. Try
return gulp
// all js files from cwd excluding test folder and gulpfile
.src(['./**/*.js', '!test/', '!gulpfile.js'])
.pipe(istanbul(...))