jest: Hanging Before Coverage Output on "Running 1 test suite..."
I’ve been running jest tests for several versions now and I am seeing an intermittent issue where the script hangs at “Running 1 test suite…” just before printing coverage. I’m running in verbose mode with the hope of catching the error. But nothing prints.
This is my package.json config:
{
"scripts": {
"test": "./node_modules/jest-cli/bin/jest.js --verbose"
},
"jest": {
"scriptPreprocessor": "../preprocessor.js",
"rootDir": "src",
"testPathIgnorePatterns": [
"/node_modules/",
"<rootDir>/node_modules/"
],
"unmockedModulePathPatterns": [
"react"
],
"collectCoverage": true
}
}
This is my preprocessor.js file:
var babelJest = require('babel-jest');
module.exports = {
process: function(src, filename) {
return babelJest.process(src, filename)
.replace(/require\(\s*\'.*\.(css|scss|less)\'\);/gm, '');
}
};
And some version numbers: npm 2.14.7 node 4.2.1 jest-cli 0.6.1 babel-jest 5.3.0
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 15 (8 by maintainers)
Got to the bottom of this issue. Basically one of my tests was doing a request, and with no internet connection, the request would just pend in a promise and eventually jest just fails.
The request was done in a flux store in response to a request data action. The problem originated from a container component test that was firing a request data action. The action hit the store and triggered the request. With the jest.autoMockOff() line at the top of the container component test. Nothing was mocked and the request was made. Simply mocking the flux store solved the issue.
All this explains the intermittent failure on machines. It was only really failing on a bad connection or when a service went down.
This is a case where I wasn’t testing a promise directly, but rather indirectly through the require chain. Not sure how jest would catch something like this in the future. Perhaps this is a place where I could stub out my Api module (which does all the requests) with the moduleNameMapper option?
For all you bright devs coming all the way to the bottom of this thread, in jest 18 the newly introduced flag --forceExit solved this for me. Install latest jest and run jest --help to see info