Open traviswimer opened 10 years ago
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?
I did attempt using different coverageVaribale
s, 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 );
});
});
My scenario is the same and I'm experiencing the same issue.
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.
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.)
+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.
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:I am mostly just curious if there is a better way to do this.