Updated docs for next

This commit is contained in:
Hector Ramos
2017-03-17 14:06:36 -07:00
parent 55ac22188a
commit 7d3605c082
6 changed files with 61 additions and 6 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1048,7 +1048,7 @@ h2 {
display: table-cell; }
p {
margin: 10px 0; }
margin: 16px 0; }
.highlight {
padding: 10px;
+1 -1
View File
@@ -5,7 +5,7 @@ javac <span class="token number">1.8</span><span class="token punctuation">.</sp
$ <span class="token punctuation">.</span><span class="token operator">/</span>scripts<span class="token operator">/</span>run<span class="token operator">-</span>android<span class="token operator">-</span>local<span class="token operator">-</span>unit<span class="token operator">-</span>tests<span class="token punctuation">.</span>sh</div><p>It&#x27;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 <a href="https://github.com/facebook/react-native/tree/master/ReactAndroid/src/test/java/com/facebook/react" target="_blank"><code>ReactAndroid/src/tests</code></a>, so you can browse through that directory for good examples of tests.</p><h3><a class="anchor" name="integration-tests"></a>Integration Tests <a class="hash-link" href="docs/testing.html#integration-tests">#</a></h3><p>To run the integration tests, you need to install the Android NDK. See <a href="docs/android-building-from-source.html#prerequisites" target="_blank">Prerequisites</a>.</p><p>You also need to install the <a href="https://buckbuild.com/setup/install.html" target="_blank">Buck build tool</a>.</p><p>We recommend running the Android integration tests in an emulator, although you can also use a real Android device. It&#x27;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.</p><p>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:</p><div class="prism language-javascript">$ cd react<span class="token operator">-</span>native
$ <span class="token punctuation">.</span><span class="token operator">/</span>scripts<span class="token operator">/</span>run<span class="token operator">-</span>android<span class="token operator">-</span>emulator<span class="token punctuation">.</span>sh</div><p>Once you have an emulator running, to run the integration tests:</p><div class="prism language-javascript">$ cd react<span class="token operator">-</span>native
$ <span class="token punctuation">.</span><span class="token operator">/</span>scripts<span class="token operator">/</span>run<span class="token operator">-</span>android<span class="token operator">-</span>local<span class="token operator">-</span>integration<span class="token operator">-</span>tests<span class="token punctuation">.</span>sh</div><p>The integration tests should only take a few minutes to run on a modern developer machine.</p><p>It&#x27;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 <a href="https://github.com/facebook/react-native/tree/master/ReactAndroid/src/androidTest/java/com/facebook/react/tests" target="_blank"><code>ReactAndroid/src/androidTest</code></a>, so you can browse through that directory for good examples of tests.</p><h2><a class="anchor" name="ios"></a>iOS <a class="hash-link" href="docs/testing.html#ios">#</a></h2><h3><a class="anchor" name="integration-tests"></a>Integration Tests <a class="hash-link" href="docs/testing.html#integration-tests">#</a></h3><p>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 <code>RCTTestRunner</code> and <code>RCTTestModule</code>. <code>RCTTestRunner</code> sets up the ReactNative environment and provides facilities to run the tests as <code>XCTestCase</code>s in Xcode (<code>runTest:module</code> is the simplest method). <code>RCTTestModule</code> is exported to JS as <code>NativeModules.TestModule</code>. </p><p>The tests themselves are written in JS, and must call <code>TestModule.markTestCompleted()</code> 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 with <code>runTest:module:initialProps:expectErrorRegex:</code> or <code>runTest:module:initialProps:expectErrorBlock:</code> which will expect an error to be thrown and verify the error matches the provided criteria. </p><p>See the following for example usage and integration points:</p><ul><li><a href="https://github.com/facebook/react-native/blob/master/IntegrationTests/IntegrationTestHarnessTest.js" target="_blank"><code>IntegrationTestHarnessTest.js</code></a></li><li><a href="https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/UIExplorerIntegrationTests/UIExplorerIntegrationTests.m" target="_blank"><code>UIExplorerIntegrationTests.m</code></a></li><li><a href="https://github.com/facebook/react-native/blob/master/IntegrationTests/IntegrationTestsApp.js" target="_blank"><code>IntegrationTestsApp.js</code></a></li></ul><p>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:</p><div class="prism language-javascript">$ cd react<span class="token operator">-</span>native
$ <span class="token punctuation">.</span><span class="token operator">/</span>scripts<span class="token operator">/</span>objc<span class="token operator">-</span>test<span class="token operator">-</span>ios<span class="token punctuation">.</span>sh</div><blockquote><p>Your 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 <code>XCODE_DESTINATION</code> param in the test script.</p></blockquote><h3><a class="anchor" name="screenshot-snapshot-tests"></a>Screenshot/Snapshot Tests <a class="hash-link" href="docs/testing.html#screenshot-snapshot-tests">#</a></h3><p>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 <code>TestModule.verifySnapshot()</code>, using the <a href="https://github.com/facebook/ios-snapshot-test-case" target="_blank"><code>FBSnapshotTestCase</code></a> library behind the scenes. Reference images are recorded by setting <code>recordMode = YES</code> on the <code>RCTTestRunner</code>, then running the tests. Snapshots will differ slightly between 32 and 64 bit, and various OS versions, so it&#x27;s recommended that you enforce tests are run with the correct configuration. It&#x27;s also highly recommended that all network data be mocked out, along with other potentially troublesome dependencies. See <a href="https://github.com/facebook/react-native/blob/master/IntegrationTests/SimpleSnapshotTest.js" target="_blank"><code>SimpleSnapshotTest</code></a> for a basic example.</p><p>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&#x27;ll need to re-record the snapshot reference image. To do this, simply change to <code>_runner.recordMode = YES;</code> in <a href="https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/UIExplorerIntegrationTests/UIExplorerSnapshotTests.m#L42" target="_blank">UIExplorer/UIExplorerSnapshotTests.m</a>, re-run the failing tests, then flip record back to <code>NO</code> and submit/update your PR and wait to see if the Travis build passes.</p><h2><a class="anchor" name="end-to-end-tests"></a>End-to-end tests <a class="hash-link" href="docs/testing.html#end-to-end-tests">#</a></h2><p>Finally, make sure end-to-end tests run successfully by executing the following script:</p><div class="prism language-javascript">$ cd react<span class="token operator">-</span>native
$ <span class="token punctuation">.</span><span class="token operator">/</span>scripts<span class="token operator">/</span>objc<span class="token operator">-</span>test<span class="token operator">-</span>ios<span class="token punctuation">.</span>sh test</div><blockquote><p>Your 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 <code>XCODE_DESTINATION</code> param in the test script.</p></blockquote><h3><a class="anchor" name="screenshot-snapshot-tests"></a>Screenshot/Snapshot Tests <a class="hash-link" href="docs/testing.html#screenshot-snapshot-tests">#</a></h3><p>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 <code>TestModule.verifySnapshot()</code>, using the <a href="https://github.com/facebook/ios-snapshot-test-case" target="_blank"><code>FBSnapshotTestCase</code></a> library behind the scenes. Reference images are recorded by setting <code>recordMode = YES</code> on the <code>RCTTestRunner</code>, then running the tests. Snapshots will differ slightly between 32 and 64 bit, and various OS versions, so it&#x27;s recommended that you enforce tests are run with the correct configuration. It&#x27;s also highly recommended that all network data be mocked out, along with other potentially troublesome dependencies. See <a href="https://github.com/facebook/react-native/blob/master/IntegrationTests/SimpleSnapshotTest.js" target="_blank"><code>SimpleSnapshotTest</code></a> for a basic example.</p><p>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&#x27;ll need to re-record the snapshot reference image. To do this, simply change to <code>_runner.recordMode = YES;</code> in <a href="https://github.com/facebook/react-native/blob/master/Examples/UIExplorer/UIExplorerIntegrationTests/UIExplorerSnapshotTests.m#L42" target="_blank">UIExplorer/UIExplorerSnapshotTests.m</a>, re-run the failing tests, then flip record back to <code>NO</code> and submit/update your PR and wait to see if the Travis build passes.</p><h2><a class="anchor" name="end-to-end-tests"></a>End-to-end tests <a class="hash-link" href="docs/testing.html#end-to-end-tests">#</a></h2><p>Finally, make sure end-to-end tests run successfully by executing the following script:</p><div class="prism language-javascript">$ cd react<span class="token operator">-</span>native
$ <span class="token punctuation">.</span><span class="token operator">/</span>scripts<span class="token operator">/</span>test<span class="token operator">-</span>manual<span class="token operator">-</span>e2e<span class="token punctuation">.</span>sh</div><h2><a class="anchor" name="website"></a>Website <a class="hash-link" href="docs/testing.html#website">#</a></h2><p>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&#x27;s always a good idea to check that the website is generated properly whenever you edit the docs.</p><div class="prism language-javascript">$ cd website
$ npm install
$ npm start</div><p>Then open <a href="http://localhost:8079/react-native/index.html">http://localhost:8079/react-native/index.html</a> in your browser.</p></div><div class="docs-prevnext"><a class="docs-prev" href="docs/gesture-responder-system.html#content">← Prev</a><a class="docs-next" href="docs/understanding-cli.html#content">Next →</a></div><p class="edit-page-block">You can <a target="_blank" href="https://github.com/facebook/react-native/blob/master/docs/Testing.md">edit the content above on GitHub</a> and send us a pull request!</p></div></section><footer class="nav-footer"><section class="sitemap"><a href="/react-native" class="nav-home"><img src="img/header_logo.png" alt="React Native" width="66" height="58"></a><div><h5><a href="docs/">Docs</a></h5><a href="docs/getting-started.html">Getting Started</a><a href="docs/tutorial.html">Tutorial</a><a href="docs/integration-with-existing-apps.html">Integration With Existing Apps</a><a href="docs/more-resources.html">More Resources</a></div><div><h5><a href="/react-native/support.html">Community</a></h5><a href="/react-native/showcase.html">Showcase</a><a href="http://www.meetup.com/topics/react-native/" target="_blank">Upcoming Events</a><a href="https://www.facebook.com/groups/react.native.community" target="_blank">Facebook Group</a><a href="https://twitter.com/reactnative" target="_blank">Twitter</a></div><div><h5><a href="/react-native/support.html">Help</a></h5><a href="http://stackoverflow.com/questions/tagged/react-native" target="_blank">Stack Overflow</a><a href="https://discord.gg/0ZcbPKXt5bZjGY5n">Reactiflux Chat</a><a href="/react-native/versions.html" target="_blank">Latest Releases</a><a href="https://react-native.canny.io/feature-requests" target="_blank">Feature Requests</a></div><div><h5>More</h5><a href="/react-native/blog">Blog</a><a href="https://github.com/facebook/react-native" target="_blank">GitHub</a><a href="http://facebook.github.io/react/" target="_blank">React</a></div></section><section class="newsletter"><div id="mc_embed_signup"><form action="//reactnative.us10.list-manage.com/subscribe/post?u=db0dd948e2b729ee62625b1a8&amp;id=47cd41008f" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate><div id="mc_embed_signup_scroll"><label for="mce-EMAIL"><h5>Get the React Native Newsletter</h5></label><input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required><div style="position:absolute;left:-5000px;" aria-hidden="true"><input type="text" name="b_db0dd948e2b729ee62625b1a8_47cd41008f" tabindex="-1" value=""></div><div class="clear"><input type="submit" value="Sign up" name="subscribe" id="mc-embedded-subscribe" class="button"></div></div></form></div></section><a href="https://code.facebook.com/projects/" target="_blank" class="fbOpenSource"><img src="img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"></a><section class="copyright">Copyright © 2017 Facebook Inc.</section></footer></div><div id="fb-root"></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script><script>
+2 -2
View File
File diff suppressed because one or more lines are too long