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

chore: upgrade to jest 24 #15778

Merged
merged 2 commits into from
Oct 3, 2019
Merged

chore: upgrade to jest 24 #15778

merged 2 commits into from
Oct 3, 2019

Conversation

SimenB
Copy link
Contributor

@SimenB SimenB commented May 30, 2019

This won't work on CI since pretty-format uses react-is internally, and since yarn finds react-is in this repo, it won't install it. I don't know how to tell yarn to install a version of react-is into pretty-formats node_modules? To test this locally, I just did cp -R ../jest/node_modules/react-is node_modules/pretty-format/node_modules which worked fine. Maybe @arcanis can help?

All tests pass locally 🙂


This contains #15779 with the upgrade to jest 24 applied on top of it

package.json Outdated Show resolved Hide resolved
@@ -160,7 +160,7 @@ describe('ReactTestRendererAsync', () => {

expect(() =>
expect(Scheduler).toFlushAndYieldThrough(['foo', 'baz']),
).toThrow('Expected value to equal:');
).toThrow('// deep equality');
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we've changed the error messages

scripts/jest/config.base.js Outdated Show resolved Hide resolved
@@ -12,12 +12,13 @@ module.exports = {
'.*': require.resolve('./preprocessor.js'),
},
setupFiles: [require.resolve('./setupEnvironment.js')],
setupTestFrameworkScriptFile: require.resolve('./setupTests.js'),
setupFilesAfterEnv: [require.resolve('./setupTests.js')],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed option

@@ -53,6 +53,9 @@ module.exports = {
if (filePath.match(/\.ts$/) && !filePath.match(/\.d\.ts$/)) {
return tsPreprocessor.compile(src, filePath);
}
if (filePath.match(/\.json$/) ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Jest passes json files through transformers now, and babel didn't like it 🙂

scripts/jest/preprocessor.js Outdated Show resolved Hide resolved
@sizebot
Copy link

sizebot commented May 30, 2019

Fails
🚫

node` failed.

Log

Error:  Error: /home/circleci/project/babel.config.js: Error while loading config - .sourceFileName must be a string, or undefined
    at assertString (/home/circleci/project/node_modules/@babel/core/lib/config/validation/option-assertions.js:118:11)
    at Object.keys.forEach.key (/home/circleci/project/node_modules/@babel/core/lib/config/validation/options.js:107:5)
    at Array.forEach (<anonymous>)
    at validateNested (/home/circleci/project/node_modules/@babel/core/lib/config/validation/options.js:83:21)
    at validate (/home/circleci/project/node_modules/@babel/core/lib/config/validation/options.js:74:10)
    at loadPrivatePartialConfig (/home/circleci/project/node_modules/@babel/core/lib/config/partial.js:66:50)
    at loadFullConfig (/home/circleci/project/node_modules/@babel/core/lib/config/full.js:43:39)
    at transformSync (/home/circleci/project/node_modules/@babel/core/lib/transform.js:41:38)
    at Object.transform (/home/circleci/project/node_modules/@babel/core/lib/transform.js:22:38)
    at Object.exports.babelify (/home/circleci/project/node_modules/danger/distribution/runner/runners/utils/transpiler.js:71:24)

Generated by 🚫 dangerJS

@arcanis
Copy link
Contributor

arcanis commented May 30, 2019

since yarn finds react-is in this repo, it won't install it. I don't know how to tell yarn to install a version of react-is into pretty-formats node_modules?

Not sure I understand - you mean that /node_modules/react-is exists, so Yarn doesn't create /node_modules/pretty-format/node_modules/react-is? Yarn should only do this if the version at the top-level is compatible with the version requested by pretty-format. Isn't it the case?

@SimenB
Copy link
Contributor Author

SimenB commented May 30, 2019

Not sure I understand - you mean that /node_modules/react-is exists, so Yarn doesn't create /node_modules/pretty-format/node_modules/react-is?

Correct.

Yarn should only do this if the version at the top-level is compatible with the version requested by pretty-format. Isn't it the case?

It is semver compatible, but the package has not been built/compiled to cjs so it doesn't work. Its main point to this file: https://github.com/facebook/react/blob/3b2302253f13c9cd049fac10784e10b6c582e3b6/packages/react-is/index.js

I'd like to tell yarn to ignore the react-is from the workspace and install it into pretty-format (at least, I think that's what I want 😀)

@arcanis
Copy link
Contributor

arcanis commented May 30, 2019

Oh I see, so you want to ignore the local workspace .. hm .. this should be doable with resolutions. Something like this, maybe?

{
  "resolutions": {
    "pretty-format/react-is": "npm:react-is@<insert the semver range>"
  }
}

@SimenB
Copy link
Contributor Author

SimenB commented May 30, 2019

That sorta works - it does indeed install from the npm registry, but it installs it to node_modules/react-is meaning the one in the workspace is not there. That might break other code importing it (via some haste resolution or some such)?

@arcanis
Copy link
Contributor

arcanis commented May 30, 2019

Damn, that's likely a bug in the resolutions implementation (fwiw we have tests on this in the v2 trunk, so I know it works properly there) 😢

I don't see an easy fix then ... maybe a resolutions entry on pretty-format instead, to point to a local copy that would list react-is@npm:^<range>? It starts to be a bit hacky 🤔

It's interesting we never got this problem before, though!

@threepointone
Copy link
Contributor

Now's a good time for us to land this. What do you folks think is the best option right to resolve this pretty-format/react-is issue?

@SimenB
Copy link
Contributor Author

SimenB commented Aug 3, 2019

I'm not sure :( I didn't try out @arcanis's last suggestion since he said it was hacky. Maybe give that a go? I'm on vacation for a few more days, so if you have time, that'd be great. Otherwise I'll give it a whack some time next week

(Landing #15779 in the meantime would be great, to reduce this diff)

@threepointone
Copy link
Contributor

Cool cool, enjoy your vacation! I’ll poke at this myself soon

@SimenB SimenB force-pushed the jest-24 branch 4 times, most recently from 8546fc8 to 3fdd00f Compare August 14, 2019 11:57
@SimenB
Copy link
Contributor Author

SimenB commented Aug 14, 2019

I've rebased this now that the other PR landed, but it still has the same react-is issue. Not sure how to deal with it, tbh. Could have some fancy postinstall that downloads react-is from the registry and unpacks it into node_modules/pretty-format/node_modules/react-is, but that feels pretty brittle

@SimenB
Copy link
Contributor Author

SimenB commented Aug 29, 2019

🎉

@SimenB SimenB force-pushed the jest-24 branch 2 times, most recently from 2da454f to 9f731b4 Compare August 29, 2019 15:58
@SimenB
Copy link
Contributor Author

SimenB commented Aug 29, 2019

Rebased and squashed the extra commits to migrate devtools over. So now it's one commit migrating to v24, and the one commit I'm rather hesitant to have my name next to as a separate one for the hacky react-is workaround. Should make it easier to review at least!

(I often use this repo to test out breaking changes in Jest itself, especially around fake timers, which is why I wanna see it upgraded. 🙂 Makes it easier)

@@ -25,7 +25,6 @@
"archiver": "^3.0.0",
"babel-core": "^7.0.0-bridge",
"babel-eslint": "^9.0.0",
"babel-jest": "^24.7.1",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are just remnants after migrating it into this monorepo, I guess? They're unused

@@ -25,7 +25,6 @@
"archiver": "^3.0.0",
"babel-core": "^7.0.0-bridge",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is quite possible also redundant now? not sure... but if it was here for jest@23, then it can go 🙂

@SimenB
Copy link
Contributor Author

SimenB commented Sep 5, 2019

@threepointone any news from your meeting?

@SimenB
Copy link
Contributor Author

SimenB commented Sep 28, 2019

@threepointone ping 🙂

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

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

Alright, I'm biting the bullet and approving this. We need jest 24 badly, and this hack is probably the way forward for now. Thanks @SimenB for your patience and effort! You're the best.

@threepointone
Copy link
Contributor

I've approved, but could you rebase one last time and make sure nothing's broken? I don't expect it to be, but want to be certain before I hit merge :)

@SimenB
Copy link
Contributor Author

SimenB commented Oct 2, 2019

Awesome! I'll give it a rebase tonight or tomorrow

@SimenB
Copy link
Contributor Author

SimenB commented Oct 3, 2019

rebased, and CI still seems happy 👍

@threepointone threepointone merged commit e09097a into facebook:master Oct 3, 2019
@threepointone
Copy link
Contributor

bing bang bosh, it's in!

@SimenB SimenB deleted the jest-24 branch October 3, 2019 17:45
@SimenB
Copy link
Contributor Author

SimenB commented Oct 3, 2019

woo, thanks! 🎉

@threepointone
Copy link
Contributor

No, thank you! We can finally start using inline snapshots yay 😃

@SimenB SimenB mentioned this pull request Oct 4, 2019
NMinhNguyen referenced this pull request in enzymejs/react-shallow-renderer Jan 29, 2020
* chore: upgrade to jest 24

* download react-is from npm manually
kassens added a commit that referenced this pull request Apr 21, 2023
This was added during an upgrade to Jest 24 in
#15778

By now we're at Jest 29. I think if CI passes we might not need this
hack anymore.
kassens added a commit that referenced this pull request Apr 21, 2023
This was added during an upgrade to Jest 24 in
#15778

By now we're at Jest 29. I think if CI passes we might not need this
hack anymore.
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Apr 24, 2023
Summary:
This was added during an upgrade to Jest 24 in
facebook/react#15778

By now we're at Jest 29. I think if CI passes we might not need this
hack anymore.

DiffTrain build for commit facebook/react@c57a0f6.

Reviewed By: poteto

Differential Revision: D45238250

Pulled By: kassens

fbshipit-source-id: 1dfb90dc08a2765a6d499a5754a311ecae002314
jeongshin pushed a commit to jeongshin/react-native that referenced this pull request May 7, 2023
Summary:
This was added during an upgrade to Jest 24 in
facebook/react#15778

By now we're at Jest 29. I think if CI passes we might not need this
hack anymore.

DiffTrain build for commit facebook/react@c57a0f6.

Reviewed By: poteto

Differential Revision: D45238250

Pulled By: kassens

fbshipit-source-id: 1dfb90dc08a2765a6d499a5754a311ecae002314
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
Summary:
This was added during an upgrade to Jest 24 in
facebook/react#15778

By now we're at Jest 29. I think if CI passes we might not need this
hack anymore.

DiffTrain build for commit facebook/react@c57a0f6.

Reviewed By: poteto

Differential Revision: D45238250

Pulled By: kassens

fbshipit-source-id: 1dfb90dc08a2765a6d499a5754a311ecae002314
EdisonVan pushed a commit to EdisonVan/react that referenced this pull request Apr 15, 2024
This was added during an upgrade to Jest 24 in
facebook#15778

By now we're at Jest 29. I think if CI passes we might not need this
hack anymore.
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.

6 participants