You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have some setup code that I want to run once before all tests. If I run the code in setupTests.js it will run before every test which slows down the total test time alot.
@Stupidism I tried running tests with react-app-rewired only to find out that react-scripts currently uses jest 20.0.4, the globalSetup option is supported in jest 22.
Looks like react-scripts is on it's way to update their jest dependency though, the next branch uses version 22.4.1.
@gaearon , curious as to why certain Jest config options are supported and others are not? I want to use the Jest preset config option, in order to use the jest-puppeteer module with my create-react-app. Could you add it as a supportedKey?
Activity
Stupidism commentedon May 3, 2018
@DuskLoop I think
react-app-rewiredcan help you modifying jest config without ejectinggaearon commentedon May 3, 2018
Maybe it would be sufficient to use a global flag in
src/setupTest.js?I'm not 100% sure but I think
globalvariables should persist between tests.DuskLoop commentedon May 4, 2018
@gaearon
globaldoes not seem to persist between test files.This code:
prints for every test file and no difference in performance
DuskLoop commentedon May 4, 2018
@Stupidism I tried running tests with
react-app-rewiredonly to find out thatreact-scriptscurrently uses jest20.0.4, the globalSetup option is supported in jest22.Looks like
react-scriptsis on it's way to update their jest dependency though, the next branch uses version22.4.1.Brian-McBride commentedon Oct 1, 2018
This is an easy change in one file: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/scripts/utils/createJestConfig.js
Current:
Changed:
One the keys are allowed to pass through, you can just specify these in your package.json jest:{} entry (or wherever).
gaearon commentedon Oct 1, 2018
That sounds fine to support out of the box. I'll add it.
pakaplace commentedon Nov 6, 2018
@gaearon , curious as to why certain Jest config options are supported and others are not? I want to use the Jest
presetconfig option, in order to use thejest-puppeteermodule with mycreate-react-app. Could you add it as asupportedKey?patricklafrance commentedon Nov 7, 2018
@pakaplace if you customize your CRA with craco you could do it.
Here's a sample
craco.config.jsfile:Hope this helps!