gulp-istanbul icon indicating copy to clipboard operation
gulp-istanbul copied to clipboard

Running serveral istanbul tasks at the same time

Open traviswimer opened this issue 9 years ago • 6 comments

I have a project that contains both client-side (browserify) code and server-side code, each with separate unit tests. If I try to run istanbul with both tests in parallel, one seem to end up superseding the other. In other words, both coverage reports end up being identical, with only the client-side tests included.

I'm not entirely sure if this is an issue. I may simply not understand how to accomplish parallel istanbul tasks or this was intentional in the design of istanbul.

This isn't a major problem as my workaround for this has been to use run-squence to prevent the tasks from running in parallel:

gulp.task('test', function(callback){
    runSequence(
        'serverUnitTests',
        'clientUnitTests',
        callback
    );
});

I am mostly just curious if there is a better way to do this.

traviswimer avatar Sep 28 '14 17:09 traviswimer

Well, I'd need more detail about what is happening in order to help you...

Did you defined differents coverage variable names? Do you use the instrumented content returned by the stream or the require() overrides?

SBoudrias avatar Sep 28 '14 17:09 SBoudrias

I did attempt using different coverageVaribales, but for some reason that caused the reports to be completely empty. I don't exactly understand the purpose of the coverageVariable option, so I was kind of just taking a stab in the dark.

If I understand your second question correctly, I was using the content returned by the streams.

In case it helps, here is the relevant code from my tasks. (I left out defining enforcerOptions, handleError and config for the sake of brevity, but you get the idea.)


gulp.task( 'test', ['serverUnitTests','clientUnitTests'] );


gulp.task('clientUnitTests', function(callback) {
    var coverageVar = '$$client_cov_' + new Date().getTime() + '$$';
    gulp.src( [config.client.js.src + '/**/*.js'] )
        // Instrument source code
        .pipe( istanbul({
            coverageVariable: coverageVar
        }) )
        .on('finish', function (){
            // Load tests into mocha
            gulp.src( [config.client.js.unitTests + '/**/*_test.js'] )
                .pipe(
                    mocha({
                        reporter: 'spec'
                    })
                    .on( 'error', handleError )
                )
                // Create coverage reports
                .pipe(istanbul.writeReports({
                    dir: config.client.root + '/coverage',
                    reporters: ['html', 'lcov', 'text-summary', 'json'],
                    reportOpts: {
                        dir: config.client.root + '/coverage'
                    },
                    coverageVariable: coverageVar
                }))
                // Throw error if coverage thresholds not met
                .pipe( istanbulEnforcer(enforcerOptions) )
                .on( 'error', handleError )
                .on( 'end', callback );
        });
});


gulp.task('serverUnitTests', function(callback) {
    var coverageVar = '$$server_cov_' + new Date().getTime() + '$$';
    gulp.src( [config.server.src + '/*.js', config.server.src + '/**/*.js'] )
        // Instrument source code
        .pipe(
            istanbul({
                coverageVariable: coverageVar
            })
        )
        .on('finish', function (){
            // Load tests into mocha
            gulp.src( [config.server.unitTests + '/*_test.js', config.server.unitTests + '/**/*_test.js'] )
                .pipe(
                    mocha({
                        reporter: 'spec'
                    })
                    .on( 'error', handleError )
                )
                // Create coverage reports
                .pipe(istanbul.writeReports({
                    dir: config.server.root + '/coverage',
                    reporters: ['html', 'lcov', 'text-summary', 'json'],
                    reportOpts: {
                        dir: config.server.root + '/coverage'
                    },
                    coverageVariable: coverageVar
                }))
                // Throw error if coverage thresholds not met
                .pipe( istanbulEnforcer(enforcerOptions) )
                .on( 'error', handleError )
                .on( 'end', callback );
        });
});


traviswimer avatar Sep 28 '14 20:09 traviswimer

My scenario is the same and I'm experiencing the same issue.

jednano avatar Dec 04 '14 19:12 jednano

Can one of your create a standalone repository on github reproducing the issue. If I can run and see what's wrong it'll help.

SBoudrias avatar Dec 04 '14 20:12 SBoudrias

What's wrong is https://github.com/SBoudrias/gulp-istanbul/blob/master/index.js#L18 The COVERAGE_VARIABLE is set once at the top of the file, and used for every istanbul run. If you're going to run two executions simultaniously, you need to pass in your own opts.coverageVariable to each gulp-istanbul method. (FYI, this is also why if you have no files to cover, you get the previous run's results.)

robrich avatar Dec 15 '14 16:12 robrich

+1 for this fix. I run into an issue where files from the previous run are getting included in a later run via a gulp pipeline. +1 for @robrich's comment.

vhmth avatar Oct 06 '15 18:10 vhmth