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

[WIP] Run Jest in PROD mode too #10273

Closed
wants to merge 5 commits into from
Closed

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Jul 25, 2017

This is a rough proof of concept. It adds production mode runner project to our Jest setup.

Example running a test in Stack, Fiber DEV and Fiber PROD:

screen shot 2017-07-25 at 5 17 39 pm

Not all unit tests are friendly to this. And it doesn't completely represent the PROD mode because I haven't applied PROD transforms. For example it doesn't strip warning calls leading to:

screen shot 2017-07-25 at 5 19 25 pm

On the other hand, applying all PROD transforms would also be a bit tricky because we often assert on error message name which would be stripped. Maybe we can have toThrowReactError matcher that just expects Minified exception in PROD.

Some are explicitly DEV only tests:

screen shot 2017-07-25 at 5 23 40 pm

We should probably gate them.

This is also surfacing what appears to be Jest multi project runner bugs. For example, it appears that some mocks get broken in multi project setup:

screen shot 2017-07-25 at 5 24 10 pm

screen shot 2017-07-25 at 5 24 45 pm

Overall I think this is a promising direction but we'll need Jest MPR to become more stable to continue.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 25, 2017

cc @aaronabramov Have you seen those issues in last two screenshots? It seems like multi project runner can't find mocks in some cases.

@aaronabramov
Copy link
Member

@gaearon i have seen it in www actually. But they were only in 2 or 3 tests, so i just fixed them by using mock/unmock and didn't look into it. Are those the only two modules that can't be found in React or is there more?

@@ -0,0 +1,18 @@
/* eslint-disable */
global.__DEV__ = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to set NODE_ENV to 'production' too for fbjs to work? (caution that in the past this made the transforms fail for me because the transforms read NODE_ENV and expect it to be 'test'. might need to set it to 'test' and back before/after the babel transform in the jest preprocessor.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caution that in the past this made the transforms fail for me because the transforms read NODE_ENV and expect it to be 'test'. might need to set it to 'test' and back before/after the babel transform in the jest preprocessor.

That's what I ran into. I suppose yes, we'll need that.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 25, 2017

Are those the only two modules that can't be found in React or is there more?

I used to have more of these when I tried at first. I was sharing all JS setup files between projects, and only had an additional prod-overrides.js in new project's JSON. But this led to ReactDOMFeatureFlags mock being broken. Separating the environment files with copy paste fixed it.

@gaearon
Copy link
Collaborator Author

gaearon commented Aug 8, 2017

Related to Jest error: we might need to add name to configs.
jestjs/jest#4119 (comment)

@gaearon
Copy link
Collaborator Author

gaearon commented Nov 21, 2017

#11616

@gaearon gaearon closed this Nov 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants