Summary:
Closes https://github.com/facebook/react-native/pull/20007
We removed support for providesModule annotations and maintained support for Haste names in installed modules via `providesModuleNodeModules`, but our default `hasteImpl` doesn't take them into account. We need to find a better way to override core components from plugins but meanwhile this adds an exception for react-native-windows in the default `hasteImpl` to unblock their upgrade to the latest RC.
Fixes https://github.com/facebook/metro/issues/188
Reviewed By: mjesun
Differential Revision: D8695207
fbshipit-source-id: 2ad6cb1e93e600880a148776ac45f6ebd7d205d3
Summary: When snapshotting, do not get affected by the building process.
Reviewed By: rafeca
Differential Revision: D8638527
fbshipit-source-id: 8335fc55c0c85f2ff110db338a5000c7af4b29aa
Summary: This is necessary to provide things like `Image.prefetch` in Jest tests. Previously this only gave access to propTypes.
Reviewed By: sahrens
Differential Revision: D8526494
fbshipit-source-id: 11d49d95d6edf3f75c90438e0b629f5345bc980d
Summary:
Fixes#19370
Applied changes to existing project that uses jest snapshot testing. Testing was broken before and now works.
To verify: Run any snapshot test containing an image reference on Windows before and after this PR.
[WINDOWS][BUGFIX][jest] - Fixed jest snapshot testing on windows
Closes https://github.com/facebook/react-native/pull/19496
Differential Revision: D8195947
Pulled By: hramos
fbshipit-source-id: 909b5fe7cfd8c6286baf161a227a359854a37603
Summary:
Upgrade Babel from beta.40 to beta.47
There are two important breaking changes here.
- If you want an AST from the Babel `transform` functions you must pass on `ast:true` in the options.
- The `sourceType` is now the only source of truth on whether to parse with the Script or Module goal. It defaults to `script` and can also be `module` or `unambiguous`. In the `unambiguous` case it will first try to parse with the Module goal and only if it crashes it will try again with the Script goal.
Beyond that there were some fixes and some smaller changes that may affect you. See the Babel changelogs for details (https://github.com/babel/babel/tags).
Also updated the way we generate the babel helpers file.
Reviewed By: rubennorte
Differential Revision: D8075280
fbshipit-source-id: 2bb902690e8a4b19d9cada2b7b0c94812b3d4f0f
Summary:
fix issue https://github.com/facebook/react-native/issues/11701.
Pass current ci
<!--
Does this PR require a documentation change?
Create a PR at https://github.com/facebook/react-native-website and add a link to it here.
-->
<!--
Required.
Help reviewers and the release process by writing your own release notes. See below for an example.
-->
[GENERAL] [BUGFIX] [JEST] - add missing jest mock in StatusBarManager
<!--
**INTERNAL and MINOR tagged notes will not be included in the next version's final release notes.**
CATEGORY
[----------] TYPE
[ CLI ] [-------------] LOCATION
[ DOCS ] [ BREAKING ] [-------------]
[ GENERAL ] [ BUGFIX ] [ {Component} ]
[ INTERNAL ] [ ENHANCEMENT ] [ {Filename} ]
[ IOS ] [ FEATURE ] [ {Directory} ] |-----------|
[ ANDROID ] [ MINOR ] [ {Framework} ] - | {Message} |
[----------] [-------------] [-------------] |-----------|
EXAMPLES:
[IOS] [BREAKING] [FlatList] - Change a thing that breaks other things
[ANDROID] [BUGFIX] [TextInput] - Did a thing to TextInput
[CLI] [FEATURE] [local-cli/info/info.js] - CLI easier to do things with
[DOCS] [BUGFIX] [GettingStarted.md] - Accidentally a thing/word
[GENERAL] [ENHANCEMENT] [Yoga] - Added new yoga thing/position
[INTERNAL] [FEATURE] [./scripts] - Added thing to script that nobody will see
-->
Closes https://github.com/facebook/react-native/pull/19017
Differential Revision: D8014888
Pulled By: hramos
fbshipit-source-id: 1be29f9643cf0faa53ad64f79e11d48b654a97b3
Summary:
This PR removes the need for having the `providesModule` tags in all the modules in the repository.
It configures Flow, Jest and Metro to get the module names from the filenames (`Libraries/Animated/src/nodes/AnimatedInterpolation.js` => `AnimatedInterpolation`)
* Checked the Flow configuration by running flow on the project root (no errors):
```
yarn flow
```
* Checked the Jest configuration by running the tests with a clean cache:
```
yarn jest --clearCache && yarn test
```
* Checked the Metro configuration by starting the server with a clean cache and requesting some bundles:
```
yarn run start --reset-cache
curl 'localhost:8081/IntegrationTests/AccessibilityManagerTest.bundle?platform=android'
curl 'localhost:8081/Libraries/Alert/Alert.bundle?platform=ios'
```
[INTERNAL] [FEATURE] [All] - Removed providesModule from all modules and configured tools.
Closes https://github.com/facebook/react-native/pull/18995
Reviewed By: mjesun
Differential Revision: D7729509
Pulled By: rubennorte
fbshipit-source-id: 892f760a05ce1fddb088ff0cd2e97e521fb8e825
Summary: Moves the implementation of Buck’s worker protocol into its own package and babelRegisterOnly for better reusability.
Reviewed By: rafeca
Differential Revision: D7666896
fbshipit-source-id: ae297494ced3b8dd1f9d90983a640643d6ce7896
Summary:
The `sourceType` option is a new mandatory option for Babel which determines whether to parse the file with the module or script goal. The value "disambiguous" determines this state by parsing.
See https://github.com/babel/babel/pull/7417
Reviewed By: mjesun
Differential Revision: D7685610
fbshipit-source-id: 3958c5ad396592bb1d790e2df4ce315737421a2f
Summary:
This should (at least partially) fix testing for OSS as per f8d6b97140 (r28647044)
Might be related to not locking down the Babel version, will do that in a different commit.
Reviewed By: mjesun
Differential Revision: D7685279
fbshipit-source-id: f00febfad2cec31b7e11996ee8efa2c96b44477b
Summary: Fix the path lookup for files to be considered to run in nodejs.
Reviewed By: mjesun
Differential Revision: D7685278
fbshipit-source-id: c921d40b60d795820448842aec464e7ff82b6eab
Summary:
Just removing a comment
As per f8d6b97140 (r28569388)
While the comment was more to notify about this in general, I suppose it doesn't matter.
Reviewed By: rafeca
Differential Revision: D7685277
fbshipit-source-id: 2d526aeccc2e89b42ae25cbce21af5fe96f1348d
Summary:
BREAKING CHANGE
This change upgrades the React Native build pipeline from Babel 6 to Babel 7
If you use a `.babelrc` then you'll need to update it to Babel 7 (note that some plugins are no longer relevant, some plugins are automatically upgraded, and some will need some manual love).
Note that you may also need to upgrade your dev env, tests etc, to make sure they work with Babel 7.
Reviewed By: mjesun
Differential Revision: D7591303
fbshipit-source-id: 29cef21f6466633a9c366d1f3c0d3cf874c714db
Summary:
BREAKING CHANGE
This change upgrades the React Native build pipeline from Babel 6 to Babel 7
If you use a `.babelrc` then you'll need to update it to Babel 7 (note that some plugins are no longer relevant, some plugins are automatically upgraded, and some will need some manual love).
Note that you may also need to upgrade your dev env, tests etc, to make sure they work with Babel 7.
Reviewed By: cpojer
Differential Revision: D7097279
fbshipit-source-id: 9fb204cae733174a1c155669b7c17ddb70f7aecc
Summary:
Changed StyleSheet.create to be the identity function. We no longer hide it behind an opaque number. Better for types and perf since we don't use it.
I don't really know if we have/need any safer way of rolling this out than just landing it.
It can break if the object passed to StyleSheet.create is mutated afterwards but that isn't a practice anywhere I've seen.
Reviewed By: sophiebits
Differential Revision: D7530023
fbshipit-source-id: bc1afa879c5a5d9cd95cb13bc8ff3347b3622851
Summary:
I am testing with Jest a component that use [AppState.removeEventListener](https://facebook.github.io/react-native/docs/appstate.html#removeeventlistener) and I am currently facing a fatal error saying that `AppState.removeEventListener` is `undefined`.
Create a component that uses `AppState`, e.g.
```jsx
import React, { Component } from 'react';
import { AppState } from 'react-native';
class TestComponent extends Component {
componentDidMount() {
AppState.addEventListener('change', this.stateChangeListener);
}
componentWillUnmount() {
AppState.removeEventListener('change', this.stateChangeListener);
}
}
```
It should pass test using Jest (snapshots)
It's the continuation of #11199. This PR finish the mock for the native module `AppState`.
[ GENERAL ] [ BUGFIX ] [AppState] Add missing mock for Jest for `removeEventListener` method.
Closes https://github.com/facebook/react-native/pull/17908
Differential Revision: D7083144
Pulled By: shergin
fbshipit-source-id: eafa07f064f971c3d657f2ffc9c00766c0925bac
Summary:
Add ignores for these requires, some of them mistakenly removed by da3424c929.
```
yarn flow
```
CircleCI should be green again.
Closes https://github.com/facebook/react-native/pull/18021
Differential Revision: D7025304
Pulled By: jeanlauliac
fbshipit-source-id: 731232093ae3ab39b3eff6fb2004ff4e7090d5ae
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.
find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.
Reviewed By: TheSavior, yungsters
Differential Revision: D7007050
fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
Summary:
**Summary**
Metro used to have support for "asset plugins", which allowed developers to specify arbitrary JS modules that could export a function for adding more fields to asset data objects. Some of this functionality was removed in the delta bundler work -- this PR adds it back.
**Test plan**
Made existing unit tests pass and added unit tests to test asset plugin behavior. Also tested E2E in a React Native project by adding `assetPlugin=/path/to/pluginModule` to a JS bundle URL and ensuring that the plugin ran.
Closes https://github.com/facebook/metro/pull/118
Differential Revision: D6711094
Pulled By: rafeca
fbshipit-source-id: f42c54cfd11bac5103194f85083084eef25fa3cd
Summary:
Jest mock for Dimensions.get("screen") is missing. Tests fail with error message:
Invariant Violation: No dimension set for key screen
Run test with usage of Dimensions.get("screen")
[GENERAL] [BUGFIX] [jest/setup.js] - Fix Jest mocks for Dimensions module
Closes https://github.com/facebook/react-native/pull/17017
Differential Revision: D6471719
Pulled By: TheSavior
fbshipit-source-id: de27b2819d088fefe20dfca94ab5672fdec5f0e1
Summary:
Jest mock for `NetInfo.getConnectionInfo()` is missing. Tests are fail with error message:
```
TypeError: _reactNative.NetInfo.getConnectionInfo is not a function
```
And cleaned code in this files for unified code styles.
Run test with usage of `NetInfo.getConnectionInfo()`
[GENERAL] [BUGFIX] [jest/setup.js] - Fix Jest mocks for NetInfo module
Closes https://github.com/facebook/react-native/pull/16722
Differential Revision: D6298133
Pulled By: hramos
fbshipit-source-id: 589cf6fed93965e7a09823015f2793f5c68a9c3b
Summary:
`Jest` allows to use fake timers and according to https://developer.mozilla.org/en-US/docs/Web/API/Window/requestAnimationFrame the return value should be `A long integer value, the request id, that uniquely identifies the entry in the callback list`. This allows to use `cancelAnimationFrame`.
In current implementation of `jest/setup.js`, the return value is undefined. Therefore it's not possible to cancel the animation frame request.
```
let id = null;
const registerCallback = (callback) => {
clearCallback();
id = requestAnimationFrame(() => {
id = null;
callback();
});
};
const clearCallback = () => {
if (null !== id) {
cancelAnimationFrame(id);
id = null;
}
};
```
```
jest.useFakeTimers();
const callback = jest.fn();
registerCallback(callback);
clearCallback();
jest.runAllTimers();
expect(callback).toHaveBeenCalledTimes(0); // Will be error in current implementation, since nothing is cleared. And test will pass, after MR is merged
```
This is fake example, but the real usage is when the animation frame request should be removed on `ComponentWillUnmount`.
[JEST] [BUGFIX] [requestAnimationFrame] - return request id
Closes https://github.com/facebook/react-native/pull/16367
Differential Revision: D6060578
Pulled By: ericnakagawa
fbshipit-source-id: c785a3380f5e267b48ae16fcf34dbbf95fa54178
Summary:
When Jest is mocking native components that are assigned a ref with an arrow function, a warning is generated about stateless components which can not have a ref. This does not happen when the ref is assigned directly.
Fixes#16045.
<!--
Thank you for sending the PR! We appreciate you spending the time to work on these changes.
Help us understand your motivation by explaining why you decided to make this change.
You can learn more about contributing to React Native here: http://facebook.github.io/react-native/docs/contributing.html
Happy contributing!
-->
The test provided in the related issue is used to validate the fix. I don't know how to detect console warnings in a Jest test.
Closes https://github.com/facebook/react-native/pull/16046
Differential Revision: D6017903
Pulled By: ericnakagawa
fbshipit-source-id: a7ed61c39f141a4094f08fc875289a7a79ebe9e8
Summary:
Basic implementation of the proposal in #15271
Note that this should not affect facebook internally since they are not using OSS releases.
Points to consider:
- How strict should the version match be, right now I just match exact versions.
- Wasn't able to use haste for ReactNativeVersion because I was getting duplicate module provider caused by the template file in scripts/versiontemplates. I tried adding the scripts folder to modulePathIgnorePatterns in package.json but that didn't help.
- Redscreen vs. warning, I think warning is useless because if the app crashes you won't have time to see the warning.
- Should the check and native modules be __DEV__ only?
**Test plan**
Tested that it works when version match and that it redscreens when versions don't before getting other errors on Android and iOS.
Closes https://github.com/facebook/react-native/pull/15518
Differential Revision: D5813551
Pulled By: hramos
fbshipit-source-id: 901757e25724b0f22bf39de172b56309d0dd5a95
Summary:
React Native v0.48.0 shipped `WebSocketModule` support with `BlobModule` as dependency. But `BlobModule` is not mocked in jest which will cause render tests failed.
Reference implantation: [BlobModule.java](ed903099b4/ReactAndroid/src/main/java/com/facebook/react/modules/blob/BlobModule.java)
Related PR: #11417
Related issue: #15810
Passed CI tests.
Need render a component in jest with WebSocketModule as dependency.
Closes https://github.com/facebook/react-native/pull/15843
Differential Revision: D5783263
Pulled By: shergin
fbshipit-source-id: 2386692f4a644796da2fd66b3135da9f5911663e
Summary:
This change only affects tests run with Jest. `require('/images/image1.png')` will be replaced with
```
Object {
"testUri": "relative/path/to/images/image1.png",
}
```
in the Jest snapshot instead of always being 1 returned by RelativeImageStub. This change makes it possible to test conditional asset loading in components.
The problem with this change is that it will probably break a lot of existing snapshots, but that should be easily fixed when a project updates to a new version of React Native by running `jest -u` to update all snapshots.
A component can have conditional asset loading based on its props, this logic would be nice to test with Jest snapshots. This problem has been discussed in https://github.com/facebook/jest/issues/2838.
* **Who does this affect**: Everyone using `Image` in Jest snapshots
* **How to migrate**: Running `jest -u` will update the snapshots, the snapshots should be reviewed that they are correct.
* **Why make this breaking change**: It enables testing of conditional asset loading.
* **Severity (number of people affected x effort)**: Low.
Closes https://github.com/facebook/react-native/pull/13319
Reviewed By: rafeca
Differential Revision: D5708180
Pulled By: mjesun
fbshipit-source-id: 16ac42004d597db08545a21d4fffe95c5ee7e21f