-
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
Can't run jest tests with 0.56.0 #19859
Comments
I experienced the same problem. And for pure js projects it can be resolved by force all bebel 7 deps to be at top level
But for typescript projects I'am still wait for |
thx for your suggestions @vovkasm - that's indeed fixed our test problems. FYI I've used these in my package.json: and I also had to delete my node_modules folder prior installation as that prevented some updates. nope - this doesn't work either. I got this error now:
|
Fixed in jestjs/jest#6505 |
Thanks @timwangdev! I'll close this issue once Jest is updated. |
I'm still working on this. Due to the way the repo is set up internally, we can't simply upgrade Jest in the RN repo, we have to upgrade Jest across all projects. Still, jest is working fine in CI, which worries me. Can someone add a failing test case to cover this situation? It would 1) ensure the upgrade to 23.2.0 fixes the issue, and 2) prevent this breakage from going unnoticed in the future. |
Hmm I'm still seeing an issue with this with one of my projects using jest 23.2.0.... I'll see if I can make it happen in the react-native internal tests as well. |
@hramos what's really interesting in my project, is that going back to babel-preset-react-native version 4 allows jest tests to pass, but breaks packaging of the JS bundle for actually running the app. |
The babel issue is still occurs, the jest version only fix |
@hramos I think there is a jest e2e test suit in https://github.com/facebook/react-native/blob/master/scripts/run-ci-e2e-tests.js#L266-L270 to and the job is defined in https://github.com/facebook/react-native/blob/master/.circleci/config.yml#L343-L345 . But it not being used in any of the workflow in CircleCI. Maybe we should re-enable this? |
thx @timwangdev - using |
This is still breaking on 0.56.0-rc.4, same error as above:
|
Hmm.... now I'm making progress.... many tests are passing now after adding the following explicitly to my top level package.json for my project:
Still seeing a few 'unexpected token import' errors in tests, but this is definitely progress. @hramos |
Ok so all the remaining test failures seem to be related to the use of react-test-renderer. Upgrading that to 16.4.1 doesn't seem to help. |
I also fail to run tests. I get the dreaded Adding these files to There is tons of issues around, e.g. in jestjs/jest#2081, but i could not find a solution. my .babelrc is failry simple:
|
@hramos Here's a simple example that should work, but fails with the "Plugin 0 specified.... provided an invalid property of default". Maybe this could be added to CI?
import React from 'react';
import renderer from 'react-test-renderer';
import App from '../App';
test('App matches Snapshot', () => {
const component = renderer.create(<App />);
let tree = component.toJSON();
expect(tree).toMatchSnapshot();
});
With version 0.55.4, Adding more babel dependencies to {
"name": "Test56",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.4.1",
"react-native": "0.56.0-rc.4"
},
"devDependencies": {
"@babel/core": "^7.0.0-beta.47",
"babel-core": "^7.0.0-beta.47",
"babel-jest": "^23.2.0",
"babel-plugin-jest-hoist": "^23.2.0",
"babel-plugin-module-resolver": "^3.1.1",
"babel-preset-env": "^1.7.0",
"babel-preset-jest": "^23.2.0",
"babel-preset-react-native": "^5",
"jest": "23.2.0",
"jest-react-native": "^18.0.0",
"react-test-renderer": "16.4.1"
},
"jest": {
"preset": "react-native"
}
} I tried adding a Jest test that doesn't use |
Thanks for looking into it, seems like something we can test in CI. |
In our app we had to add this babel-bridge and enforce yarn resolutions in order to make sure that everything worked properly. Have you tried using them? I feel this issue may be related to something not "using" babel7 🤔 |
@dlowder-salesforce Installing |
To summarize experience with our projects. It works if:
Update after #19859 (comment):
If anyone interested, there is my diff of upgrading one of simple project.
Then |
Still doesn't work for me if I follow @vovkasm's directions. My .babelrc{ "presets": [ "react-native" ], "plugins": [ [ "module-resolver", { "root": [ "./src" ] } ] ] } My babel dependencies (removed everything else for brevity)"dependencies": { "@babel/cli": "^7.0.0-beta", "@babel/core": "^7.0.0-beta", "@babel/preset-flow": "^7.0.0-beta", "@babel/preset-stage-2": "^7.0.0-beta", "@babel/preset-stage-3": "^7.0.0-beta", "babel-core": "7.0.0-bridge.0", "babel-eslint": "^9.0.0-beta.1", "babel-jest": "^23.2.0", "babel-plugin-module-resolver": "^3.1.1", "babel-preset-react-native": "5.0.2", "jest": "23.3.0", "react-test-renderer": "16.4.1" }, And the broken test file...import React from 'react'; import renderer from 'react-test-renderer'; import { Text } from 'react-native'; ...fails like so:FAIL test/JestBreakage.spec.js ● Console |
Update on this issue: #20068 (comment) I'm unlocking because (as mentioned in the link) I'm investigating it further and it seems that there is something "weird" going on with By investigating in the and potentially related too: jestjs/jest#6229 |
I'm not using typescript, so the changes I had to make so that it now works were:
devDependencies now using:
jest (in the same file):
|
Ok, so, after a whole lot of testing and investigating here's the TLDR
I'd like to thank @vovkasm for his help in finding a way to fix this issue. (I'm locking this issue again since I'd prefer to keep this as last comment, if there are any evolutions on the subject please open a new issue) *It may break Metro parsing the
|
I believe we should get this fixed in master so that it works out of the box. @kelset, are you able to tackle this since you have done significant research into it already? I believe it can be connected with our "preset" PR (the one that was about to remove |
I just updated tests in a project to work on RN master and here are the steps I had to do (thanks @kelset)
|
Yeah it's been a while since the workaround I wrote, may be worth updating the HelloWorld template to have the steps you list embedded, what do you think @janicduplessis? I think that now we should be able to have safely |
Ideally .babelrc should work, I guess there is a bug somewhere but I don’t really have the time to investigate this for now. I agree that we should update the starting template to install the dependencies in my comment and include the babel.config.js workaround. |
Summary: A while back Jest introduced `jest.requireActual` and `jest.requireMock` which are aliases to `require.requireActual` and `require.requireMock`. We believe that users should use official Jest API and are planning to deprecate the latter. Pull Request resolved: #21849 Differential Revision: D10448849 Pulled By: TheSavior fbshipit-source-id: 34fffde97f48c26098c74ee222a56d99071703a6
Unfortunately it seems like the setup there was a bit broken. I recommend upgrading to the latest version of RN (0.58) which brings babel 7 and a working Jest setup. |
Environment
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.4
CPU: x64 Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz
Memory: 27.74 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.9.0 - /usr/local/bin/node
npm: 6.1.0 - /usr/local/bin/npm
Watchman: 4.5.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 11.4, macOS 10.13, tvOS 11.4, watchOS 4.3
Android SDK:
Build Tools: 23.0.1, 23.0.2, 23.0.3, 24.0.2, 25.0.0, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 27.0.0, 27.0.3
API Levels: 19, 22, 23, 24, 25, 26, 27
IDEs:
Android Studio: 2.2 AI-145.3360264
Xcode: 9.4.1/9F2000 - /usr/bin/xcodebuild
npmPackages:
react: 16.3.2 => 16.3.2
react-native: 0.56.0-rc.2 => 0.56.0-rc.2
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7
Description
My jest tests are broken - it displays this error for each test file:
Plugin 0 specified in "project/node_modules/babel-preset-react-native/index.js" provided an invalid property of "default" (While processing preset: "project/node_modules/babel-preset-react-native/index.js")
at Plugin.init (node_modules/babel-core/lib/transformation/plugin.js:131:13)
at Function.normalisePlugin (node_modules/babel-core/lib/transformation/file/options/option-manager.js:152:12)
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:184:30
at Array.map ()
at Function.normalisePlugins (node_modules/babel-core/lib/transformation/file/options/option-manager.js:158:20)
at OptionManager.mergeOptions (node_modules/babel-core/lib/transformation/file/options/option-manager.js:234:36)
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:265:14
at node_modules/babel-core/lib/transformation/file/options/option-manager.js:323:22
at Array.map ()
at OptionManager.resolvePresets (node_modules/babel-core/lib/transformation/file/options/option-manager.js:275:20)
these tests worked perfectly fine with 0.53.3
my .babelrc file:
{
"presets": ["react-native"]
}
my jest version is "23.1.0"
The text was updated successfully, but these errors were encountered: