3

I'm trying to generate istanbul coverage report for my node js es6 application that has mocha tests. I have used isparta to instrument code and also babel to transpile from ES6 to ES5, but unfortunately nothing has worked. Is anyone successful in generating code coverage report using gulp istanbul. When I run the nyc from command line on non ES6 code coverage report is coming up well (I've some unit tests written on non ES6 style). Please find the code below.

gulp.task('coverage',function(cb){
    return gulp.src(['./server/controllers/*.js','./server/services/*.js'])
        .pipe(istanbul({
            includeUntested:true,
            instrument: Instrumenter,
        excludes:[['*.spec.js', '*.watcherSpec.js','*.intspec.js',]]}))
        .pipe(babel({
            plugins:[["transform-es2015-arrow-functions",{ "spec": true }]]
        }))
        .pipe(istanbul.hookRequire()) //force 'require' to return covered files
})

gulp.task('api-tests', ['coverage'], function (cb) {
    gulp.src(['./server/**/*.intspec.js'])
        .pipe(mocha({
            harmony: true,
            timeout: '10000',
            reporter: 'spec',
            excludes: ['*.spec.js', '*.watcherSpec.js'],
            env: {
                'NODE_ENV': 'integration-testing',
                'hostedAddress': hostedAddress
            }
        }))
        .pipe(istanbul.writeReports({
            dir: './coverage',
            reporters: [ 'html' ],
            reportOpts: { dir: './coverage'}
        }))
        .on('end', cb);
});
Ajay Srikanth
  • 1,095
  • 4
  • 22
  • 43

0 Answers0