karma-coverage
karma-coverage copied to clipboard
hangs karma
when starting karma with callback:
var karma = require('karma');
var opts = {
configFile: __dirname + '/karma.conf.js',
singleRun: true
};
new karma.Server(opts, () => null).start();
coverage causes the process to hang after running the tests.
using karma.conf.js:
module.exports = function(config) {
config.set({
files: ['test.js'],
frameworks: ['jasmine'],
reporters: ['coverage'],
coverageReporter: {
reporters: [{type: 'text'}]
},
port: 9876,
browsers: ['PhantomJS'],
plugins: [
'karma-jasmine',
'karma-phantomjs-launcher',
'karma-coverage'
]
})
}
The process exits normally if either: no callback is passed to the Server constructor, or the coverage reporter is disabled.
I notice there is no change in coverage that caused this issue; it may be related to socketio/socket.io#2368 ?
I have this same issue. For me, it seems to be related specifically to the text-summary
reporter.
coverageReporter: {
dir: 'build', subdir: 'coverage-js',
reporters: [
{type: 'html', subdir: 'coverage-js/html'},
{type: 'cobertura', file: 'coverage.xml'},
{type: 'lcov', dir: 'coverage/'},
{type: 'text-summary'}
]
}
$> time npm test
> [email protected] test /Users/bjacobel/code/edx-ui-toolkit
> gulp test
[11:12:17] Using gulpfile ~/code/edx-ui-toolkit/gulpfile.js
[11:12:17] Starting 'test'...
< ... test output>
=============================== Coverage summary ===============================
Statements : 92.81% ( 774/834 )
Branches : 65.38% ( 119/182 )
Functions : 95.51% ( 234/245 )
Lines : 92.78% ( 771/831 )
================================================================================
[11:12:18] Finished 'test' after 1.89 s
real 0m34.425s
user 0m3.619s
sys 0m0.602s
But after removing the text-summary
reporter:
coverageReporter: {
dir: 'build', subdir: 'coverage-js',
reporters: [
{type: 'html', subdir: 'coverage-js/html'},
{type: 'cobertura', file: 'coverage.xml'},
{type: 'lcov', dir: 'coverage/'}
]
}
$> time npm test
> [email protected] test /Users/bjacobel/code/edx-ui-toolkit
> gulp test
[11:13:55] Using gulpfile ~/code/edx-ui-toolkit/gulpfile.js
[11:13:55] Starting 'test'...
< ... test output>
[11:13:56] Finished 'test' after 1.61 s
real 0m3.536s
user 0m3.271s
sys 0m0.451s
(Similar results when using the text
reporter as a substitute for text-summary
.)
Interestingly, it's not taking that 30sec to produce the coverage output, as the 30sec hang is after the text-summary coverage is output.
Oddly the issue goes away if you specify a file for text
or text-coverage
to write to, e.g., {type: 'text-summary', file: 'coverage.txt'}
This only happens when I run it through gulp. If I change my test
script in npm to call karma start --single-run
directly the issue never happens anymore. This might actually be an issue with karma-runner/gulp-karma and not this project.
Edit: Actually I wasn't even using gulp-karma
just var karma = require('karma').Server;
, so an issue with karma itself is also a possibility.
Edit Edit: It's because I'm an idiot and gulp-karma
ain't even a thing. Please don't mind my stupidity, point still stands though.
Just started seeing this issue today. Running karma server through gulp. Disabling coverage reporter fixes the hang. Seems to happen w/ both HTML and JSON reporters.
UPDATE - Also confirmed that running karma directly from command-line avoids the issue. Seems to be some connection between var karma = require('karma').Server
and karma-coverage
At least in our case, this appears to have something to do with console output happening after text
output is written to the console.
e.g.
...
---------------------------------------------|----------|----------|----------|----------|----------------|
All files | 99.99 | 99.99 | 99.99 | 99.99 | |
---------------------------------------------|----------|----------|----------|----------|----------------|
LOG: Error blah
will hang, but with
LOG: Error blah
...
---------------------------------------------|----------|----------|----------|----------|----------------|
All files | 99.99 | 99.99 | 99.99 | 99.99 | |
---------------------------------------------|----------|----------|----------|----------|----------------|
it will not...
For us it also seems to specifically hang within gulp
, making me suspect that perhaps something is going haywire with the output stream...?
UPDATE & Workaround: waiting for 3 seconds after test suite completion to make sure any async calls that perform console.log
execute before the coverage reporter runs successfully gets around the problem.
FWIW: I also found a workaround by installing karma
, and using child_process.execSync('node node_modules/karma/bin/karma start --single-run', {stdio: [0, 1, 2]});
inside a gulp
task.