Граф коммитов

246 Коммитов

Автор SHA1 Сообщение Дата
Eric Lewis 18fededae0 add spec for I18nManager (#24908)
Summary:
Part of #24875.

## Changelog

[General] [Added] - add TM spec for I18nManager
Pull Request resolved: https://github.com/facebook/react-native/pull/24908

Reviewed By: fkgozali

Differential Revision: D15395163

Pulled By: RSNara

fbshipit-source-id: 8fd3a5a8ce5d0f74132efff4fae7224eab03405b
2019-05-31 19:56:37 -07:00
James Ide 1ed352517a Explicitly separate mocked native modules from mocked JS modules (#24809)
Summary:
This commit more clearly defines the mocks RN sets up and uses paths instead of Haste names to define the mocks. The Jest setup script defined mocks for native modules (Obj-C, Java) and mocks for JS modules in the same data structure. This meant that some non-native modules (that is, JS modules) were in the `mockNativeModules` map -- this commit splits them out and mocks them in typical `jest.mock` fashion.

Additionally, the setup script used to mock the modules using the Haste names. As one of the steps toward migrating to standard path-based imports, the setup script now mocks JS modules using paths (native modules don't need a Haste name nor path since they are just entries in `NativeModules`). This gets us closer to being able to remove `hasteImpl`. (Tracking in https://github.com/facebook/react-native/issues/24772.)

Also, this commit removes mocks that are not referenced anywhere in the RN and React repositories (grepped for the names and found no entries outside of the Jest setup scripts).

## Changelog

[General] [Changed] - Explicitly separate mocked native modules from mocked JS modules
Pull Request resolved: https://github.com/facebook/react-native/pull/24809

Differential Revision: D15316882

Pulled By: cpojer

fbshipit-source-id: 039e4e320121bea9580196fe0a091b8b1e8b41bf
2019-05-31 03:19:49 -07:00
Tom Sanderson 7fd08e1461 add spec for PlatformConstants (#24928)
Summary:
part of #24875.

## Changelog

[General] [Added] - add TM spec for PlatformConstants
Pull Request resolved: https://github.com/facebook/react-native/pull/24928

Reviewed By: RSNara

Differential Revision: D15551340

Pulled By: fkgozali

fbshipit-source-id: 9de15ff4cfe717f963332868bd873d5147a37506
2019-05-30 14:29:42 -07:00
Emily Janzer 96a5001024 Add spec for DeviceInfo module
Summary: Adding flow types for DeviceInfo module and migrating our codebase over to using `DeviceInfo.getConstants()`

Reviewed By: fkgozali

Differential Revision: D14645744

fbshipit-source-id: e30a060c6dc92938cd1420ba11a1d837c79d1e32
2019-05-29 16:37:15 -07:00
Rick Hanlon ac62274e56 Use generated view config for ActivityIndicatorView
Summary: This diff moves ActivityIndicatorView to the generated view config

Reviewed By: shergin

Differential Revision: D15392561

fbshipit-source-id: 67a2fa0dbbb884af9e9c02b9062d3a610a023240
2019-05-24 09:21:27 -07:00
Eric Lewis 342c81d754 Add spec for BlobModule (#24909)
Summary:
Part of #24875. Not sure that the id’s types are necessarily correct here…

## Changelog

[General] [Added] - Add TM spec for BlobModule
Pull Request resolved: https://github.com/facebook/react-native/pull/24909

Reviewed By: fkgozali

Differential Revision: D15433753

Pulled By: RSNara

fbshipit-source-id: 68193d1a82fc7c66d6cc7ba4f22a0d3786987599
2019-05-22 13:10:25 -07:00
Jean Regisser 163fb08792 Add spec for SourceCode (#24901)
Summary:
Part of #24875

## Changelog

[General] [Added] - Add TurboModule spec for SourceCode
Pull Request resolved: https://github.com/facebook/react-native/pull/24901

Reviewed By: fkgozali

Differential Revision: D15391727

Pulled By: rickhanlonii

fbshipit-source-id: 9d4622d809efdc3955d435c5a51b72c38cedccc5
2019-05-22 03:27:54 -07:00
James Ide 59749f527a Migrate Jest setup scripts from Haste to path-based requires (#24753)
Summary:
This is another step in moving RN towards standard path-based requires. All the requires in Jest's setup script have been rewritten to use relative requires. This commit uses relative requires instead of `react-native/...` so that if Facebook were to stop syncing out certain folders and therefore remove code from the react-native package, internal code at Facebook would not need to change.

[General] [Changed] - Migrate Jest setup scripts from Haste to path-based requires
Pull Request resolved: https://github.com/facebook/react-native/pull/24753

Differential Revision: D15258238

Pulled By: cpojer

fbshipit-source-id: aa05dc8ea2e4ba195226e8ec7ba6482b7de03240
2019-05-08 06:59:47 -07:00
Nicolas Breidinger 28e0de070d Fix HasteImpl Regex (#24628)
Summary:
The jest HasteImpl's `pluginNameReducers` regex was not properly escaping a backslash, resulting in unintended behavior.

The intent of the code is to strip the `.${name}` from the end of a filepath, where `name` is a platform name. The correct regex for that would be `^(.*)\.(myPlat)$`, but because the regex is being constructed from a string, the `\.` is being interpreted as an escaped period, resulting in the regex  `^(.*).(myPlat)$`. To correct this, the backslash needs to be escaped so it makes it into the regex.

[General] [Fixed] - Fix HasteImpl platform name regex
Pull Request resolved: https://github.com/facebook/react-native/pull/24628

Differential Revision: D15224468

Pulled By: hramos

fbshipit-source-id: 6eb507aa5410bdd7c247e6d301052d41995a2f11
2019-05-06 15:56:15 -07:00
empyrical b27d1d3da2 Remove out-of-tree platform tests (#24536)
Summary:
This pull request removes the tests for out-of-tree platforms and the dependency on the package `react-native-dummy` from the React Native repo.

The logic that this was meant to test was moved to the React Native CLI repo, and [it is being tested there](827daa4c16/packages/cli/src/tools/config/__tests__/index-test.js (L125-L152)) as well making this a bit redundant at this point.

The dependency on `react-native-dummy` was also an issue, because when the file structure under `Libraries/` changes, bundler errors could crop up if there wasn't an update made to the file structure of `react-native-dummy/Libraries/`.

This was an issue when [`TabBarIOS` was removed](02697291ff (diff-b9cfc7f2cdf78a7f4b91a753d10865a2)) - `react-native-dummy` was causing Haste errors and was stopping the commit from being able to land, and I needed to cut a new version just for it. With Lean Core, I expect more issues like this happening in the future.

[General] [Removed] - Removed Out-of-Tree platform tests (functionality is tested in the RN-CLI repo now)
Pull Request resolved: https://github.com/facebook/react-native/pull/24536

Differential Revision: D15063320

Pulled By: cpojer

fbshipit-source-id: 2a0467bed326b286623fa3cfa4e0bb6959b66b78
2019-04-24 07:56:30 -07:00
Brandon Carroll de12b98cd5 WIP: add snapshots for mocked and unmocked components (#24554)
Summary:
Per a conversation with TheSavior, in #24538, this adds snapshot tests for all components whose mocks will be addressed in that PR. Shallow and deep snapshots are included.

[General] [Added] - Snapshots
Pull Request resolved: https://github.com/facebook/react-native/pull/24554

Differential Revision: D15062197

Pulled By: cpojer

fbshipit-source-id: 70ddbaa5e6d1d2c0fd1130ab04c458d9c49d0ee8
2019-04-24 06:52:20 -07:00
Christoph Nakazawa ec90ad127f Fix React Native tests
Summary: At Facebook we do not install the cli or the packages around it. I added some workaround for that in D15044762 but failed to run Jest without cache to test it and it seems like it didn't run on sandcastle properly either (wtf?). Either way, this adds back the `ios` and `android` reducers for `hasteImpl` to run the tests properly again.

Reviewed By: rubennorte

Differential Revision: D15063152

fbshipit-source-id: 2f1fefe664f02d5f2f5e65b75ac1e0c5b813a343
2019-04-24 06:52:20 -07:00
Mike Grabowski 706f67a882 Use latest React Native CLI (#24517)
Summary:
Updates React Native to use latest CLI.

Changes:
- No more `--reactNativePath`, define it once in the configuration file. This reverts the previous PR that added this flag
- Add `platforms` and `commands` - React Native now defines platform like any other package. There's no longer concept of "out-of-tree" platform. All are treated equally. If React Native works, any other platform will work too.
- Updates `jest/hasteImpl.js` to use public CLI interface (`loadConfig`) instead of `findPlugins` and removes a weird conditional that checks for CI presence.

[INTERNAL] - Update React Native CLI
Pull Request resolved: https://github.com/facebook/react-native/pull/24517

Differential Revision: D15044762

Pulled By: cpojer

fbshipit-source-id: 379b61e842e619312c542173219a7d326663cf24
2019-04-24 05:09:10 -07:00
Brandon Carroll a2b699daf6 change jest native method mocks to jest functions (#24337)
Summary:
Currently calling native methods on internal react native components throw a warning. I believe this is problematic because _users_ aren't calling native methods on internal components, the _component_ is making the call.

So for instance, if I unmount a component that has a form with a few uses of `TextInput`, which is a perfectly valid test case, my test output will be full of warnings that I can't call `.blur()` in the test renderer environment. That's very misleading, because I didn't, the internal component did. In fact, as far as I can tell, there's not really even anything I can do to stop that call or use the output from it, its all internal. `TextInput` is a black box, and 99% of users writing tests probably won't even know it calls `.blur()` under the hood on unmount.

I want to change these to `jest.fn()` because I think this eliminates a lot of chatter in test output, but also doesn't send users down a rabbit hole of trying to find workarounds that may involve filtering console output, which could potentially lead them to inadvertently filter out real warnings that they should see.

So I'm willing to change the implementation of how I did this, but I don't think its right to warn users that they called a native method when they didn't. If they build a component that calls these methods, I believe it's on them to do something similar to this, and maybe we can make this exposed as a helper that can be used for third party component mocks?

[General] [Changes] - Changed MockNativeMethods for core components to `jest.fn()` instead of function that warns about calling native methods.
Pull Request resolved: https://github.com/facebook/react-native/pull/24337

Differential Revision: D14822126

Pulled By: cpojer

fbshipit-source-id: 2199b8c8da8e289d38823bdcd2c43c82f3f635c9
2019-04-07 11:54:48 -07:00
Spencer Ahrens b8c8562ffb Set scroll view throttle by default
Summary:
Setting the scroll throttle for every animated scrollview is a pain, and if you forget it's super janky and can be confusing and frustrating.

Enables setting default props in createAnimatedComponent and uses it for scrollview.

Reviewed By: TheSavior

Differential Revision: D14790093

fbshipit-source-id: dd8f6f6540813245e87d696351f09ebb2e6ed5f2
2019-04-05 13:52:30 -07:00
Christoph Nakazawa 06cf7face2 Remove Polyfills from RN Open Source
Summary:
We don't need these polyfills in RN Open Source any longer because JSC supports these features natively.

We also don't need these internally at FB, but I want the removal to be a step by step process and separate from the open source work.

Reviewed By: rickhanlonii

Differential Revision: D14762827

fbshipit-source-id: 114626bd18516c42ced43c3f7aa29d42d1d95335
2019-04-04 15:20:33 -07:00
Estevão Lucas fa426cf05f - Add openSettings method to Linking module (#23965)
Summary:
This will create a cross-platform and safe way to programmatically open the app's settings into the iOS /Android Settings app.

Right now it's possible to open the app's settings, but _**only for iOS**_ via `Linking.openURL("app-settings:")`

To do the same for Android, you need to either create NodeModule or install a dependency such as [react-native-open-settings](https://github.com/lunarmayor/react-native-open-settings).

Why this new method is useful: since Android 6, app permissions work similar to iOS. It's granular and it's requested in the app runtime.

https://developer.android.com/guide/topics/permissions/overview#runtime_requests_android_60_and_higher

> If the device is running Android 6.0 (API level 23) or higher, and the app's targetSdkVersion is 23 or higher, the user isn't notified of any app permissions at install time. Your app must ask the user to grant the dangerous permissions at runtime. When your app requests permission, the user sees a system dialog telling the user which permission group your app is trying to access. The dialog includes a Deny and Allow button.

Thus, if the user checks the **"Never ask again box"** and taps **"Deny"**, for some specific permission, the only way to change the permission is going to the Android Setting app.

And that's where this new method becomes useful. It'll allow our apps to programmatically send the the user to  settings app.

Also, `openSettings()` doesn't receive a parameter to redirect to specific subsections of the Settings app because there's no public API to do it on iOS ([there's a way to have, via private API, but it causes the app to get rejected.](https://github.com/mauron85/cordova-plugin-background-geolocation/issues/394))

Create `Linking.openSettings()` for iOS and Android;

[General] [add ] - Add openSetting method to Linking module
Pull Request resolved: https://github.com/facebook/react-native/pull/23965

Differential Revision: D14502910

Pulled By: cpojer

fbshipit-source-id: d27d62282b9df499845c78d983d3b6936c36ea39
2019-03-18 08:06:12 -07:00
Georgios Andreadis 6047d42bc7 Add tests for Geolocation module (#23987)
Summary:
This PR adds a number of unit tests for the Geolocation module, as a follow-up of #23903. I also added two missing documentation strings to that module, with references to the online documentation, for consistency with the other methods in the same module.

Not applicable, since it only adds tests.
Pull Request resolved: https://github.com/facebook/react-native/pull/23987

Differential Revision: D14502848

Pulled By: cpojer

fbshipit-source-id: 8f7c1cee6be3fae081d9770e5e942fadda65e6c2
2019-03-18 07:40:56 -07:00
Estevão Lucas 65a8a51556 Add missing mock for AccessibilityInfo (#23982)
Summary:
I've realized after #23839 got merged, that `AccessibilityInfo` doesn't have a jest mock the same way as the other frameworks do.

This PR adds the testing mock for `AccessibilityInfo`.
Pull Request resolved: https://github.com/facebook/react-native/pull/23982

Differential Revision: D14502780

Pulled By: cpojer

fbshipit-source-id: ec11bd547b6f90858e7f51ed8230c8d02dc4904c
2019-03-18 07:28:46 -07:00
Mike Grabowski 5558333c60 Update React Native to use latest CLI (#23940)
Summary:
Landing D14472633 again which failed because of a metro-buck issue.

Latest CLI requires `reactNativePath` to be explicitly set when `react-native` is not present under `node_modules` (which is the case when running from source).

Fixes #23936

This PR also updates CLI to latest version and removes private calls to `findPlugins` (it's now exposed under public interface).

We also remove custom `rn-cli.config.js` options that are no longer needed that we have `--reactNativePath`. I added them a month ago as a temporary workaround.

[GENERAL] [FIXED] - Internal - Update to the latest CLI
Pull Request resolved: https://github.com/facebook/react-native/pull/23940

Reviewed By: rickhanlonii

Differential Revision: D14501686

Pulled By: cpojer

fbshipit-source-id: c8dac71b3806d81c9d18b6d4a7e92d82962791f9
2019-03-18 06:22:53 -07:00
Adam Ernst 0ceaaf0cf6 Revert D14472633: [react-native][PR] Update React Native to use latest CLI
Differential Revision:
D14472633

Original commit changeset: b7ea92ee130d

fbshipit-source-id: ed5bce3ba4a39c8b60e787cb678747231583f6f5
2019-03-15 14:07:54 -07:00
Mike Grabowski 1fe4799a88 Update React Native to use latest CLI (#23940)
Summary:
Latest CLI requires `reactNativePath` to be explicitly set when `react-native` is not present under `node_modules` (which is the case when running from source).

Fixes #23936

This PR also updates CLI to latest version and removes private calls to `findPlugins` (it's now exposed under public interface).

We also remove custom `rn-cli.config.js` options that are no longer needed that we have `--reactNativePath`. I added them a month ago as a temporary workaround.

[GENERAL] [FIXED] - Internal - Update to the latest CLI
Pull Request resolved: https://github.com/facebook/react-native/pull/23940

Differential Revision: D14472633

Pulled By: cpojer

fbshipit-source-id: b7ea92ee130da6730aa0093265958aa1b8c2ab97
2019-03-15 11:07:48 -07:00
Peter van der Zee dcd4e90d9a Bump Prettier to 1.16.4
Summary:
@public
This bumps Prettier to v1.16.4
Only format source files were updated.

Reviewed By: mjesun

Differential Revision: D14454893

fbshipit-source-id: 72f9872fe764a79dbf0d9fab9bebb1456b039f2f
2019-03-14 07:00:27 -07:00
zhongwuzw 585d41b30a Add DerivedData to BLACKLISTED_PATTERNS for haste paths (#23807)
Summary:
Each time, when I run `iOS` tests like `RNTesterIntegrationTests`, Xcode will copy the bundle in `DerivedData` directory, and we added `RNTesterUnitTestsBundle.js` to bundle, so it leads `Haste module naming collision`, I think we can add `DerivedData` directory to blacklist.

<img width="752" alt="c7d7dcbd-6507-481a-a8ef-64f16fec3a6f" src="https://user-images.githubusercontent.com/5061845/53960917-6888cc80-4122-11e9-9d1d-faac97f73a26.png">

[iOS] [Fixed] - Add DerivedData to BLACKLISTED_PATTERNS for haste paths
Pull Request resolved: https://github.com/facebook/react-native/pull/23807

Differential Revision: D14436103

Pulled By: cpojer

fbshipit-source-id: fa4bbd87d429f70167253aa38ff20049c9df58b4
2019-03-12 22:32:18 -07:00
George Zahariev 35d2dfcabf Deploy 0.94 to xplat
Summary:
Update Flow version in xplat (https://our.intern.facebook.com/intern/wiki/Flow/Flow_Release_Process/#update-xplat-js)

allow-large-files
bypass-lint

Reviewed By: nmote

Differential Revision: D14317820

fbshipit-source-id: 07ec22c0745321db036f4e10a502009a4b640652
2019-03-06 14:57:30 -08:00
Christoph Nakazawa 14d9b2d68d Remove ListView and SwipeableListView from React Native
Summary:
This diff removes ListView and SwipeableListView from React Native:
* Removes the code and all examples
* Removes the exports on `react-native-implementation` but leaves an error message in dev mode only
* Uses `deprecated-react-native-listview` for `ListView` and `deprecated-react-native-swipeable-listview` for `SwipeableListView`

Both ListView and SwipeableListView are now fully removed from React Native in open source and we will continue to use the deprecated packages internally.

Reviewed By: TheSavior

Differential Revision: D14181708

fbshipit-source-id: 5030c33791f998567de058fee934449c16fa1d54
2019-02-25 22:40:10 -08:00
Nimish 9f4ee25cf7 fix: remove the unused packages and convert minimist to yargs (#23467)
Summary:
`Minimist` package functionality can be done easily using `yargs` package. Also removed couple of unused dependencies.

[General] [changed] - used `yarns` package instead of `minimist` package

Pull Request resolved: https://github.com/facebook/react-native/pull/23467

Differential Revision: D14099638

Pulled By: cpojer

fbshipit-source-id: 59de2086e4204e09c91fd2c99d209ca32c0ef82c
2019-02-15 05:54:10 -08:00
Mike Grabowski 1af390be19 Update references to the CLI (#23052)
Summary:
This updates React Native to use latest CLI. We also create Metro configuration, because CLI looks for React Native in "node_modules" by default. Since we are running React Native from source, it will fail to find required files.

To avoid hacky logic to detect if we are running from source backed into the CLI, I decided to leverage the Metro configuration instead.
Pull Request resolved: https://github.com/facebook/react-native/pull/23052

Reviewed By: rickhanlonii

Differential Revision: D13719938

Pulled By: cpojer

fbshipit-source-id: 1f40a40b3cdbb07ccd42daf75feb457556d3e40f
2019-01-21 09:13:08 -08:00
Ramanpreet Nara 9db0050635 Fix Jest mocks
Summary: Since we started relying on NativeModules' getConstants() method to access constants, we need to update our jest mocks of these NativeModules, so that the tests still pass. I do that in this diff.

Reviewed By: fkgozali

Differential Revision: D13561376

fbshipit-source-id: eaef3de82d842fd97d04be741d55bdded73c6a11
2018-12-30 13:31:16 -08:00
Rafael Oleza f5cb4b68eb Remove metro dependency from react native
Summary:
This diff removes the dependency of `metro` on `react-native` by using the newly created `metro-react-native-babel-transformer` package.

This package does not depend on any other internal metro logic and this will decouple RN from metro a bit more.

Reviewed By: cpojer

Differential Revision: D13434949

fbshipit-source-id: a02a3b327c71cef53111514b797f7d6bc9f9d71c
2018-12-14 08:15:09 -08:00
Christoph Nakazawa 63a6bb7637 Remove remaining references to local-cli
Summary: This removes the remaining references to `local-cli`. We already have a `cli.js` file on the root that was just forwarding to the local-cli folder, so I removed that. It also seems that `setupBabel.js` is no longer necessary in RN.

Reviewed By: TheSavior

Differential Revision: D13396218

fbshipit-source-id: a945cb91dae39c4b58c5cabcca6b0f0328fc4717
2018-12-10 19:08:10 -08:00
Rafael Oleza c8047bfe66 Fix flow types
Summary:
This diff ignores the `react-native-local-cli` from being used internally.

Unfortunately, since `react-native-local-cli` has its own dependency on Metro, and using `yarn` selective resolutions causes some issues with `flow` rechecks that have not been resolved (https://fb.facebook.com/groups/flow/permalink/2220467474668522/), the easiest way to move forward is to just not install the `react-native-local-cli` package internally (we don't need it since we have our own cli).

Reviewed By: pvdz

Differential Revision: D13377495

fbshipit-source-id: 6d6edbd947104e050ad1c31a657fc21fe6848692
2018-12-10 08:36:29 -08:00
ferrannp e8a6cb5e18 Android: Adding sendIntent on Linking module (#22302)
Summary:
This PR implements "Add a standardized way to send intents on Android" discussed in https://github.com/react-native-community/discussions-and-proposals/issues/34.
Pull Request resolved: https://github.com/facebook/react-native/pull/22302

Differential Revision: D13374186

Pulled By: cpojer

fbshipit-source-id: 2f0b9b9f46e99f382b6c35b1914e75df23a7fd74
2018-12-06 21:13:58 -08:00
Christoph Nakazawa 168ac8d83d Use `findPlugins` from `react-native-local-cli`
Summary: This module now lives outside of the React Native repo.

Reviewed By: TheSavior

Differential Revision: D13337412

fbshipit-source-id: 548868e5f1f3812574fda3d235eb9d47c81d6522
2018-12-06 20:15:46 -08:00
Rick Hanlon c5b80062ea Fix ActivityIndicator snapshot test, add toMatchShallowSnapshot
Summary:
This diff adds a custom matcher which will wrap a given component and shallow render it, snapshotting the result with the formatting users will see when they do the same.

I also update the ActivityIndicator test to use this new strategy, and add an additional check that the displayName is set.

For context see:
- https://github.com/facebook/react-native/pull/21950
- https://github.com/rajivshah3/rn-broken-snapshot/blob/broken-example/__tests__/App.spec.js#L3
- https://github.com/facebook/react-native/issues/21937

Reviewed By: TheSavior

Differential Revision: D13326689

fbshipit-source-id: 8ed2302a8aad12962fa2498a46d2502ccfb5c737
2018-12-05 17:23:42 -08:00
Panagiotis Vekris ef2084c6bd 0.87.0 in xplat/js
Summary: allow-large-files

Reviewed By: samwgoldman

Differential Revision: D13230018

fbshipit-source-id: f07e2371a3b7382de0592cc7c7b20e7f4faa6889
2018-11-28 17:32:50 -08:00
Spencer Ahrens 6f34bc4016 Back out "reapply TextInput es6 conversion with fixes, attemps to fix"
Summary:
Back it out again. This time really not sure why this is breaking, but it seems to be production only. The error seems to be "RCTSinglelineTextInputView" was not found in the UIManager" but the relavent logic is not changed in this diff, just moved around, so unclear why it would trigger a failure.

Reverting to be safe. When we re-apply the diff, we'll need to test a full OTA to prod to verify the fix.

Reviewed By: blairvanderhoof

Differential Revision: D13108463

fbshipit-source-id: 5f877a0c1a08dc114ce45921d6d92bf619575977
2018-11-16 14:50:23 -08:00
Spencer Ahrens 9ea1295179 reapply TextInput es6 conversion with fixes, attemps to fix
Summary: D10515754 reapplied by backing out D12989604 and then fixed by manually forwarding the instance methods to the host function instead of using `forwardRef`. This also removes the need for the $flowFixMe.

Reviewed By: TheSavior

Differential Revision: D13048482

fbshipit-source-id: ff2447aff123e0960eddaef645f7dc976a426e14
2018-11-15 20:51:52 -08:00
Gary Borton 0b314960aa Adds support for `publicPath` to enable serving assets from different locations. (#299)
Summary:
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. The two fields below are mandatory. -->

**Summary**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

This is an updated followup from https://github.com/facebook/metro/pull/280, which we would still need to address the following assumptions about `/assets/`:

e7deea1900/packages/metro/src/Server.js (L332)

e7deea1900/packages/metro/src/Server.js (L379)

e7deea1900/packages/metro/src/Server.js (L385)

As pointed out by gdborton, there isn't currently a way to make this a configurable option. I am not certain how to find a proper workaround for `processRequest`.

We found a temporary solution to have our express app pick up serving the assets from a publicPath as a middleware. But the change in this PR is still necessary to get it working fully.

**Test plan**

<!-- Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes UI. -->

- Will add tests once we figure out a comprehensive solution
Pull Request resolved: https://github.com/facebook/metro/pull/299

Reviewed By: rafeca

Differential Revision: D12939229

Pulled By: mjesun

fbshipit-source-id: 769c23468c5ac434f8319e5e7caaf46dd6453f2d
2018-11-09 05:51:06 -08:00
Eli White f386f831d2 Back out TextInput es6 conversion
Summary:
This was failing due to issues with refs, which we were able to fix and then finally due to some jest tests that were failing due to things being null that shouldn't be which I couldn't easily figure out. Reverting the stack until we can actually solve it, hopefully with additional tests.

This was created by running:

```
$ hg backout c2fe2c46e538
fetching tree '' b9bbfc1925c6daf85ba3227d12f177aca9c0c054, based on 4257c76aefa84aaa17279e65aa7ca1174f4401e7, found via 02368b670953
connected to hg015.frc2.facebook.com
60 trees fetched over 2.91s
fetching tree '' c3c304df13399f0f1a29a668242da454fc1d8a97, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via c2fe2c46e538
7 trees fetched over 0.03s
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
commit 4270328:50a65c5c2e27 backs out commit 4266783:c2fe2c46e538
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 0.57s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (50a65c5)]$ hg backout 02368b670953
fetching tree '' a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, based on b9bbfc1925c6daf85ba3227d12f177aca9c0c054, found via bade4285eafb
connected to hg024.frc2.facebook.com
27 trees fetched over 3.21s
fetching tree '' 361548a090e81d18bab6f4fc16036c518cb4d7c1, based on a46c8ca065f5b92cf375d7ed899fc5ca268ba4da, found via bade4285eafb
41 trees fetched over 0.10s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
8 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270329:dbaca0daf0ac backs out commit 4266782:02368b670953
14 files fetched over 7 fetches - (14 misses, 0.00% hit ratio) over 1.72s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (dbaca0d)]$ hg backout bade4285eafb
connected to hg030.frc2.facebook.com
fetching tree '' 1b4a17164fdbfcad40139e46da4a9bfa8aa8def3, based on 361548a090e81d18bab6f4fc16036c518cb4d7c1, found via 5cfb25344385
7 trees fetched over 0.06s
merging react-native-github/Libraries/Components/TextInput/TextInput.js
20 files updated, 1 files merged, 0 files removed, 0 files unresolved
commit 4270330:2951740e5b32 backs out commit 4266781:bade4285eafb
33 files fetched over 14 fetches - (33 misses, 0.00% hit ratio) over 4.50s
[twsvcscm@sandcastle3265.ftw1 /data/sandcastle/boxes/instance-ide/xplat/js (2951740)]$ hg backout 5cfb25344385
connected to hg035.frc2.facebook.com
merging react-native-github/Libraries/Components/TextInput/TextInput.js
0 files updated, 1 files merged, 2 files removed, 0 files unresolved
commit 4270331:fffb4629a397 backs out commit 4266780:5cfb25344385
1 files fetched over 1 fetches - (1 misses, 0.00% hit ratio) over 4.03s
```

Reviewed By: yungsters

Differential Revision: D12989604

fbshipit-source-id: 703a7c9c1f5bdd710077e515bdff06fdb34502ec
2018-11-08 17:59:10 -08:00
Eli White 7e818aed9a Fixing TextInput related jest tests
Reviewed By: yungsters

Differential Revision: D10519823

fbshipit-source-id: 02368b670953a0275fa6495b0c73ef84403598cb
2018-11-07 18:44:40 -08:00
Michał Pierzchała 5e997f9d51 use requireActual and requireMock from jest instead of require (#21849)
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: https://github.com/facebook/react-native/pull/21849

Differential Revision: D10448849

Pulled By: TheSavior

fbshipit-source-id: 34fffde97f48c26098c74ee222a56d99071703a6
2018-10-18 15:32:15 -07:00
Rafael Oleza 89a358f347 Expose enableBabelRuntime config param externally
Summary:
Up until now the `enableBabelRuntime` option in the `metro-react-native-preset` package was hardcoded in the transformer: our internal transformer set it to `false` and the opensource one was `true`.

This diff now exposes this param out to the config of Metro (now that it's quite easy to expose things) so anybody can set it to false or true.

This allows our end to end tests to set it to false to not have to deal with requires to `babel/runtime`.

Reviewed By: davidaurelio

Differential Revision: D10123776

fbshipit-source-id: 97e744eeb567c8e86ab3c613ac71970d226ed2ca
2018-10-05 11:33:38 -07:00
Andrew Chen (Eng) aac7c4d5d2 Refactor UIManager view manager accesses
Summary: Replaced each view manager access with a getViewManager() function call. This will later be used to lazily load view manager classes by allowing java to avoid sending the entire list of view managers to JS.

Reviewed By: QueryConnectionException

Differential Revision: D9695788

fbshipit-source-id: 949858aa2f0b0b00b68e260461ba8f1d085cf07f
2018-09-27 16:03:22 -07:00
empyrical 57041ee44f Add tests for out-of-tree platform support (#20932)
Summary:
This PR is a WIP for adding tests for out-of-tree platform support. [I originally had issues](https://github.com/facebook/react-native/pull/20825#issuecomment-416433611) with this, so I want to give it a try in a separate pull request. None of these issues appear on my machine while running these tests as of this rebase - if everything seems okay on CircleCI after this rebase against `master`, I will ditch the [WIP] tag. Otherwise, I will see if I can find a way to make this work.

The bunch of JS files that will give this a "Large PR" tag are in `RNTester/js/OutOfTreeTestPlatform` - they are only used by the bundler and not executed at any point in time. So if another file needs to be added when React Native's module structure changes, you do not need to have a functional JS file in there as a stub. `module.exports` could be `null` if you wanted. I just had copied over stubs from `Libraries` because I wanted a non-trivial haste module map to be in the test.
Pull Request resolved: https://github.com/facebook/react-native/pull/20932

Reviewed By: axe-fb

Differential Revision: D9818112

Pulled By: hramos

fbshipit-source-id: 0b53359b84430fdefb972587c95d19f85773c5fa
2018-09-27 13:19:32 -07:00
Janic Duplessis 458d56c0a1 Remove global babelHelpers and regenerator (#21283)
Summary:
Follow up to 8932a9caa8

Babel helpers and regenerator runtime will be imported automatically from `babel/runtime`. We still need to add the global regeneratorRuntime for jest tests since we disable babel-runtime currently.
Pull Request resolved: https://github.com/facebook/react-native/pull/21283

Reviewed By: mjesun

Differential Revision: D10010963

Pulled By: rafeca

fbshipit-source-id: da5e23dd901f8f8940d46816b4fc9290d0e28c76
2018-09-26 10:03:05 -07:00
Rafael Oleza 28dedfb6d6 Cleanup the transformer flow types
Summary:
Since the options that are passed to the `babelTransformer` are not exactly the same ones as the `transformer` receives, we need to have a specific object for them.

This allows us to make the transformer options object strict (since unfortunately the `babeltransformer` options object comes from many places and needs a bit of work to be able to be strict...

Reviewed By: mjesun

Differential Revision: D9309173

fbshipit-source-id: 0a92381968f17e5eb6c4740c1ca89580fa7ee4d3
2018-09-24 10:22:23 -07:00
Rafael Oleza 2e0d5c87e9 Remove absolute path parameter from transformers
Summary:
Up until now, transformers in Metro received the absolute path of a file, the relative path of a file and the projectRoot.

This diff gets rid of the absolute path sent to the worker, since by having the projectRoot and the relative path, the absolute path can be easily calculated.

This has been done to avoid having absolute paths as transform options, since we need to have custom logic to filter them out from the cache key generation, which is dangerous.

Reviewed By: mjesun

Differential Revision: D9195147

fbshipit-source-id: e95c5c29272eec7f1a48af7cede4c6d6b4a8ffb7
2018-09-24 10:22:23 -07:00
Janic Duplessis 36033bd0ed Use babel runtime instead of relying on global babelHelpers and regenerator (#198)
Summary:
**Summary**

The RN transformer currently relies on the enviroment providing babelHelpers and regeneratorRuntime as globals by using 'babel-external-helpers'. This wasn't really a problem before since helpers were stable and we could maintain our copy easily but it seems like there are more now with babel 7 and it makes sense to include only those used by the app.

This is exactly what babel/transform-runtime does. It will alias all helpers and calls to regeneratorRuntime to files in the babel/runtime package.

This will solve issues like this https://github.com/facebook/react-native/issues/20150 caused by missing babelHelpers. This solution also avoids bloating babelHelpers to fix OSS issues like the one linked before.

**Test plan**

- Updated tests so they all pass.
- Tested that it actually works by applying the changes locally in an RN app.
- Added a test for async functions, to make sure regenerator is aliased properly and doesn't depend on the global.
- Made sure require-test.js still fails if the require implementation contains babel helpers (by adding an empty class in the file).
Pull Request resolved: https://github.com/facebook/metro/pull/198

Reviewed By: mjesun

Differential Revision: D8833903

Pulled By: rafeca

fbshipit-source-id: 7081f769f288ab358ba89ae8ee72a513bb12e225
2018-09-21 16:17:40 -07:00
Héctor Ramos 1151c096da Update copyright headers to yearless format
Summary: This change drops the year from the copyright headers and the LICENSE file.

Reviewed By: yungsters

Differential Revision: D9727774

fbshipit-source-id: df4fc1e4390733fe774b1a160dd41b4a3d83302a
2018-09-11 15:33:07 -07:00
empyrical 03476a225e Add support for out-of-tree platform plugins (#20825)
Summary:
This pull request adds the ability for a platform developer to provide a `"haste"` key under the `"rnpm"` key in their `package.json` which allows the packager to pick up that platform's javascript files. The intent is to remove the need to have custom platforms hardcoded in. This is inspired by the `"jest": { "haste": {} }` key used by jest.

For example, React Native Dom would have an entry like:

```json
{
  "rnpm": {
    "haste": {
      "providesModuleNodeModules": [
        "react-native-dom"
      ],
      "platforms": [
        "dom"
      ]
    }
  }
}
```

Support for more keys (path blacklists perhaps?) could be added in the future.

This succeeds #20662, as per a discussion I had with matthargett.

I've got an open discussion over here as well: https://github.com/react-native-community/discussions-and-proposals/issues/21
Pull Request resolved: https://github.com/facebook/react-native/pull/20825

Differential Revision: D9596429

Pulled By: hramos

fbshipit-source-id: a02f0da0bea8870bdc45d55e23da8ccbc36249f2
2018-08-30 16:38:07 -07:00
Eli White d2c27f5bff Remove view configs from JS
Summary: Apparently different apps have different implementations of view managers that support different props. This is a problem that we will need to address. Unfortunately, this means we can't have a static config defined in JS. We will need to find another approach to this problem.

Reviewed By: sahrens

Differential Revision: D9500178

fbshipit-source-id: b591559164fcf29f5fd43e13a0f2da15011491c6
2018-08-24 14:04:09 -07:00
Rafael Oleza dd0900a03a Standarize options passed to the transformer
Summary:
This is the first step to make transformers fully customizable (and not be tied to JS, or RN). In order to do that, I'm changing the signature of the transformers, which currently is:

```
function transformCode(
  filename: string,
  localPath: LocalPath,
  transformerPath: string,
  options: WorkerOptions,
  assetExts: $ReadOnlyArray<string>,
  assetRegistryPath: string,
  minifierPath: string,
  asyncRequireModulePath: string,
  dynamicDepsInPackages: DynamicRequiresBehavior,
)
```

to be:

```
async function transformCode(
  filename: string,
  localPath: LocalPath,
  options: WorkerOptions,
)
```

(so basically, all the RN-custom properties are moved to `WorkerOptions`, which in the future will be a generic to allow anybody pass any random option to their transformers).

In order to make all this work, I've had to get rid of the logic that calculates the base cache key hash based on a subset of worker options (the ones that Metro knows that are not going to change between runs).

This could potentially cause a perf regression (since we're now making the hash calculation a bit more costly), and in fact I could measure a ~400ms regression on the worse case scenario (which happens when restarting Metro and re-transforming a Wilde from a warm local cache).

I've benchmarked this regression and could find that it's caused by the array of `assetExtensions` (which is potentially large). I have a followup diff to improve this, which is able to remove the regression completely.

Reviewed By: pvdz

Differential Revision: D8695766

fbshipit-source-id: eccd18a4cbc91854f34d5c9ba7f95088f19483a1
2018-08-23 15:48:03 -07:00
Eli White 1329d18c6a Require that JS defined Component Attributes match Native ones in dev
Summary: As we move these configs to JS from native, until we have codegen that ensures everything stays up to date, this adds a dev mode check to ensure they are consistent.

Reviewed By: yungsters

Differential Revision: D9475011

fbshipit-source-id: 9d6f7b6c649229cae569d840eda3d5f7b7aa7cb2
2018-08-23 13:01:41 -07:00
Kohei TAKATA 88be0cefac Fix eslint errors and warnings in preprocessor.js
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/20632

Differential Revision: D9367291

Pulled By: hramos

fbshipit-source-id: bdb823db132dcbb07ad02389a3246e5314de2b17
2018-08-22 13:48:53 -07:00
Héctor Ramos 1081560d86 Add missing trailing comma
Summary: Adds missing comma, following up on https://github.com/facebook/react-native/pull/20178. Thanks to LinusU for pointing out the error.

Reviewed By: TheSavior

Differential Revision: D9242887

fbshipit-source-id: 4b547396722d0e37dc5c8eb3439b9a441c3c0ac2
2018-08-13 12:01:57 -07:00
Jan Kassens 7205232792 remove FbRelayNativeAdapter
Summary: Doesn't look like this is used anymore.

Reviewed By: schwink

Differential Revision: D9032481

fbshipit-source-id: c35b7db07c068b6238bacc25183a468c9d62661d
2018-07-27 13:37:12 -07:00
Vincent Riemer c4bcca6685 Whitelist react-native-dom in haste/cli config defaults (#20393)
Summary:
This adds `react-native-dom` to `hasteImpl.js` because it's not currently possible to configure it from an out of tree platform. Also adds the relevant `providesModuleNodeModules` and `platforms` values to the default RN CLI config. This should hopefully be able to be removed once better support for out of tree platforms is implemented.
Pull Request resolved: https://github.com/facebook/react-native/pull/20393

Differential Revision: D9007186

Pulled By: hramos

fbshipit-source-id: 67077860dc1fb191d80300fb980599ed76d5f91c
2018-07-25 17:47:42 -07:00
Rafael Oleza 3ac86c366c Fix hasteImpl path checks on Windows machines
Summary:
@public

This fixes https://github.com/facebook/metro/issues/181

Reviewed By: mjesun

Differential Revision: D8880071

fbshipit-source-id: 27e232baa7f39a938af86de810ff5357f777e858
2018-07-17 16:33:56 -07:00
Umair Ansari 9d5bd50737 - Invalid use of destructuring
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/20178

Differential Revision: D8860733

Pulled By: TheSavior

fbshipit-source-id: ec4aa3050755652106dec9ea245394314c862e97
2018-07-16 11:07:23 -07:00
Rubén Norte 54942746d4 Hotfix to include react-native-windows in hasteImpl accepted paths (#20007)
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
2018-07-02 11:17:41 -07:00
Miguel Jimenez Esun 14cd15ef54 Enforce component name
Summary: When snapshotting, do not get affected by the building process.

Reviewed By: rafeca

Differential Revision: D8638527

fbshipit-source-id: 8335fc55c0c85f2ff110db338a5000c7af4b29aa
2018-06-26 07:47:11 -07:00
Eli White 66aeeff2f9 Include static properties in jest mocks for core components
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
2018-06-19 21:32:26 -07:00
Spencer Ahrens ddf2c2ffd6 fix forwardRef displayName on Text and View
Reviewed By: TheSavior

Differential Revision: D8342852

fbshipit-source-id: 5af80edfd5de5b6d6ea6fdc24abf8931f767c812
2018-06-11 19:22:51 -07:00
Eli White edd7acbb1e ActivityIndicator ES6 Class
Reviewed By: yungsters

Differential Revision: D8219463

fbshipit-source-id: 7d252d15bb4a7345d156b1659b09be2a4a69ba6c
2018-06-01 10:25:30 -07:00
Rafael Oleza b90cbd195a Rename default RN transformer
Differential Revision: D8235001

fbshipit-source-id: 59a4b2f13185dd9be0d33f01589d907d49493a26
2018-06-01 07:16:42 -07:00
sAm_vdP 216bce3163 Fix jest snapshot testing on windows
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
2018-05-31 12:58:05 -07:00
Peter van der Zee 7014a30baa Upgrade babel to beta.47 across xplat
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
2018-05-23 06:16:01 -07:00
gengjiawen 4a2c560768 add missing jest mock in StatusBarManager
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
2018-05-15 14:01:39 -07:00
Rafael Oleza b762f5293e Decouple the Worker options from the Babel Transformer options
Reviewed By: jeanlauliac

Differential Revision: D7894079

fbshipit-source-id: 40cbd991690f25f8c0f045c42a0105d74d516803
2018-05-11 15:18:53 -07:00
Eli White 36fcbaa56d Prettier the rest of ReactNative
Reviewed By: yungsters

Differential Revision: D7974340

fbshipit-source-id: 5fe457a8a9be4bd360fc3af9acb5c1136b2be0d7
2018-05-11 13:52:30 -07:00
Tim Yung e708010d18 RN: Switch `Text` to `React.forwardRef`
Reviewed By: sahrens

Differential Revision: D7902262

fbshipit-source-id: 218f95cde6d77f21d9362a2f2bd47c5f83d5ee15
2018-05-09 01:16:12 -07:00
Tim Yung 3e534b9aab RN: Switch `View` to `React.forwardRef`
Reviewed By: bvaughn, sophiebits

Differential Revision: D7896711

fbshipit-source-id: c10c8a14a00ac2d67605e6e4fe1a341b4688fdd8
2018-05-09 01:16:11 -07:00
Tim Yung 5d4c542c58 RN: Refactor `MockNativeMethods` in Jest
Reviewed By: sahrens

Differential Revision: D7917498

fbshipit-source-id: 97636080588bf2641a56256688cb0f2ec81ae463
2018-05-09 01:16:11 -07:00
Brian Vaughn de08f4ab6c Blacklist FB RN renderer for RN GitHub OSS tests
Reviewed By: rubennorte

Differential Revision: D7774634

fbshipit-source-id: f293e897e31daf1e7230f55cc932c25ee6f8558a
2018-04-26 08:58:40 -07:00
Rubén Norte d5e9e55fa3 Remove @providesModule from all modules
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
2018-04-25 07:37:10 -07:00
David Aurelio 2690ba5e59 Move worker protocol and babelRegisterOnly into their own packages
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
2018-04-23 04:00:00 -07:00
Peter van der Zee 3aa453d975 Add sourceType as a new mandatory option
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
2018-04-19 10:11:25 -07:00
Peter van der Zee da57ae740d Add `ast: true` to transform options for jest
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
2018-04-19 09:16:48 -07:00
Peter van der Zee c18684a293 Fix the metro paths for files detected as nodejs
Summary: Fix the path lookup for files to be considered to run in nodejs.

Reviewed By: mjesun

Differential Revision: D7685278

fbshipit-source-id: c921d40b60d795820448842aec464e7ff82b6eab
2018-04-19 09:16:48 -07:00
Peter van der Zee d408de0438 Drop confusing comment
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
2018-04-19 09:16:48 -07:00
Peter van der Zee f8d6b97140 BREAKING CHANGE: UPGRADE REACT NATIVE TO BABEL 7!
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
2018-04-11 16:47:18 -07:00
Matt Mahoney c9a6b8560f Revert D7097279: BREAKING CHANGE: UPGRADE REACT NATIVE TO BABEL 7!
Differential Revision:
D7097279

Original commit changeset: 9fb204cae733

fbshipit-source-id: bbbb20b5dbed5dc01ae5557686a07d987b9a6cc6
2018-04-11 08:25:17 -07:00
Peter van der Zee ebd12fa09f BREAKING CHANGE: UPGRADE REACT NATIVE TO BABEL 7!
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
2018-04-10 21:02:43 -07:00
Sebastian Markbage a8e3c7f578 Yolo Delete ReactNativePropRegistry
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
2018-04-09 18:46:11 -07:00
Matt Oakes 43014eaf19 Fix #18279: Add 'addNetworkingHandler' to jest mock setup
Summary:
Fixes #18279 by adding the correct methods to the jest mocks setup file.

Test by no longer including the workarounds in [issue comments](https://github.com/facebook/react-native/issues/18279#issuecomment-374177940). A [comment from hramos](https://github.com/facebook/react-native/issues/18279#issuecomment-371914037) mentioned improving the test coverage as well, but I wasn't certain how to achieve that.

[GENERAL] [BUGFIX] [BlobManager] - Fixed the jest mocks to avoid breaking tests
Closes https://github.com/facebook/react-native/pull/18718

Differential Revision: D7542458

Pulled By: hramos

fbshipit-source-id: 77c9c7cae77971d62e878c4832b2e1d205131e8f
2018-04-09 11:33:24 -07:00
Eli White 3e9a371ace Mock ReactNative.NativeComponent native methods in jest
Reviewed By: yungsters

Differential Revision: D7218964

fbshipit-source-id: f4b25a533b7e150c978863ff8411dc80937a4fed
2018-03-09 13:43:30 -08:00
Maxime Thirouin 59c7b2cfac Add missing mock for AppState (removeEventListener)
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
2018-02-25 22:18:30 -08:00
Jean Lauliac 4454fdc219 fix Flow typing for OSS
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
2018-02-19 10:41:33 -08:00
Caleb Meredith da3424c929 @allow-large-files Upgrade xplat/js to Flow v0.66
Reviewed By: gabelevi

Differential Revision: D7016717

fbshipit-source-id: 2bd2fd67074ba5d405ecd63a1aeb37354f8634c9
2018-02-16 20:24:57 -08:00
Sophie Alpert 1490ab12ef Update license headers for MIT license
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
2018-02-16 18:31:53 -08:00
Andres Suarez 59401f89c1 Fold .eslintrc's into the root eslintrc
Reviewed By: TheSavior

Differential Revision: D6997050

fbshipit-source-id: 81e45d24343cca8336adb0de43bd766899ff03b6
2018-02-15 07:53:52 -08:00
James Ide af6450c660 Add back support for the assetPlugin option
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
2018-01-12 05:52:16 -08:00
uk-ar 11a2a35c63 Fix Jest mocks for Dimensions module
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
2017-12-03 16:48:17 -08:00
Christoph Nakazawa 654fed46f4 Rename metro-bundler to metro
Reviewed By: davidaurelio

Differential Revision: D6413420

fbshipit-source-id: f13184b8157de2c3aeaa7f2647becc175f62cdbb
2017-11-29 03:35:29 -08:00
Rafael Oleza d5b59517c2 Simplify transform options + pass minify to the transformer
Reviewed By: mjesun

Differential Revision: D6406614

fbshipit-source-id: 722e8e209c7b7c922139f0777b9b3bd2a77bf735
2017-11-24 13:07:24 -08:00
Rafael Oleza 2ae255a6ea Update jest preprocessors to use the ast from the transformers
Reviewed By: jeanlauliac

Differential Revision: D6390677

fbshipit-source-id: e023fc32188c2d601b35d7a2e3f0f6f8af067962
2017-11-22 13:41:57 -08:00
Tim Wang 7fb3a9229d Fix Jest mocks for NetInfo module.
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
2017-11-10 10:12:30 -08:00
Maksym Rusynyk 3088096684 Return request id in jest mock for requestAnimationFrame
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
2017-10-14 14:03:16 -07:00
Julien Moutte bbceb48dbb Direct assignment of the ref to avoid warning when mocking.
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
2017-10-09 21:46:20 -07:00
Janic Duplessis 1af645b2fd Validate that JS and Native code versions match for RN releases
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
2017-09-27 18:31:15 -07:00
Miguel Jimenez Esun 33bbfb7125 Fix test for RN asset
Reviewed By: cpojer, rafeca

Differential Revision: D5777553

fbshipit-source-id: 3bc8559076435c6254972552095967b88acb0576
2017-09-07 01:55:56 -07:00
Tim Wang 165f876730 Add BlobModule native module mock to jest setup
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
2017-09-06 23:51:57 -07:00
Marshall Roch 91b6b4efb9 @allow-large-files Flow v0.54.0
Reviewed By: leebyron

Differential Revision: D5773490

fbshipit-source-id: 2c54bb6326f23edbe9a969f3010f79da8189923e
2017-09-06 03:33:43 -07:00
Martin Yrjölä 25639176ff Asset basenames in Jest snapshots
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
2017-09-06 03:33:43 -07:00
Eli White 36f2d18b10 Disallow trailing commas in react-native-github
Reviewed By: cpojer

Differential Revision: D5645043

fbshipit-source-id: 7378cc96ce39d3d18da7fba51d48db84cfdfa08f
2017-08-17 16:20:04 -07:00
Brian Vaughn 046f600cc2 React 16 beta 5 sync (5495e49...c3718c4)
Reviewed By: spicyj

Differential Revision: D5564030

fbshipit-source-id: fd3e6133df7ee8e7488a3c515ce6c783c11d9401
2017-08-09 12:35:30 -07:00
Alex Dvornikov 70edc2fd80 Upgrade metro-bundler to v0.10.0
Reviewed By: davidaurelio

Differential Revision: D5469746

fbshipit-source-id: 1d2c0f6c5bb9761cfc54b6c9fdbb1a9f20f535ea
2017-07-21 09:40:15 -07:00
Eli White aafccdf622 Revert D5409825: [RN] Convert easy files to Prettier
Differential Revision: D5409825

fbshipit-source-id: f797a40b58bc6bcc6ae53ed820a10ab49d3f10f5
2017-07-12 19:23:58 -07:00
Eli White c198911561 Convert easy files to Prettier
Reviewed By: zertosh

Differential Revision: D5409825

fbshipit-source-id: 81f67be174cc8ecfcd0955dfec83955ebdc84622
2017-07-12 16:08:22 -07:00
Eli White fc86f25f9a Run eslint on all js files
Reviewed By: zertosh

Differential Revision: D5405047

fbshipit-source-id: 5ade9d8beb3688d8bb08a208709c0dbf1ec671b2
2017-07-12 14:09:53 -07:00
Hank Brekke 0797dae500 Jest Mocks for NetInfo and Linking
Summary:
This isn't exhaustive, but it's a few more functions that these modules normally export which need to be stubbed.
Closes https://github.com/facebook/react-native/pull/14432

Differential Revision: D5345928

Pulled By: shergin

fbshipit-source-id: f333056ac43ce7c75c6734bca8dc9035745721df
2017-06-29 01:00:39 -07:00
David Aurelio 1faf40b02a Upgrade metro-bundler to v0.9.0
Summary: Upgrade metro-bundler to v0.9.0. This version has no functional change. The only change is that the structure of the npm package reflects the structure of the source code.

Reviewed By: bestander

Differential Revision: D5315651

fbshipit-source-id: 3a69337106d4ccf708823c80d304941973360e8e
2017-06-24 17:15:55 -07:00
David Aurelio 5c57601769 Remove `retainLines` and `sourceMaps` options
Summary:
`retainLines` is no longer necessary with the much improved source map generation.
`sourceMaps` is handled by the transformer itself.

Reviewed By: cpojer

Differential Revision: D5237103

fbshipit-source-id: e5c6bf5aa9d553fce9c3f4d59b3ea0057d45cfdc
2017-06-14 09:32:37 -07:00
Christoph Pojer 236e9e4d01 Remove react-native/packager folder.
Summary: This folder is not necessary any longer. All the code now lives in https://github.com/facebook/metro-bundler

Reviewed By: davidaurelio, jeanlauliac

Differential Revision: D5199196

fbshipit-source-id: 35bf0f10a9163f53426db9a76f8f853dceb69167
2017-06-07 07:30:32 -07:00
Jean Lauliac 328d8ddb47 metro-bundler: make internal tool to use the new source of thruth for packager/metro-bundler
Reviewed By: davidaurelio

Differential Revision: D5182904

fbshipit-source-id: df5de3a9eb85560a09789d0a94eccb5c48ecba7b
2017-06-06 05:15:51 -07:00
Kyle Pinkham 7c2ef3281f Fixed ImageLoader Mock for Android
Summary:
When trying to mock an Image on Android, this error occurs referencing the ImageLoader mock in setup.js:
```
/Users/.../node_modules/react-native/jest/setup.js:120
return success(320,240);
       ^

TypeError: success is not a function
    at /Users/.../node_modules/react-native/jest/setup.js:120:8
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
```
- Mocking Images works for iOS but not Android.
- Since Image.android.js uses ImageLoader vs ImageViewManager, the code cannot be carried over from iOS.

Since this is code within the testing framework, the existing tests should test this. If there is no existing test coverage, then this would need to be done.
Closes https://github.com/facebook/react-native/pull/14262

Differential Revision: D5162640

Pulled By: shergin

fbshipit-source-id: 5b1efbbb685b767e09b5c7fb05f073445c94a3aa
2017-05-31 23:49:35 -07:00
Christoph Pojer 57bb955ba1 Move remaining Metro Bundler files around.
Reviewed By: jeanlauliac

Differential Revision: D5154653

fbshipit-source-id: 482bf9829263d5d8f3d0b951ee58e2020236cc2c
2017-05-31 11:17:41 -07:00
Eli White dc339f77f3 Adding mocks for missing native modules
Reviewed By: fkgozali

Differential Revision: D5052517

fbshipit-source-id: 649e0f01c3d8534b898690f9140d5fc610676041
2017-05-15 15:45:26 -07:00
David Aurelio 2fbe3b799e Pass local paths to transformers
Summary:
Pass `localPath` to transformers to allow usage of plugins like `transform-react-jsx-source` that don’t conflict with x-machine caches, e.g. Buck or our own global cache.
These caches don’t work properly if paths local to a specific machine are part of cached outputs.

Reviewed By: jeanlauliac

Differential Revision: D5044147

fbshipit-source-id: 1177afb48d6dd9351738fcd4da8f9f6357e25e81
2017-05-11 16:47:43 -07:00
David Aurelio 58337c9032 BREAKING: Pass parameters to `transformer.transform` as object
Reviewed By: jeanlauliac

Differential Revision: D5037155

fbshipit-source-id: fbd18bd62254d7e1522f659ea62055e66748a951
2017-05-11 08:35:07 -07:00
ZauberNerd 31a0b8788f Add jest mock for 'PushNotificationManager'
Summary:
`PushNotificationIOS` is a library that makes use of the
`PushNotificationManager` native module.
This commit adds a jest mock for its native module so that code that
uses `PushNotificationIOS` can be tested using jest.

In order to enable behaviour in unit tests it is possible to replace or
overwrite the mock implementation, see the [jest guide on
mocks](https://facebook.github.io/jest/docs/mock-functions.html).
By doing something similar to:
```javascript
import { NativeModules } from 'react-native';
const { PushNotificationManager } = NativeModules;
// mock 'checkPermissions' to return a different value than the default:
PushNotificationManager.checkPermissions.mockImplementationOnce((callback) => {
    // execute callback in next tick to enable async behaviour
    process.nextTick(() => callback({
        alert: false,
        badge: false,
        sound: false
    }));
});
// execute unit tests for code that makes use of 'PushNotificationIOS'
```
Closes https://github.com/facebook/react-native/pull/13410

Differential Revision: D5043904

Pulled By: cpojer

fbshipit-source-id: 11e73cd215ba6854d06f4ac7a5aea0ab4be26584
2017-05-11 03:50:52 -07:00
David Aurelio 73fc439bc0 Stronger typing for transformers
Reviewed By: jeanlauliac

Differential Revision: D5006679

fbshipit-source-id: 795c60db363fb53bc74697e4befe50995e9b97a7
2017-05-09 08:02:36 -07:00
Emily Janzer 8ae4c3fcfd Add request/cancelAnimationFrame to jest setup
Reviewed By: cpojer

Differential Revision: D5005587

fbshipit-source-id: 653c281df9025a75ed8eecd22a2e64eaf188bf3e
2017-05-04 17:35:06 -07:00
Emmanouil Konstantinidis 5121434262 Mock Linking - openURL & canOpenURL
Summary:
This PR brings 2 basic mocks for `Linking`'s `openURL` & `canOpenURL` methods. Below you can find 2 examples on how to it works.

```javascript

  it('presses the open website button', () => {
    const wrapper = shallow(<Info />);

    expect(wrapper).toBeDefined();

    wrapper.find('TouchableOpacity').simulate('press');

    expect(Linking.openURL).toHaveBeenCalledTimes(1);
    expect(Linking.openURL).toHaveBeenCalledWith('https://www.hello.world/');
  });

  it('presses the call button', () => {
    const wrapper = shallow(<MoreInfo />);

    expect(wrapper).toBeDefined();

    wrapper.find('TouchableOpacity').simulate('press');

    expect(Linking.canOpenURL).toHaveBeenCalledTimes(1);
    expect(Linking.canOpenURL).toHaveBeenCalledWith('tel:01273123123');
  });
````
Closes https://github.com/facebook/react-native/pull/12839

Differential Revision: D4908903

Pulled By: javache

fbshipit-source-id: 0b62e9c2a7f920dc8bf0a49c1973f65c473eb653
2017-04-19 04:20:12 -07:00
William Durand 6a1e0516e9 Add Geolocation API Jest mock
Summary:
Hello!

The [Geolocation API](https://facebook.github.io/react-native/docs/geolocation.html) is currently not mocked in Jest, which often leads to an `Invariant Violation: Native module cannot be null` error. This patch adds a basic Jest configuration similar to the existing ones for the other modules.

None unfortunately, but this patch makes my test suite all green 😉

Thanks,
William
Closes https://github.com/facebook/react-native/pull/13442

Differential Revision: D4883830

Pulled By: javache

fbshipit-source-id: c2a976834cca7537bd832a698e8cd25cf877705b
2017-04-13 09:35:22 -07:00
ZauberNerd 469acbaa9d fix mock for AsyncLocalStorage
Summary:
The current mock of `AsyncLocalStorage` seems to mock parts of the
`AsyncStorage` API that can't be found on the `AsyncLocalStorage`
object itself and therefore it doesn't work as expected.

What it should do is mock the API of `AsyncLocalStorage` which is a
`NativeModule` so that the `AsyncStorage` module can be used in tests
and it will require the mocked methods.

In order to enable behaviour in unit tests it is possible to replace or
overwrite the mock implementation, see the [jest guide on mocks](https://facebook.github.io/jest/docs/mock-functions.html).
By doing something similar to:
```javascript
import { NativeModules } from 'react-native';
const { AsyncLocalStorage } = NativeModules;
// mock 'multiGet', in order to allow 'AsyncStorage.getItem('myKey')'
AsyncLocalStorage.multiGet.mockImplementationOnce((keys, callback) => {
    callback(null, [['myKey', 'myValue']]);
});
// execute unit tests for code that makes use of 'AsyncStorage'
```
Closes https://github.com/facebook/react-native/pull/13433

Differential Revision: D4883389

Pulled By: javache

fbshipit-source-id: 92a0ee94480b3022acc748e306ee2d4ee7a9869d
2017-04-13 06:32:47 -07:00
Brian Vaughn 703936d9e3 Sync React master (and 16 alpha 4)
Reviewed By: sebmarkbage

Differential Revision: D4747529

fbshipit-source-id: 5efea6422a2502f27c1b23506cbae2187c7f7b0d
2017-03-22 21:30:50 -07:00
Ashwin Bharambe 95c1926193 Introduce `DeviceInfo` as a new native module
Summary:
The `UIManager` already has a lot of responsibilities and is deeply
tied with React Native's view architecture. This diff separates out a
`DeviceInfo` native module to provide information about screen dimensions and
font scale, etc.

Reviewed By: fkgozali

Differential Revision: D4713834

fbshipit-source-id: f2ee93acf876a4221c29a8c731f5abeffbb97974
2017-03-17 17:01:57 -07:00
Christoph Pojer 91b2dbb1de Fix incorrect line numbers in test failures
Reviewed By: voideanvalue

Differential Revision: D4597677

fbshipit-source-id: 9e10fb7aaee16cd902489cd95cfb04a151da2226
2017-02-22 06:51:15 -08:00
Sebastian Markbage c3b25c9059 Patch up for future React Sync
Reviewed By: spicyj, bvaughn

Differential Revision: D4523259

fbshipit-source-id: 317a26ce3e9e48553a7f7c856dd6b48038b4b2ea
2017-02-08 14:50:43 -08:00
Christoph Pojer a2c84d14ce Remove `react-packager` indirection.
Summary:
This moves the `src` directory one level up and removes the `react-packager` folder. Personally, I always disliked this indirection. I'm reorganizing some things in RNP, so this seems to make sense.

Not sure if I forgot to update any paths. Can anyone advice if there are more places that need change?

Reviewed By: jeanlauliac

Differential Revision: D4487867

fbshipit-source-id: d63f9c79d6238300df9632d2e6a4e6a4196d5ccb
2017-02-02 05:44:15 -08:00
Alex Kotliarskyi 2275ca5a7f Add UIManager method mocks to jest/setup.js
Reviewed By: cpojer

Differential Revision: D4420536

fbshipit-source-id: 4fb5c1857974b4d32e21de6d5b5b581213aad87b
2017-01-20 16:43:42 -08:00
David Aurelio 0849f84df2 create better debuggable source maps
Summary:
Introduces a new mechanism to build source maps that allows us to use real mapping segments instead of just mapping line-by-line.

This mechanism is only used when building development bundles to improve the debugging experience in Chrome.

The new mechanism takes advantage of a new feature in babel-generator that exposes raw mapping objects. These raw mapping objects are converted to arrays with 2, 4, or 5 for the most compact representation possible.
We no longer generate a source map for the bundle that maps each line to itself in conjunction with configuring babel generator to retain lines.

Instead, we create a source map with a large mappings object produced from the mappings of each individual file in conjunction with a “carry over” – the number of preceding lines in the bundle.

The implementation makes a couple of assumptions that hold true for babel transform results, e.g. mappings being in the order of the generated code, and that a block of mappings always belongs to the same source file. In addition, the implementation avoids allocation of objects and strings at all costs. All calculations are purely numeric, and base64 vlq produces numeric ascii character codes. These are written to a preallocated buffer objects, which is turned to a string only at the end of the building process. This implementation is ~5x faster than using the source-map library.

In addition to providing development source maps that work better, we can now also produce individual high-quality source maps for production builds and combine them to an “index source map”. This approach is unfeasable for development source maps, because index source map consistently crash Chrome.

Better production source maps are useful to get precise information about source location and symbol names when symbolicating stack traces from crashes in production.

Reviewed By: jeanlauliac

Differential Revision: D4382290

fbshipit-source-id: 365a176fa142729d0a4cef43edeb81084361e54d
2017-01-12 14:28:41 -08:00
Mike Grabowski 8305743725 Fix jest tests
Summary: https://www.facebook.com/groups/reactnativeoss/permalink/1627334037563224/

Differential Revision: D4357483

fbshipit-source-id: 32e9d91c2348e4046a5cfaa08eab34d1f4dd2f7e
2016-12-21 07:58:25 -08:00
Emmanouil Konstantinidis 797506f09f Jest - Support Immutable Objects for ListViewDataSource mock
Summary:
Currently the jest mock for `ListViewDataSource` has a property called `items` which returns the number of items of the data source. Example from a snapshot:

    ListViewDataSource {
      "items": 6,
    }

If the datablob includes immutable Maps like:

    const dataBlob = {
      'alpha': immutable.Map({ name: 'Alpha' }),
      'beta': immutable.Map({ name: 'Beta' }),
    };

then the result is:

    ListViewDataSource {
      "items": NaN,
    }

This PR checks if the properties of the `dataBlob` are immutable Maps and then checks whether they are empty.

The result for the above dataBlob would be:

    ListViewDataSource {
      "items": 2,
    }
Closes https://github.com/facebook/react-native/pull/11567

Differential Revision: D4354977

Pulled By: cpojer

fbshipit-source-id: 9f6bd6ea9896eebd9373344a43ffe97deee5015b
2016-12-20 16:58:29 -08:00
Spencer Ahrens 5537055bf8 Add some `Fake`s for easier interaction snapshot testing
Summary:
`Fake` components are simplified so snapshots are stable and reliable, and references are exported
so that interactions like `onRefresh` and `onScroll` can be called manually. Currently there is just
one global export for each class, but we may change this in the future if we need to manage multiple
`Fake`s of the same type in one render tree.

Right now these must be installed explicitly, but I might move them into `__mocks__` folders if it
seems reasonable to make them defaults.

Reviewed By: cpojer

Differential Revision: D4318207

fbshipit-source-id: 62802353a98b09ca1c80804ef7201ea63091f94a
2016-12-20 15:58:30 -08:00
Nelen 2190221c44 Added mocked functions to StatusBarManager
Summary:
**Description:**
Jest tests that use that StatusBar failing because the status bar functions aren't mocked.
Errors I ran into:
`TypeError: StatusBarManager. setNetworkActivityIndicatorVisible is not a function`
`TypeError: StatusBarManager. setHidden is not a function`
`TypeError: StatusBarManager. setStyle is not a function`

**Fix:**
Added mocks for all the functions that the StatusBar offers according to the docs: https://facebook.github.io/react-native/docs/statusbar.html

**Test plan (required)**
Verify that the tests using StatusBar and its functions succeed.
Closes https://github.com/facebook/react-native/pull/11322

Differential Revision: D4284536

Pulled By: cpojer

fbshipit-source-id: b67be8c0595d91ee9aca4784f457c0959d7e45d5
2016-12-06 05:58:32 -08:00
mlanter 39554ab32c Fix missing mock for StatusBarManager
Summary:
Fix an issue when running Jest unit tests due to a missing mock for StatusBarManger.

**More info:**
In one of my files I have:
```
export const STATUS_BAR_HEIGHT = (StatusBar.currentHeight || 0);
```
When I run the tests it gives this error, which seems to be because StatusBarManager is undefined (https://github.com/facebook/react-native/blob/master/Libraries/Components/StatusBar/StatusBar.js#L20)

```
TypeError: Cannot read property 'HEIGHT' of undefined
  at Object.<anonymous> (node_modules/react-native/Libraries/Components/StatusBar/StatusBar.js:395:1823)
  at Object.StatusBar (node_modules/react-native/Libraries/react-native/react-native.js:55:24)
```

**Test plan (required)**
Verify that with this change tests that use StatusBar pass.
Closes https://github.com/facebook/react-native/pull/11198

Differential Revision: D4246367

Pulled By: cpojer

fbshipit-source-id: ee9406d2566688d235a11cab8f24b0583698e93a
2016-11-29 22:13:44 -08:00
Kevin Cooper 00f888a318 Add missing mock for AppState
Summary:
**Description**

In the same vein as https://github.com/facebook/react-native/pull/11198, this adds a mock for the native module `AppState`.

**Test plan**

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);
  }
}
```
Closes https://github.com/facebook/react-native/pull/11199

Differential Revision: D4246668

Pulled By: cpojer

fbshipit-source-id: e3a73a98963a0e152a70aba78ef3461b86da0f6c
2016-11-29 14:43:38 -08:00
Tim Yung 23331df5a4 RN: Cleanup OSS JS & Flow Declarations
Reviewed By: vjeux

Differential Revision: D4210763

fbshipit-source-id: 5abaa547100b8badd13bcf311ceffc5b4098d252
2016-11-20 17:58:29 -08:00
Cristian Carlesso 6d3e074dd4 Adding Jest preset so that people can configure Jest using react-native as preset
Reviewed By: cpojer

Differential Revision: D4081817

fbshipit-source-id: 43cf2ec467ea69651705162b6a58e0b3f1ad1dbf
2016-10-31 12:58:35 -07:00
Cristian Carlesso 9833e1bd34 Fixes typo
Reviewed By: bestander

Differential Revision: D4103918

fbshipit-source-id: 1176f97cf489180490e497be7deca331ed26e730
2016-10-31 09:28:36 -07:00
Cristian Carlesso 45275e30b9 Fixes Components with prefixes in mock
Reviewed By: bestander

Differential Revision: D4096027

fbshipit-source-id: 342677a27c6d03dc7d2d6eb53970a504fb62d63b
2016-10-28 10:58:39 -07:00
Christoph Pojer 487171fd89 Mock requireNativeComponent so manual mocking of UIManager properties isn't needed
Summary:
Fixes warnings such as `Warning: Native component for "RCTView" does not exist` when you don't mock the native view class on `UIManager`.

**Test plan (required)**

Run `npm test` with it and without it, notice that warnings are gone and results are the same.

cc cpojer
Closes https://github.com/facebook/react-native/pull/10486

Differential Revision: D4063500

Pulled By: cpojer

fbshipit-source-id: f6bdda1fdd1ad87958f435071d353684cb812af4
2016-10-22 20:28:42 -07:00
Cristian Carlesso 6a462fb085 Moving the jest configuration from jest-react-native to react native.
Reviewed By: cpojer

Differential Revision: D3923609

fbshipit-source-id: 62804df81b064871b499ae8c091e13dd1e0f229b
2016-10-17 08:44:05 -07:00