-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Fix jest-preset to use internal preprocessor (fix testing with 0.56) #20068
Conversation
…est (should fix facebook#19859) By unknown reason babel-jest can't transform tests and react-native's files, see facebook#19859 for details. But internal preprocessor.js can, so use it for now in published jest-preset.json.
I think that failed end_to_end tests does not have any relation to this change... As I know, jest tests in generated application from template currently does not exists. See this comment: #19859 (comment) from @hramos and test plan above it. |
Hey thanks for the PR! Yes it looks like all those tests are failing because of the packager not starting (?). I'll let the core know, hopefully we can get this passing tests -> reviewed -> merged in master -> cherry picked for 0.56.1 |
@vovkasm For me this workaround seems to break tests that rely on |
@stevehollaar Seems like that, mocks was didn't in test project, so I miss this check. Do you have any suggestions? |
Sadly I don't have any suggestions on where to go from here, but I added manual mocking to the test repo here: https://github.com/stevehollaar/rn-56-test, so the tests now fail there, since manual mocks are not hoisted. If you're able to get those tests green, that would be wonderful. |
Ok. I trying to walk another way and stay with babel-jest (because it automatically adds hoisting plugin). And found that Then I open my
Now all tests pass as expected. So:
Any suggestions what to do welcomed! |
After some thinking. We can still apply this patch as a fast workaround (may be even update internal transformer to include hoisting of mocks). In the more far perspective someone should fix jest. What do people think? What the intention of core team? |
It will allow using jest mocks within tests configured with react-native jest preset..
After tracking history of |
@stevehollaar Can you please test? Quick check can be done if you download |
This comment has been minimized.
This comment has been minimized.
@vovkasm Sorry for the delay, but yes! I can confirm that your updated |
@vovkasm did you try and see if using https://github.com/lehni/babel-jest-nested fixes your issue? And if it does, could you maybe add your voice to jestjs/jest#6617 to get some traction? |
@lehni To be clear... Personally I do not bitten by this error. We use typescript and ts-jest seems work properly (also we do not use jest mocks). But I will look and vote if solution is appropriate ) |
Hey @vovkasm just wanted to let you know that I'm trying to get this merged asap but we have been really busy trying to fix RN 0.56 working with Windows. We should be close to a fix for that so hopefully we'll be able to come back to this 💪 |
so until this is merged, the only workaround is adding this to jest config? React native init creates a broken test suite, should probably merge this asap
UPDATE: I had to copy the preprocessor file and add the mock support to it as seen in the PR. Thanks @vovkasm |
@evanjmg Yes, also you can write your own preprocessor (especially if your project uses custom babel configuration). |
👋 everyone, since I couldn't find anyone else to review this PR I'm trying to investigate it deeply in order to be able to review it myself. And I think that sadly this workaround should not be merged, since the issue is actually So tbh I'd prefer to understand and fix why I'll report back here once I have more info/ better ideas. For now I don't want to close this PR as its the only viable workaround. |
|
Yeah I was using your comments as guidance, thank you so much for your investigations :) And I agree with the preprocessor, not sure if it's there because of some metro requirement but I'll ask around. |
Hey @vovkasm I'm closing this for the reasons I mentioned earlier - but I wrote a "more complete" guide to fixing this issue over there #19859 (comment) Thanks again for all your help! |
fwiw, I just tried this fix out - it seems to not be working (anymore?). this is what my devdeps looks like: "@babel/cli": "7.0.0-beta.47",
"@babel/core": "7.0.0-beta.47",
"@babel/parser": "^7.0.0-beta.48", // there is no beta.47
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.4.2", // i'm fairly sure this isn't used
"babel-plugin-jest-hoist": "^23.2.0", I then copied across the Running I've absolutely no idea what's going on here. My metro version is |
I was also having issues with the internal preprocessor (after applying the fix suggested in #19859 (comment)), because of the missing Doing what @deecewan suggested actually did work for me and fixed the tests that had broken. So if you're struggling like I was it may be worth a try. |
Fixes #19859 at least until problem will be fixed properly.
By unknown reason babel-jest can't transform tests and react-native's files, see #19859 for details. But internal preprocessor.js can, so use it for now in published jest-preset.json.
Test Plan:
From original issue:
react-native init Test56 --version=0.56.0
cd Test56
mkdir __tests__
__tests__/AppTest.js
that has following lines:npm test
Slighly modified repo for reproduction: https://github.com/dlowder-salesforce/rn-56-test/tree/eb0611b1870c410cd4a7458a740a3ac52bad2827
Fixed repo: https://github.com/vovkasm/rn-56-test/tree/a00fc639bd6a681591131c24e3ee976ae374438e
@kelset You want to be mentioned ;-)
Release Notes:
[GENERAL] [BUGFIX] [jest-preset.json] - Fix js transformation in jest