2

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
  1. what should I put here? gulp.src(['./assets/**/js/*.js']) ?
  2. how should I adopt my code to make it work?

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...

  • It seems you don't have `assets` folder. Atleast "My project look like following" doesn't have it. Try `return gulp.src(['/**/*.js', '!test/', '!gulpfile.js']).pipe(istanbul(...))` – Yury Tarabanko Jul 25 '16 at 12:41
  • @YuryTarabanko - thanks Yury you give some direction but it seems that when I want to use the root path of my files I should put them explicit way? I use now the following pattern './*/**.js', 'app.js', and as you can see I put the app.js explicit,there is a way to avoid it? –  Jul 25 '16 at 20:11
  • @YuryTarabanko - when I try the pattern you put I got permission error '/**/*.js' so I try this and this is working './*/**.js', 'app.js' ... you can add your replay as answer...Thanks! –  Jul 25 '16 at 20:13
  • Sure. You need cwd relative path. I have missed the dot :) – Yury Tarabanko Jul 25 '16 at 20:17

1 Answers1

0

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(...))
Yury Tarabanko
  • 44,270
  • 9
  • 84
  • 98
  • Thank a lot ,I've additional question please see if you can assist please :) –  Jul 26 '16 at 07:13
  • http://stackoverflow.com/questions/38583304/gulp-load-plugins-error-dep-is-not-defiend –  Jul 26 '16 at 07:13