-
-
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
Update to Jest 24 #6278
Update to Jest 24 #6278
Conversation
I think (based on the comments in the issue) that jest@24 would fix #2393 so it would be really nice to get this working. |
setupFiles: [ | ||
isEjecting | ||
? 'react-app-polyfill/jsdom' | ||
: require.resolve('react-app-polyfill/jsdom'), | ||
], | ||
|
||
setupTestFrameworkScriptFile: setupTestsFile, | ||
setupFilesAfterEnv: setupTestsFile ? [setupTestsFile] : [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe rather than this here you modify the assignment of setupTestsFile
above to potentially allow multiple files to be assigned:
function setupTestsFiles(rootDir) {
const setupTestsFiles = [];
if(fs.existsSync(paths.testsSetup)){
const setupTestsMatches = paths.testsSetup.match(/src[/\\]setupTests\.(.+)/);
const setupTestsFileExtension = (setupTestsMatches && setupTestsMatches[1]) || 'js';
setupTestsFiles.push(`${rootDir}/src/setupTests.${setupTestsFileExtension}`)
}
return setupTestsFiles
}
...
module.exports = (resolve, rootDir, isEjecting) => {
...
setupFilesAfterEnv: setupTestsFiles(rootDir),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can totally do this, although i think that most users would use setupFilesAfterEnv
like:
setupFilesAfterEnv: [
'jest-dom/extend-expect',
'react-testing-library/cleanup-after-each'
]
rather than creating multiple file themselves.
IMO we should allow overriding setupFilesAfterEnv
in package.json
if we really want to support this.
Config for typescript can probably be simplified whenever this lands (jest uses |
Just a side-note/reminder: Once this is done we'll merge in #4176. |
d2fb553
to
089cdeb
Compare
I don't get why |
This is related to a recent change. I think if you swap the arguments it should work. Please try that and let us know if that doesn't resolve the issue. |
a4e3065
to
36999f0
Compare
It works now but there are 2 more failing builds that i can't get my head around. Can you help me with that? It appears that it fails only with latest node |
This is super welcome for us, we want to start a monorepo project with CRA + Typescript + Jest, and we will not start until we get jest 24 working nicely with this dream stack :-) |
Yeah we're having some issues with the latest node builds in Travis on master as well. |
36999f0
to
1e92930
Compare
1e92930
to
537c115
Compare
Looks like we just have one failing test left: https://github.com/facebook/create-react-app/blob/master/test/fixtures/issue-5176-flow-class-properties/index.test.js I'm not exactly sure why it's failing but let me know if you need any help looking into it. |
I'm not quite sure how to takle this, it passes in my local machine (i'm on node 10.15). Right now i'm trying to debug what's happening on travis |
Aaaaand we have green lights 🎉🎉 |
Awesome, when can we expect a release ? |
You should wait for jestjs/jest#8088 |
No, please please don't wait anymore lol, the pain is intense here without this merged, you have no idea! I understand the problem with jestjs/jest#8088 , but this is a relatively rare bug that happens when you don't want to install watchman... However having jest 24 (which supports typescript more easily) in create react app is a big deal for many of us. |
We're going to merge this as is and release it in an alpha of version 3.0. I've created a follow up issue to make sure we update Jest before releasing the final version of 3.0. |
@loryman The |
Yeah sorry, just reverted it! |
Nice! Do you have an ETA on this v3 alpha release ? Thank you |
We're hoping in the next couple days to have a first cut alpha out. |
Thanks! |
Things to notice before merging
There's currently a bug for which jest 24 crashes if it's called programmatically. Until a bugfix comes out, i've addedThis has been fixed in version 24.1 🎉require('jest-cli/build/cli')
beforerequire('jest')
like this comment suggests.The current version ofFixed injest-pnp-resolver
doesn't work because jest changed the file names ofjest-resolve
. They already have the fix in their code but it isn't published yet. I've filed an issue, but in the meantime i've createdpnpResolver.js
just to make things work.jest-pnp-resolver
1.1.0 🎉Jest 24 comes with a new
setupFilesAfterEnv
option that replacessetupTestFrameworkScriptFile
. It now accepts an array of files instead of a single one. I'm wondering if we should allow multiple setup files?