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

Decide on Jest's default environment #338

Closed
cpojer opened this issue Aug 3, 2016 · 4 comments
Closed

Decide on Jest's default environment #338

cpojer opened this issue Aug 3, 2016 · 4 comments
Assignees
Milestone

Comments

@cpojer
Copy link
Contributor

cpojer commented Aug 3, 2016

Jest ships with jsdom by default. With the test renderer we don't need jsdom so I recommend people to use the node environment, also in CRA: https://github.com/facebookincubator/create-react-app/blob/master/scripts/utils/create-jest-config.js#L22

However, I expect people would like to continue using enzyme until they are fully bought into snapshot testing and until the test renderer supports all the APIs to put enzyme itself (or a compatible API) on top of the test renderer.

Here are the possible solutions:

  • Remove the testEnvironment config I linked to above. The only downside is that Jest's startup increases by 500ms because jsdom takes 500ms to require. (simply measure require('jsdom');) . This is the easiest fix.
  • Encourage people to install and load jsdom themselves: It's basically const window = require('jsdom').jsdom(...).defaultView;

I don't have strong feelings either way. Personally I'd like to get into a place where jsdom is available but not the default in Jest (maybe with a @jest-env jsdom directive in the header; we haven't finalized our ideas yet).

For CRA, given that people predominantly write web apps, it likely makes sense to take this performance hit and go with option one. It's a bit slower but the saner no-config default.

@cpojer
Copy link
Contributor Author

cpojer commented Aug 4, 2016

See the discussion in #355. We will provide documentation on how to use jsdom with CRA.

@cpojer cpojer closed this as completed Aug 4, 2016
@gaearon
Copy link
Contributor

gaearon commented Aug 4, 2016

I'm going to try what both options feel like today and make the call.

Ideally I would like to ship performant default and provide clear instructions automatically when somebody tries to use things relying on jsdom. I'm not sure if it's even possible through.

@gaearon gaearon reopened this Aug 4, 2016
@cpojer
Copy link
Contributor Author

cpojer commented Aug 4, 2016

I'm happy to do whatever you decide is best for CRA. I never tried to load jsdom from within Jest using the node environment but it is definitely a use-case we should support. I have time tomorrow to make anything happen.

@gaearon
Copy link
Contributor

gaearon commented Sep 1, 2016

Decided to go with jsdom by default but as a flag so people who know what it is can disable it.

@gaearon gaearon closed this as completed Sep 1, 2016
LeshikJanz pushed a commit to LeshikJanz/nubabi that referenced this issue Dec 29, 2017
@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
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

2 participants