Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running serveral istanbul tasks at the same time #39

Open
traviswimer opened this issue Sep 28, 2014 · 6 comments
Open

Running serveral istanbul tasks at the same time #39

traviswimer opened this issue Sep 28, 2014 · 6 comments

Comments

@traviswimer
Copy link

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.

@SBoudrias
Copy link
Owner

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?

@traviswimer
Copy link
Author

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 );
        });
});

@jednano
Copy link

jednano commented Dec 4, 2014

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

@SBoudrias
Copy link
Owner

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.

@robrich
Copy link
Collaborator

robrich commented Dec 15, 2014

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

@vhmth
Copy link

vhmth commented Oct 6, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants