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

Watch mode crashes with ProcessTerminatedError in new test pattern mode #2979

Closed
gaearon opened this issue Feb 22, 2017 · 33 comments
Closed

Comments

@gaearon
Copy link
Contributor

gaearon commented Feb 22, 2017

git clone https://github.com/facebook/react.git
cd react
yarn
npm test -- --watch Perf

t
returns <Enter>

screen shot 2017-02-22 at 6 27 29 pm

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.

@rogeliog
Copy link
Contributor

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

@gaearon
Copy link
Contributor Author

gaearon commented Feb 23, 2017

I can repro it in the React's master branch which is still using Jest 18.0.0

React master definitely uses Jest 19: facebook/react#9034.
Also, Jest 18 didn't have this feature in the first place, did it?

@rogeliog
Copy link
Contributor

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 😄

@zouxuoz
Copy link
Contributor

zouxuoz commented Feb 23, 2017

@gaearon @rogeliog I reproduced that without watch mode yarn test -- -t returns.

@zouxuoz
Copy link
Contributor

zouxuoz commented Feb 23, 2017

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)

@zouxuoz
Copy link
Contributor

zouxuoz commented Feb 23, 2017

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.

@gaearon
Copy link
Contributor Author

gaearon commented Feb 23, 2017

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.

@zouxuoz
Copy link
Contributor

zouxuoz commented Feb 23, 2017

@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?

@cpojer
Copy link
Member

cpojer commented Feb 23, 2017

This is definitely odd and Jest shouldn't crash in this case.

@rogeliog
Copy link
Contributor

Yep, I agree

@TobiasBales
Copy link

TobiasBales commented Apr 7, 2017

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?

@thymikee thymikee modified the milestone: Jest 20 Apr 21, 2017
@cpojer
Copy link
Member

cpojer commented Apr 28, 2017

I can't repro this with Jest on master.

@cpojer cpojer closed this as completed Apr 28, 2017
@Vanuan
Copy link
Contributor

Vanuan commented Aug 22, 2017

Can reproduce this after upgrading from 18.1.0 to 20.1.0-delta.3

@Vanuan
Copy link
Contributor

Vanuan commented Aug 22, 2017

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

@cpojer
Copy link
Member

cpojer commented Aug 22, 2017

Please use the 21.0.0 alphas.

@Vanuan
Copy link
Contributor

Vanuan commented Aug 22, 2017

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.

@gaearon
Copy link
Contributor Author

gaearon commented Aug 22, 2017

Can you provide a reproducing case?

@gaearon gaearon reopened this Aug 22, 2017
@sospedra
Copy link

sospedra commented Aug 25, 2017

I've got the same problem with

jest 19, 20 and 21
react-native 47
react 16
react-test-renderer 16

@gaearon
Copy link
Contributor Author

gaearon commented Aug 25, 2017

@sospedra Please provide a reproducing case for folks can look into it.

@Vanuan
Copy link
Contributor

Vanuan commented Aug 26, 2017

Yeah, it's always reproducible on one test case. Will try to isolate the problem next week

@sospedra
Copy link

sospedra commented Aug 28, 2017

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?

@Vanuan
Copy link
Contributor

Vanuan commented Aug 28, 2017

No, I don't have "timers": "fake" in my jest config.

@Vanuan
Copy link
Contributor

Vanuan commented Sep 16, 2017

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

@Vanuan
Copy link
Contributor

Vanuan commented Sep 16, 2017

For some peculiar reason, if virtual DOM contains at least 2 elements with id equal to string "undefined", rendering it to jsdom will fail. 😱

@liesislukas
Copy link
Contributor

liesislukas commented Sep 24, 2017

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

@hakimelek
Copy link

Any updates on this? :)

@admmasters
Copy link

admmasters commented Oct 17, 2017

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)

@DoubleOTheven
Copy link

DoubleOTheven commented Oct 25, 2017

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

@Flaque
Copy link

Flaque commented Nov 8, 2017

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 .

@SimenB
Copy link
Member

SimenB commented Feb 15, 2019

If anybody can create a reproduction, please open up a new issue and link to this

@SimenB SimenB closed this as completed Feb 15, 2019
@panmona
Copy link

panmona commented Apr 3, 2019

I received this error when I was using import 'jsdom-global/register'; as it was suggested in enzymejs/enzyme#341 (comment)
Removed it now and replaced it with --env=jsdom which fixed this issue.

@sanjeevyadavIT
Copy link

This did it for me: ref

 "testEnvironment": "jsdom"

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests