-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Allow projects to customize Jest configs. Fixes #338. #355
Conversation
I'm not a big fan of this change for the same reasons we don't want to provide webpack configuration overrides. Not sure why somebody would have existing code that uses DOM APIs in a newly created app? |
One reason I mentioned in the associated task is that many people still prefer using enzyme and might want to use it together with create-react-app, so they should get to do that. I believe the test renderer is the future of React testing but we don't have a selector API yet, unfortunately (it is being worked on, though). Providing an escape hatch to modify the configuration seems valuable. There isn't much of a point in forcing them to eject just to add some configuration for their test environment, right? I didn't realize you aren't allowing any other configuration overrides. Happy to follow the philosophy of this project but personally I don't want anyone to feel locked in, which is why I'm providing this solution. Another solution would be a soft-eject which simply copies the default jest config into package.json and the test command would then pick it up from there. We could also just ignore the default config if the user provides his own: |
That's what we do for every other configuration and tool too, not sure why the test env would be different tbh.
We've had these discussions in a few issues and PRs now but I can't find them (I'm sure @gaearon has them stored somewhere), basically you either like That's also why including Jest by default has stirred such a big discussion |
Got it, so the way I see it, we now have two options:
I'm inclined to go with option 1, because that's really where I see things heading. What do you think? |
I totally agree, I don't think beginners will download CRA and immediately start thinking "Oh, I need jsdom for enzyme to test my react app!". Let's do it! |
I'm sorry, with the part that you quoted and your comment it feels inconclusive whether you are voting for option 1 or 2. Which is it? |
Sorry, Option 1 sounds good to me! 👍 |
I actually sort of expect that. Also many user written components reference things like I think shipping jsdom by default might be a better decision until TestRenderer is more fully fledged. |
This changes
create-jest-config
to take in the app's configuration so that people can decide to overwrite the defaults if they like.I recommend people to use the node environment and not bother with jsdom, however people might have existing code that accesses DOM APIs. In such cases people can put
into their config and
npm run test
will merge the default config and the app config together. If someone decides to eject, the custom config will be kept in-tact when we write the default config intopackage.json
.I was unsure how to test my changes to test/eject so I figured I'll add a Jest test to
scripts
which can be invoked usingnpm run test-scripts
. I used a snapshot test to lock in the Jest config and validated that it is correct. I also enjoy how meta it is to use snapshots in Jest to test a feature for Jest integration into a project that is promoting snapshot testing. Anyway, people can now write tests for stuff inscripts/
to make sure we don't regress.Fixes #338