diff --git a/releases/next/docs/getting-started.html b/releases/next/docs/getting-started.html index 3156e0bd453..31ce69675de 100644 --- a/releases/next/docs/getting-started.html +++ b/releases/next/docs/getting-started.html @@ -67,27 +67,28 @@ choco install python2
You can find additional installation o
The React Native CLI #
Node.js comes with npm, which lets you install the React Native command line interface.
Run the following command in a Terminal:
npm install -g react-native-cliIf you get an error like
Cannot find module 'npmlog', try installing npm directly:curl -0 -L https://npmjs.org/install.sh | sudo sh.- Xcode #
The easiest way to install Xcode is via the Mac App Store. Installing Xcode will also install the iOS Simulator and all the necessary tools to build your iOS app.
You will also need to install the Xcode Command Line Tools. Open Xcode, then choose "Preferences..." from the Xcode menu. Go to the Locations panel and install the tools by selecting the most recent version in the Command Line Tools dropdown.
+ Xcode #
The easiest way to install Xcode is via the Mac App Store. Installing Xcode will also install the iOS Simulator and all the necessary tools to build your iOS app.
Android Development Environment #
Setting up your development environment can be somewhat tedious if you're new to Android development. If you're already familiar with Android development, there are a few things you may need to configure. In either case, please make sure to carefully follow the next few steps.
1. Download and install Android Studio #
Android Studio provides the Android SDK and AVD (emulator) required to run and test your React Native apps.
- Android Studio requires a recent version of the Java SE Development Kit (JDK).
+ Android Studio requires the Java SE Development Kit(JDK), version 8. You can type
javac -versionin a terminal to see what version you have, if any.$ javac -version +javac 1.8.0_111The version string
1.8.x_xxxcorresponds to JDK 8.- 2. Install the AVD and HAXM #
Android Virtual Devices allow you to run Android apps on your computer without the need for an actual Android phone or tablet. Choose
Custominstallation when running Android Studio for the first time. Make sure the boxes next to all of the following are checked:
Android SDKAndroid SDK PlatformPerformance (Intel ® HAXM)Android Virtual DeviceThen, click "Next" to install all of these components.
If you've already installed Android Studio before, you can still install HAXM without performing a custom installation.
+ 2. Install the AVD and HAXM #
Choose
Custominstallation when running Android Studio for the first time. Make sure the boxes next to all of the following are checked:
Android SDKAndroid SDK PlatformPerformance (Intel ® HAXM)Android Virtual DeviceThen, click "Next" to install all of these components.
If you've already installed Android Studio before, you can still install HAXM without performing a custom installation.
- 2. Install the AVD and configure VM acceleration #
Android Virtual Devices allow you to run Android apps on your computer without the need for an actual Android phone or tablet. Choose
Custominstallation when running Android Studio for the first time. Make sure the boxes next to all of the following are checked:
Android SDKAndroid SDK PlatformAndroid Virtual DeviceClick "Next" to install all of these components, then configure VM acceleration on your system.
+ 2. Install the AVD and configure VM acceleration #
Choose
Custominstallation when running Android Studio for the first time. Make sure the boxes next to all of the following are checked:
Android SDKAndroid SDK PlatformAndroid Virtual DeviceClick "Next" to install all of these components, then configure VM acceleration on your system.
- 3. Install the Android 6.0 (Marshmallow) SDK #
Android Studio installs the most recent Android SDK by default. React Native, however, requires the
Android 6.0 (Marshmallow)SDK. To install it, launch the SDK Manager, click on "Configure" > "SDK Manager" in the "Welcome to Android Studio" screen.The SDK Manager can also be found within the Android Studio "Preferences" menu, under Appearance & Behavior → System Settings → Android SDK.
Select the "SDK Platforms" tab from within the SDK Manager, then check the box next to "Show Package Details" in the bottom right corner. Look for and expand the
Android 6.0 (Marshmallow)entry, then make sure the following items are all checked:
Google APIsAndroid SDK Platform 23Intel x86 Atom_64 System ImageGoogle APIs Intel x86 Atom_64 System Image
Next, select the "SDK Tools" tab and check the box next to "Show Package Details" here as well. Look for and expand the "Android SDK Build Tools" entry, then make sure that
Android SDK Build-Tools 23.0.1is selected.Finally, click "Apply" to download and install the Android SDK and related build tools.
+ 3. Install the Android 6.0 (Marshmallow) SDK #
Android Studio installs the most recent Android SDK by default. React Native, however, requires the
Android 6.0 (Marshmallow)SDK. To install it, launch the SDK Manager, click on "Configure" > "SDK Manager" in the "Welcome to Android Studio" screen.The SDK Manager can also be found within the Android Studio "Preferences" menu, under Appearance & Behavior → System Settings → Android SDK.
Select the "SDK Platforms" tab from within the SDK Manager, then check the box next to "Show Package Details" in the bottom right corner. Look for and expand the
Android 6.0 (Marshmallow)entry, then make sure the following items are all checked:
Google APIsAndroid SDK Platform 23Intel x86 Atom System ImageIntel x86 Atom_64 System ImageGoogle APIs Intel x86 Atom_64 System ImageNext, select the "SDK Tools" tab and check the box next to "Show Package Details" here as well. Look for and expand the "Android SDK Build Tools" entry, then make sure that
Android SDK Build-Tools 23.0.1is selected.Finally, click "Apply" to download and install the Android SDK and related build tools.
4. Set up the ANDROID_HOME environment variable #
The React Native command line interface requires the
ANDROID_HOMEenvironment variable to be set up.- Add the following lines to your
~/.profile(or equivalent) config file:export ANDROID_HOME=${HOME}/Library/Android/sdk +Add the following lines to your
~/.bashrc(or equivalent) config file:export ANDROID_HOME=${HOME}/Library/Android/sdk export PATH=${PATH}:${ANDROID_HOME}/tools -export PATH=${PATH}:${ANDROID_HOME}/platform-toolsType
source ~/.profileto load the config into your current shell.Please make sure you export the correct path for
ANDROID_HOME. If you installed the Android SDK using Homebrew, it would be located at/usr/local/opt/android-sdk.+export PATH=${PATH}:${ANDROID_HOME}/platform-tools Please make sure you export the correct path for
ANDROID_HOME. If you installed the Android SDK using Homebrew, it would be located at/usr/local/opt/android-sdk.- Add the following lines to your
~/.profile(or equivalent) config file:export ANDROID_HOME=${HOME}/Android/Sdk +Add the following lines to your
~/.bashrc(or equivalent) config file:export ANDROID_HOME=${HOME}/Android/Sdk export PATH=${PATH}:${ANDROID_HOME}/tools -export PATH=${PATH}:${ANDROID_HOME}/platform-toolsType
source ~/.profileto load the config into your current shell.Please make sure you export the correct path for
ANDROID_HOMEif you did not install the Android SDK using Android Studio.+export PATH=${PATH}:${ANDROID_HOME}/platform-tools Please make sure you export the correct path for
ANDROID_HOMEif you did not install the Android SDK using Android Studio.Go to Control Panel → System and Security → System → Change settings → Advanced System Settings → Environment variables → New, then enter the path to your Android SDK.
Restart the Command Prompt to apply the new environment variable.
Please make sure you export the correct path for
ANDROID_HOMEif you did not install the Android SDK using Android Studio.@@ -95,17 +96,17 @@ export PATH=$ Watchman (optional) #
Follow the Watchman installation guide to compile and install Watchman from source.
Watchman is a tool by Facebook for watching changes in the filesystem. It is highly recommended you install it for better performance, but it's alright to skip this if you find the process to be tedious.
- Starting the Android Virtual Device #
You can see the list of available AVDs by opening the "AVD Manager" from within Android Studio. You can also run the following command in a terminal:
android avdOnce in the "AVD Manager", select your AVD and click "Edit...". Choose "Android 6.0 - API Level 23" under Device, and "Intel Atom (x86_64)" under CPU/ABI. Click OK, then select your new AVD and click "Start...", and finally, "Launch".
It is very common to run into an issue where Android Studio fails to create a default AVD. You may follow the Android Studio User Guide to create a new AVD manually if needed.
Using a real device #
If you have a physical Android device, you can use it for development in place of an AVD. Plug it in to your computer using a USB cable and enable USB debugging before proceeding to the next step.
+ Starting the Android Virtual Device #
You can see the list of available AVDs by opening the "AVD Manager" from within Android Studio. You can also run the following command in a terminal:
android avdOnce in the "AVD Manager", select your AVD and click "Start...".
Android Studio should have set up an Android Virtual Device for you during installation, but it is very common to run into an issue where Android Studio fails to install the AVD. You may follow the Android Studio User Guide to create a new AVD manually if needed.
Testing your React Native Installation #
Use the React Native command line interface to generate a new React Native project called "AwesomeProject", then run
react-native run-iosinside the newly created folder.react-native init AwesomeProject cd AwesomeProject -react-native run-iosYou should see your new app running in the iOS Simulator shortly.
react-native run-iosis just one way to run your app. You can also run it directly from within Xcode or Nuclide.+react-native run-ios You should see your new app running in the iOS Simulator shortly.
react-native run-iosis just one way to run your app. You can also run it directly from within Xcode or Nuclide.Use the React Native command line interface to generate a new React Native project called "AwesomeProject", then run
react-native run-androidinside the newly created folder:react-native init AwesomeProject cd AwesomeProject -react-native run-androidIf everything is set up correctly, you should see your new app running in your Android emulator shortly.
react-native run-androidis just one way to run your app - you can also run it directly from within Android Studio or Nuclide.+react-native run-android If everything is set up correctly, you should see your new app running in your AVD shortly.
react-native run-androidis just one way to run your app - you can also run it directly from within Android Studio or Nuclide.Modifying your app #
Now that you have successfully run the app, let's modify it.
@@ -119,13 +120,15 @@ react-native run Testing your React Native Installation #
Use the React Native command line interface to generate a new React Native project called "AwesomeProject", then run
react-native startinside the newly created folder to start the packager.react-native init AwesomeProject cd AwesomeProject -react-native startOpen a new command prompt and run
react-native run-androidinside the same folder to launch the app on your Android emulator.react-native run-android+react-native start Open a new command prompt and run
react-native run-androidinside the same folder to launch the app on your AVD.react-native run-androidTesting your React Native Installation #
Use the React Native command line interface to generate a new React Native project called "AwesomeProject", then run
react-native run-androidinside the newly created folder.react-native init AwesomeProject cd AwesomeProject react-native run-android- If everything is set up correctly, you should see your new app running in your Android emulator shortly.
+ If everything is set up correctly, you should see your new app running in your Android emulator shortly.
+ + If you're targeting API level 23, the app might crash on first launch with an error smilar to
Unable to add window android.view.ViewRootImpl$W@c51fa6 -- permission denied for this window type. To fix this, you need to go toSystem settings > Apps > Configure apps > Draw over other appsand grant the permission for the app.NOTE: Many React Native modules haven't been tested on Marshmallow and might break. Please thoroughly test the app if you target API level 23 and file a bug report if you find that something is broken.
Modifying your app #
Now that you have successfully run the app, let's modify it.
- Open
index.android.jsin your text editor of choice and edit some lines.- Press the
Rkey twice or selectReloadfrom the Developer Menu to see your change!That's it! #
Congratulations! You've successfully run and modified a React Native app.
diff --git a/releases/next/docs/testing.html b/releases/next/docs/testing.html index be292e884f3..347206b4a92 100644 --- a/releases/next/docs/testing.html +++ b/releases/next/docs/testing.html @@ -1,14 +1,8 @@ - Testing Testing #
This document is about running tests on React Native itself. If you're interested in testing a React Native app, check out the React Native Tutorial on the Jest website.
Running Tests and Contributing #
The React Native repo has several tests you can run to verify you haven't caused a regression with your PR. These tests are run with the Travis and CircleCI continuous integration systems, which will automatically annotate pull requests with the test results.
Whenever you are fixing a bug or adding new functionality to React Native, you should add a test that covers it. Depending on the change you're making, there are different types of tests that may be appropriate.
JavaScript Tests #
Jest #
Jest tests are JavaScript-only tests run on the command line with node. You can run the existing React Native jest tests with:
$ cd react-native -$ npm testIt's a good idea to add a Jest test when you are working on a change that only modifies JavaScript code.
The tests themselves live in the
__tests__directories of the files they test. SeeTouchableHighlight-test.jsfor a basic example.Flow #
You should also make sure your code passes Flow tests. These can be run using:
$ cd react-native -$ npm run flowAndroid #
Unit Tests #
The Android unit tests do not run in an emulator. They just use a normal Java installation. The default macOS Java install is insufficient, you may need to install Java 8 (JDK8). You can type
javac -versionin a terminal to see what version you have:$ javac -version -javac 1.8.0_111The version string
1.8.x_xxxcorresponds to JDK 8.You also need to install the Buck build tool.
To run the Android unit tests:
$ cd react-native -$ ./scripts/run-android-local-unit-tests.shIt's a good idea to add an Android unit test whenever you are working on code that can be tested by Java code alone. The Android unit tests live under
ReactAndroid/src/tests, so you can browse through that directory for good examples of tests.Integration Tests #
To run the integration tests, you need to install the Android NDK. See Prerequisites.
You also need to install the Buck build tool.
We recommend running the Android integration tests in an emulator, although you can also use a real Android device. It's a good idea to keep the emulator running with a visible window. That way if your tests stall, you can look at the emulator to debug.
Some devices and some emulator configurations may not work with the tests. We do maintain an emulator configuration that works, as the standard for testing. To run this emulator config:
$ cd react-native +Testing Testing #
Running Tests and Contributing #
This document is about running tests on React Native itself. If you're interested in testing a React Native app, check out the React Native Tutorial on the Jest website.
The React Native repo has several tests you can run to verify you haven't caused a regression with your PR. These tests are run with the Travis and CircleCI continuous integration systems, which will automatically annotate pull requests with the test results.
Whenever you are fixing a bug or adding new functionality to React Native, you should add a test that covers it. Depending on the change you're making, there are different types of tests that may be appropriate.
Jest Tests #
Jest tests are JavaScript-only tests run on the command line with node. You can run the existing React Native jest tests with:
$ cd react-native +$ npm testIt's a good idea to add a Jest test when you are working on a change that only modifies JavaScript code.
The tests themselves live in the
__tests__directories of the files they test. SeeTouchableHighlight-test.jsfor a basic example.Android Unit Tests #
The Android unit tests do not run in an emulator. They just use a normal Java installation. You do need to install Java 8. In particular, the default OS X Java install is insufficient.
You also need to install the Buck build tool.
To run the Android unit tests:
$ cd react-native +$ ./scripts/run-android-local-unit-tests.shIt's a good idea to add an Android unit test whenever you are working on code that can be tested by Java code alone. The Android unit tests live under
ReactAndroid/src/tests, so you can browse through that directory for good examples of tests.Android Integration Tests #
To run the integration tests, you need to install the Android NDK. See Prerequisites.
You also need to install the Buck build tool.
We recommend running the Android integration tests in an emulator, although you can also use a real Android device. It's a good idea to keep the emulator running with a visible window. That way if your tests stall, you can look at the emulator to debug.
Some devices and some emulator configurations may not work with the tests. We do maintain an emulator configuration that works, as the standard for testing. To run this emulator config:
$ cd react-native $ ./scripts/run-android-emulator.shOnce you have an emulator running, to run the integration tests:
$ cd react-native -$ ./scripts/run-android-local-integration-tests.shThe integration tests should only take a few minutes to run on a modern developer machine.
It's a good idea to add an Android integration test whenever you are working on code that needs both JavaScript and Java to be tested in conjunction. The Android integration tests live under
ReactAndroid/src/androidTest, so you can browse through that directory for good examples of tests.iOS #
Integration Tests #
React Native provides facilities to make it easier to test integrated components that require both native and JS components to communicate across the bridge. The two main components are
RCTTestRunnerandRCTTestModule.RCTTestRunnersets up the ReactNative environment and provides facilities to run the tests asXCTestCases in Xcode (runTest:moduleis the simplest method).RCTTestModuleis exported to JS asNativeModules.TestModule.The tests themselves are written in JS, and must call
TestModule.markTestCompleted()when they are done, otherwise the test will timeout and fail. Test failures are primarily indicated by throwing a JS exception. It is also possible to test error conditions withrunTest:module:initialProps:expectErrorRegex:orrunTest:module:initialProps:expectErrorBlock:which will expect an error to be thrown and verify the error matches the provided criteria.See the following for example usage and integration points:
You can run integration tests locally with cmd+U in the IntegrationTest and UIExplorer apps in Xcode, or by running the following in the command line on macOS:
$ cd react-native -$ ./scripts/objc-test-ios.shYour Xcode install will come with a variety of Simulators running the latest OS. You may need to manually create a new Simulator to match what the
XCODE_DESTINATIONparam in the test script.Screenshot/Snapshot Tests #
A common type of integration test is the snapshot test. These tests render a component, and verify snapshots of the screen against reference images using
TestModule.verifySnapshot(), using theFBSnapshotTestCaselibrary behind the scenes. Reference images are recorded by settingrecordMode = YESon theRCTTestRunner, then running the tests. Snapshots will differ slightly between 32 and 64 bit, and various OS versions, so it's recommended that you enforce tests are run with the correct configuration. It's also highly recommended that all network data be mocked out, along with other potentially troublesome dependencies. SeeSimpleSnapshotTestfor a basic example.If you make a change that affects a snapshot test in a PR, such as adding a new example case to one of the examples that is snapshotted, you'll need to re-record the snapshot reference image. To do this, simply change to
_runner.recordMode = YES;in UIExplorer/UIExplorerSnapshotTests.m, re-run the failing tests, then flip record back toNOand submit/update your PR and wait to see if the Travis build passes.End-to-end tests #
Finally, make sure end-to-end tests run successfully by executing the following script:
$ cd react-native -$ ./scripts/test-manual-e2e.shWebsite #
The React Native website is hosted on GitHub pages and is automatically generated from Markdown sources as well as comments in the JavaScript source files. It's always a good idea to check that the website is generated properly whenever you edit the docs.
$ cd website -$ npm install -$ npm startThen open http://localhost:8079/react-native/index.html in your browser.
You can edit the content above on GitHub and send us a pull request!