-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Upgrade to Babel 7 #1191
Upgrade to Babel 7 #1191
Conversation
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.
Thanks for looking into this. Asked questions inline.
Every AsyncStorage
test is failing. There's probably a common cause. It might be that the way assertions are done needs to change following the Jest upgrade.
It looks like these changes have broken the Babel transform as the output is being compiled when it shouldn't be.
FAIL packages/babel-plugin-react-native-web/src/__tests__/index-test.js
● Rewrite react-native to react-native-web › import from "native-native"
expect(value).toMatchSnapshot()
Received value does not match stored snapshot "Rewrite react-native to react-native-web import from "native-native": import from "native-native" 1".
- Snapshot
+ Received
@@ -4,12 +4,17 @@
import { Invalid, View as MyView, ViewPropTypes } from 'react-native';
import * as ReactNativeModules from 'react-native';
↓ ↓ ↓ ↓ ↓ ↓
- import ReactNative from 'react-native-web/dist/index';
- import View from 'react-native-web/dist/exports/View';
- import { Invalid } from 'react-native-web/dist/index';
- import MyView from 'react-native-web/dist/exports/View';
- import ViewPropTypes from 'react-native-web/dist/exports/ViewPropTypes';
- import * as ReactNativeModules from 'react-native-web/dist/index';
+ "use strict";
+
+ var ReactNativeModules = _interopRequireWildcard(require("react-native-web/dist/index"));
+
+ var _View = _interopRequireDefault(require("react-native-web/dist/exports/View"));
+
+ var _ViewPropTypes = _interopRequireDefault(require("react-native-web/dist/exports/ViewPropTypes"));
+
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
+
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
"
at tester (node_modules/babel-plugin-tester/dist/index.js:196:44)
at Object.<anonymous> (node_modules/babel-plugin-tester/dist/index.js:108:13)
at step (node_modules/babel-plugin-tester/dist/index.js:37:191)
at node_modules/babel-plugin-tester/dist/index.js:37:361
Some of the failures look like Jest changed the signature of some functions.
FAIL packages/react-native-web/src/exports/TextInput/__tests__/index-test.js (12.328s)
● components/TextInput › prop "clearTextOnFocus" › encountered a declaration exception
Missing second argument. It must be a callback function.
13 | test(message, fn);
14 | } else {
> 15 | test.skip(`${message} – document is not focused`);
| ^
16 | }
17 | };
FAIL packages/react-native-web/src/exports/Text/__tests__/index-test.js
● components/Text › encountered a declaration exception
Missing second argument. It must be a callback function.
35 | });
36 |
> 37 | test('prop "numberOfLines"');
And this failure makes me think the way the native methods are applied to the class prototype isn't working anymore
● components/TextInput › prop "onKeyPress" › enter key
TypeError: _this.blur is not a function
402 | }
403 | if (shouldBlurOnSubmit) {
> 404 | this.blur();
| ^
405 | }
406 | }
407 | };
package.json
Outdated
@@ -49,8 +51,8 @@ | |||
"flow-bin": "^0.63.1", | |||
"glob": "^7.1.2", | |||
"husky": "^0.14.3", | |||
"jest": "^22.4.3", | |||
"jest-canvas-mock": "^1.0.2", | |||
"jest": "^23.6.0", |
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.
Jest needs to be upgraded to upgrade Babel?
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 just expected better babel 7 support with the latest version. I noticed jest was still installing the babel 6 dependencies but it kept doing it after the upgrade.
Reverted, but had to change a config var testURL
to http://localhost/
because it was giving an error without this (ps: it's the default on newer jests).
"@babel/preset-env": "^7.1.6", | ||
"@babel/preset-flow": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"babel-core": "^7.0.0-bridge.0", |
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.
What is this for?
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.
Not sure if it's required, it was automatically added by https://github.com/babel/babel-upgrade
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.
It is so that babel-jest
can work. https://jestjs.io/docs/en/getting-started#using-babel
package.json
Outdated
"@babel/preset-react": "^7.0.0", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-eslint": "^10.0.1", | ||
"babel-jest": "^23.6.0", |
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.
Why is this needed now?
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.
This was also added automatically by https://github.com/babel/babel-upgrade
Without this I get invalid syntax errors when it sees a import
.
It seems this causes jest to compile the code, but based on your comment that shouldn't happen.
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.
Might that be because you removed the babelrc file? Jest might have been using that before
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.
The .babelrc
was migrated to babel.config.js
, this change was required to fix something.
fc4c0dc
to
3d734d5
Compare
@necolas is |
Are you planning to fix the test failures? |
ea02f35
to
7ce7d3c
Compare
@@ -401,7 +401,7 @@ class TextInput extends Component<*> { | |||
onSubmitEditing(e); | |||
} | |||
if (shouldBlurOnSubmit) { | |||
this.blur(); | |||
if (this.blur) this.blur(); |
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.
The tests were failing with _this.blur is not a function
, not sure what's the best way to fix is, so I changed this code.
@necolas build is passing now. Please make the remaining changes, if any. I may not be available. |
Thank you! Do you know which update fixed the AsyncStorage tests? |
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.
Notes for myself are included inline
\\"use strict\\"; | ||
|
||
exports.__esModule = true; | ||
exports.createElement = exports.Text = exports.StyleSheet = exports.ColorPropType = exports.View = void 0; |
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.
Ensure these snapshots are not changed. The commonjs flag is probably no longer needed here: https://github.com/necolas/react-native-web/blob/0.9.8/package.json#L18
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.
This was being caused by the babel-core
bridge dependency
@@ -401,7 +401,7 @@ class TextInput extends Component<*> { | |||
onSubmitEditing(e); | |||
} | |||
if (shouldBlurOnSubmit) { | |||
this.blur(); | |||
if (this.blur) this.blur(); |
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.
Get to the bottom of what causes this to fail
Yes, it was caused by a new version of |
"@babel/preset-react": "^7.0.0", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-eslint": "^10.0.0", | ||
"babel-jest": "^23.4.2", |
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.
make sure to match jest major version here
This is done in branch |
Nice, would appreciate |
Sorry in this case I didn't use this PR as the basis for the work as I had to change all the dependencies and fix the tests rather than commit incorrect an snapshot and leave the blur instance method broken |
Some tests are failing:
Might be related: jestjs/jest#7016, jestjs/jest#7118
Closes #1170