git clone https://github.com/facebook/react.git
cd react
yarn
npm test -- --watch Perf
t
returns <Enter>

The watch mode crashes:
FAIL src/renderers/dom/shared/__tests__/ReactBrowserEventEmitter-test.js
โ Test suite failed to run
ProcessTerminatedError: cancel after 2 retries!
at Farm.<anonymous> (node_modules/worker-farm/lib/farm.js:81:25)
at Array.forEach (native)
at Farm.<anonymous> (node_modules/worker-farm/lib/farm.js:75:36)
at ontimeout (timers.js:365:14)
at tryOnTimeout (timers.js:237:5)
at Timer.listOnTimeout (timers.js:207:5)
A worker process has quit unexpectedly! Most likely this an initialization error.
RUNS src/renderers/dom/shared/__tests__/findDOMNode-test.js
RUNS src/renderers/dom/shared/__tests__/ReactBrowserEventEmitter-test.js
RUNS eslint-rules/__tests__/warning-and-invariant-args-test.js
RUNS src/renderers/__tests__/ReactMockedComponent-test.js
Test Suites: 79 skipped, 10 passed, 10 of 126 total
Tests: 1469 skipped, 19 passed, 1488 total
Snapshots: 0 total
Time: 6snpm ERR! Test failed. See above for more details.
If I just run npm test -- --watch ReactBrowserEventEmitter I can't reproduce this.
I think it was not introduced in Jest 19, I can repro it in the React's master branch which is still using Jest 18.0.0 npm test -- -t returns
I can repro it in the React's master branch which is still using Jest 18.0.0
React master definitely uses Jest 19: https://github.com/facebook/react/pull/9034.
Also, Jest 18 didn't have this feature in the first place, did it?
Oh sorry, I was in an "old" master ๐
Yeah is was added in Jest 16 as a CLI flag --testNamePattern|-t, but it was not exposed in watch mode until Jest 19 ๐
@gaearon @rogeliog I reproduced that without watch mode yarn test -- -t returns.
but yarn test -- -t returns --runInBand works fine ๐ฏ
and after some magic I catch this
TypeError: Cannot read property 'initEvent' of null
at Window.process.nextTick (/Users/zouxuoz/forks/react/node_modules/jsdom/lib/jsdom/browser/Window.js:448:9)
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
01: it('should not crash ensureScrollValueMonitoring when createEvent returns null', () => {
02: var originalCreateEvent = document.createEvent;
03: document.createEvent = function() {
04: return null;
05: };
06: spyOn(document, 'createEvent');
07:
08: try {
09: var hasEventPageXY = ReactBrowserEventEmitter.supportsEventPageXY();
10: expect(document.createEvent.calls.count()).toBe(1);
11: expect(hasEventPageXY).toBe(false);
12: } finally {
13: document.createEvent = originalCreateEvent;
14: }
15: });
@gaearon I think test crashed because at 03-06 lines document.createEvent is overridden, tests runs in multiple workers and jsdom doesn't like this, but maybe I'm wrong.
Interesting. In any case, even if the failure is on jsdom's side, the watch mode shouldn't crash and exit. The problem is not just that the test fails, but that it also brings down the watcher.
@gaearon I agree with you. I think it's worker-farm problem because sometimes workers use same global context. @cpojer what are you thinking about it?
This is definitely odd and Jest shouldn't crash in this case.
Yep, I agree
I just ran
git clone https://github.com/facebook/react.git
cd react
yarn
npm test -- --watch Perf
t
returns <Enter>
and I could not reproduce the crashing - fixed by accident somewhere else?
I can't repro this with Jest on master.
Can reproduce this after upgrading from 18.1.0 to 20.1.0-delta.3
โ Test suite failed to run
ProcessTerminatedError: cancel after 2 retries!
at Farm.<anonymous> (node_modules/worker-farm/lib/farm.js:81:25)
at Array.forEach (native)
at Farm.<anonymous> (node_modules/worker-farm/lib/farm.js:75:36)
at Timer.listOnTimeout (timers.js:92:15)
A worker process has quit unexpectedly! Most likely this is an initialization error.
error Command failed with exit code 1.
Please use the 21.0.0 alphas.
Same error with 21.0.0.alpha.2:
โ Console
console.info node_modules/@storybook/react/dist/server/babel_config.js:67
=> Loading custom .babelrc
console.error node_modules/fbjs/lib/warning.js:36
Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead.
console.error node_modules/fbjs/lib/warning.js:36
Warning: Portal: React.createClass is deprecated and will be removed in version 16. Use plain JavaScript classes instead. If you're not yet ready to migrate, create-react-class is available on npm as a drop-in replacement.
console.error node_modules/fbjs/lib/warning.js:36
Warning: Invalid argument supplid to oneOfType. Expected an array of check functions, but received undefined at index 1.
TypeError: Cannot read property '_h' of undefined
at isUnhandled (/src/node_modules/babel-polyfill/node_modules/core-js/modules/es6.promise.js:127:13)
at isUnhandled (/src/node_modules/babel-polyfill/node_modules/core-js/modules/es6.promise.js:133:26)
at Immediate._onImmediate (/src/node_modules/babel-polyfill/node_modules/core-js/modules/es6.promise.js:110:8)
at processImmediate [as _immediateCallback] (timers.js:396:17)
โ Test suite failed to run
ProcessTerminatedError: cancel after 2 retries!
at Farm.<anonymous> (node_modules/worker-farm/lib/farm.js:81:25)
at Array.forEach (native)
at Farm.<anonymous> (node_modules/worker-farm/lib/farm.js:75:36)
at Timer.listOnTimeout (timers.js:92:15)
A worker process has quit unexpectedly! Most likely this is an initialization error.
error Command failed with exit code 1.
Can you provide a reproducing case?
I've got the same problem with
jest 19, 20 and 21
react-native 47
react 16
react-test-renderer 16
@sospedra Please provide a reproducing case for folks can look into it.
Yeah, it's always reproducible on one test case. Will try to isolate the problem next week
Follow up. I'm trying to make a repro case but react-native clean install is not working :/ (unrelated problems). I'll come back later.
Edit: More research. It's definetely something related to the worker-farm and timers.js.
Edit 2: Ok. So I can confirm that's a timer issue. Becaue when I set "timers": "fake" http://facebook.github.io/jest/docs/en/configuration.html#timers-string the issue doesn't rise. @Vanuan - in the absense of a repro case - can you confirm this?
No, I don't have "timers": "fake" in my jest config.
I think I found the secret combination:
import React from 'react';
import ReactDOM from 'react-dom';
describe('this test', () => {
it('will crash', () => {
ReactDOM.render(
<div>
<div id="undefined" />
<div id="undefined" />
</div>,
document.body
)
});
});
For some peculiar reason, if virtual DOM contains at least 2 elements with id equal to string "undefined", rendering it to jsdom will fail. :scream:
just got same error on
FAIL src/helpers/stripe/oauth/__tests__/getAuthorizeUrl.test.js
โ Test suite failed to run
ProcessTerminatedError: cancel after 2 retries!
at Farm.<anonymous> (node_modules/worker-farm/lib/farm.js:87:25)
at Array.forEach (<anonymous>)
at Farm.<anonymous> (node_modules/worker-farm/lib/farm.js:81:36)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
A worker process has quit unexpectedly! Most likely this is an initialization error.
and function it tests is just joining some stuff
import getEnv from './../../../helpers/environment/get';
export default function getAuthorizeUrl({email}) {
const parts = [];
if (!getEnv('STRIPE_CLIENT_ID')) {
throw new Error(`#slkfsd getEnv('STRIPE_CLIENT_ID') is falsy: ${getEnv('STRIPE_CLIENT_ID')}`);
}
parts.push(`client_id=${getEnv('STRIPE_CLIENT_ID')}`);
parts.push('response_type=code');
parts.push(`redirect_uri=${getEnv('STRIPE_REDIRECT_URI')}`);
parts.push('scope=read_only');
parts.push('state=blndr'); // An arbitrary string value we will pass back to you, useful for CSRF protection
parts.push(`stripe_user[email]=${email}`);
return `https://connect.stripe.com/oauth/authorize?${parts.join('&')}`;
}
and getEnv is:
const fs = require('fs');
const path = require('path');
const envFile = path.join(__dirname, '../../../.env');
export default function getConfig(variable, secondTry) {
if (typeof process.env[variable] !== 'undefined') {
return process.env[variable];
} else if (secondTry === true) {
console.error(`#jdfkdjs variable "${variable}" in ${envFile} is not defined.`);
process.exit(1);
} else if (!fs.existsSync(envFile)) {
console.log(`#k4hkdfs env file (${envFile}) does NOT exist`);
process.exit(1);
} else {
require('dotenv').config({path: envFile});
return getConfig(variable, true);
}
}
"jest": "^21.1.0",
node v8.5.0
npm 5.4.2
OS X Sierra 10.12.6
Any updates on this? :)
Getting this issue in our app with react-native while running tests. Adding:
"jest": { ... "timers": "fake" ... }
resolved the issue.
Stacktrace (without timers: fake ):
TypeError: Cannot read property 'Object.<anonymous>' of null
at Runtime._execModule (/opt/application/node_modules/jest-runtime/build/index.js:518:64)
at Runtime.requireModule (/opt/application/node_modules/jest-runtime/build/index.js:332:14)
at Runtime.requireModuleOrMock (/opt/application/node_modules/jest-runtime/build/index.js:408:19)
at Function.bezier (/opt/application/node_modules/react-native/Libraries/Animated/src/Easing.js:228:13)
at ease (/opt/application/node_modules/react-native/Libraries/Animated/src/Easing.js:94:14)
at TimingAnimation._easing (/opt/application/node_modules/react-native/Libraries/Animated/src/Easing.js:260:8)
at TimingAnimation.onUpdate (/opt/application/node_modules/react-native/Libraries/Animated/src/animations/TimingAnimation.js:138:6)
at ontimeout (timers.js:469:11)
at tryOnTimeout (timers.js:304:5)
at Timer.listOnTimeout (timers.js:264:5)
Try adding jest.useFakeTimers(); above your it blocks. You don't need to make any global config changes that way.
describe(SomeAnimatedComponent, () => {
jest.useFakeTimers();
it('works', () => {
// ...tests
});
});
@hakimelek
Currently getting this error here. Adding:
{
"timers": "fake"
}
to "jest" doesn't fix, nor does adding jest.useFakeTimers();. Will come back and update if I figure something out.
EDIT: Fixing some dependencies solved my problem but I'm not sure wh .
If anybody can create a reproduction, please open up a new issue and link to this
I received this error when I was using import 'jsdom-global/register'; as it was suggested in https://github.com/airbnb/enzyme/issues/341#issuecomment-263045603
Removed it now and replaced it with --env=jsdom which fixed this issue.
Most helpful comment
Try adding
jest.useFakeTimers();above youritblocks. You don't need to make any global config changes that way.@hakimelek