Skip to content

Commit cd17376

Browse files
authored
Merge branch 'master' into 9145-android-no-port-hardcode
2 parents 2549437 + ea8571b commit cd17376

File tree

386 files changed

+10408
-8516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

386 files changed

+10408
-8516
lines changed

.circleci/DockerTests.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Docker Test Environment
2+
3+
This is a high-level overview of the test configuration using Docker.
4+
It explains how to run the tests locally.
5+
6+
## Docker Installation
7+
8+
It is required to have Docker running on your machine in order to build and run the tests in the Dockerfiles.
9+
See <https://docs.docker.com/engine/installation/> for more information on how to install.
10+
11+
## Convenience Scripts
12+
13+
We have added a number of default run scripts to the `package.json` file to simplify building and running your tests.
14+
15+
### Configuring Docker Images
16+
17+
The following two scripts need to be run first before you can move on to testing:
18+
19+
- `yarn run docker-setup-android`: Pulls down the React Native Community Android image that serves as a base image when building the actual test image.
20+
21+
- `yarn run docker-build-android`: Builds a test image with the latest dependencies and React Native library code, including a compiled Android test app.
22+
23+
### Running Tests
24+
25+
Once the test image has been built, it can be used to run our Android tests.
26+
27+
- `yarn run test-android-run-unit` runs the unit tests, as defined in `scripts/run-android-docker-unit-tests.sh`.
28+
- `yarn run test-android-run-e2e` runs the end to end tests, as defined in `scripts/run-ci-e2e-tests.sh`.
29+
- `yarn run test-android-run-instrumentation` runs the instrumentation tests, as defined in `scripts/run-android-docker-instrumentation-tests.sh`.
30+
31+
#### Instrumentation Tests
32+
33+
The instrumentation test script accepts the following flags in order to customize the execution of the tests:
34+
35+
`--filter` - A regex that filters which instrumentation tests will be run. (Defaults to .*)
36+
37+
`--package` - Name of the java package containing the instrumentation tests (Defaults to com.facebook.react.tests)
38+
39+
`--path` - Path to the directory containing the instrumentation tests. (Defaults to ./ReactAndroid/src/androidTest/java/com/facebook/react/tests)
40+
41+
`--retries` - Number of times to retry a failed test before declaring a failure (Defaults to 2)
42+
43+
For example, if locally you only wanted to run the InitialPropsTestCase, you could do the following:
44+
`yarn run test-android-run-instrumentation -- --filter="InitialPropsTestCase"`
45+
46+
## Detailed Android Setup
47+
48+
There are two Dockerfiles for use with the Android codebase.
49+
The base image used to build `reactnativecommunity/react-native-android` is located in the https://github.com/react-native-community/docker-android GitHub repository.
50+
It contains all the necessary prerequisites required to run the React Android tests.
51+
It is separated out into a separate Dockerfile because these are dependencies that rarely change and also because it is quite a beastly image since it contains all the Android dependencies for running Android and the emulators (~9GB).
52+
53+
The good news is you should rarely have to build or pull down the base image!
54+
All iterative code updates happen as part of the `Dockerfile.android` image build.
55+
56+
Lets break it down...
57+
58+
First, you'll need to pull the base image.
59+
You can use `docker pull` to grab the latest version of the `reactnativecommunity/react-native-android` base image.
60+
This is what you get when you run `yarn run docker-setup-android`.
61+
62+
This will take quite some time depending on your connection and you need to ensure you have ~10GB of free disk space.
63+
64+
Once you have downloaded the base image, the test image can be built using `docker build -t reactnativeci/android -f ./.circleci/Dockerfiles/Dockerfile.android .`. This is what `yarn run docker-build-android` does. Note that the `-t` flag is how you tell Docker what to name this image locally. You can then use `docker run -t reactnativeci/android` to run this image.
65+
66+
Now that you've built the test image, you can run unit tests using what you've learned so far:
67+
68+
```bash
69+
docker run --cap-add=SYS_ADMIN -it reactnativeci/android bash .circleci/Dockerfiles/scripts/run-android-docker-unit-tests.sh
70+
```
71+
72+
> Note: `--cap-add=SYS_ADMIN` flag is required for the `.circleci/Dockerfiles/scripts/run-android-docker-unit-tests.sh` and `.circleci/Dockerfiles/scripts/run-android-docker-instrumentation-tests.sh` in order to allow the remounting of `/dev/shm` as writeable so the `buck` build system may write temporary output to that location.
73+
74+
Every time you make any modifications to the codebase, including changes to the test scripts inside `.circleci/Dockerfiles/scripts`, you should re-run the `docker build ...` command in order for your updates to be included in your local docker test image.
75+
76+
For rapid iteration, it's useful to keep in mind that Docker can pass along arbitrary commands to an image.
77+
For example, you can alternatively use Gradle in this manner:
78+
79+
```bash
80+
docker run --cap-add=SYS_ADMIN -it reactnativeci/android ./gradlew RNTester:android:app:assembleRelease
81+
```

ContainerShip/Dockerfile.android renamed to .circleci/Dockerfiles/Dockerfile.android

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,43 @@
22
#
33
# This source code is licensed under the MIT license found in the
44
# LICENSE file in the root directory of this source tree.
5-
6-
# React Native Android Unit Tests
75
#
8-
# This image builds upon the React Native Base Android Development Environment
9-
# image. Ideally, this image would be rebuilt with any new commit to the master
10-
# branch. Doing so will catch issues such as BUCK failing to fetch dependencies
11-
# or run tests, as well as unit test failures.
12-
FROM react-native-community/react-native
6+
# This image builds upon the React Native Community Android image:
7+
# https://github.com/react-native-community/docker-android
8+
#
9+
# The base image is expected to remain relatively stable, and only
10+
# needs to be updated when major dependencies such as the Android
11+
# SDK or NDK are updated.
12+
#
13+
# In this Android Test image, we download the latest dependencies
14+
# and build a Android application that can be used to run the
15+
# tests specified in the scripts/ directory.
16+
#
17+
FROM reactnativecommunity/react-native-android
1318

14-
LABEL Description="This image prepares and runs React Native's Android tests."
19+
LABEL Description="React Native Android Test Image"
1520
LABEL maintainer="Héctor Ramos <[email protected]>"
1621

1722
# set default environment variables
1823
ENV GRADLE_OPTS="-Dorg.gradle.daemon=false -Dorg.gradle.jvmargs=\"-Xmx512m -XX:+HeapDumpOnOutOfMemoryError\""
1924
ENV JAVA_TOOL_OPTIONS="-Dfile.encoding=UTF8"
2025

21-
# add ReactAndroid directory
2226
ADD .buckconfig /app/.buckconfig
2327
ADD .buckjavaargs /app/.buckjavaargs
28+
ADD tools /app/tools
2429
ADD ReactAndroid /app/ReactAndroid
2530
ADD ReactCommon /app/ReactCommon
26-
ADD ReactNative /app/ReactNative
31+
ADD React /app/React
2732
ADD keystores /app/keystores
2833

29-
# set workdir
3034
WORKDIR /app
3135

32-
# run buck fetches
3336
RUN buck fetch ReactAndroid/src/test/java/com/facebook/react/modules
3437
RUN buck fetch ReactAndroid/src/main/java/com/facebook/react
3538
RUN buck fetch ReactAndroid/src/main/java/com/facebook/react/shell
3639
RUN buck fetch ReactAndroid/src/test/...
3740
RUN buck fetch ReactAndroid/src/androidTest/...
3841

39-
# build app
4042
RUN buck build ReactAndroid/src/main/java/com/facebook/react
4143
RUN buck build ReactAndroid/src/main/java/com/facebook/react/shell
4244

@@ -46,22 +48,10 @@ ADD settings.gradle /app/settings.gradle
4648
ADD build.gradle /app/build.gradle
4749
ADD react.gradle /app/react.gradle
4850

49-
# run gradle downloads
5051
RUN ./gradlew :ReactAndroid:downloadBoost :ReactAndroid:downloadDoubleConversion :ReactAndroid:downloadFolly :ReactAndroid:downloadGlog :ReactAndroid:downloadJSC
5152

52-
# compile native libs with Gradle script, we need bridge for unit and integration tests
5353
RUN ./gradlew :ReactAndroid:packageReactNdkLibsForBuck -Pjobs=1
5454

55-
# add all react-native code
5655
ADD . /app
57-
WORKDIR /app
5856

59-
# build node dependencies
60-
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
61-
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
62-
RUN apt-get install apt-transport-https
63-
RUN apt-get update
64-
RUN apt-get install yarn
6557
RUN yarn
66-
67-
WORKDIR /app

ContainerShip/scripts/run-android-ci-instrumentation-tests.js renamed to .circleci/Dockerfiles/scripts/run-android-ci-instrumentation-tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ return async.mapSeries(testClasses, (clazz, callback) => {
8686
}
8787

8888
return async.retry(test_opts.RETRIES, (retryCb) => {
89-
const test_process = child_process.spawn('./ContainerShip/scripts/run-instrumentation-tests-via-adb-shell.sh', [test_opts.PACKAGE, clazz], {
89+
const test_process = child_process.spawn('./.circleci/Dockerfiles/scripts/run-instrumentation-tests-via-adb-shell.sh', [test_opts.PACKAGE, clazz], {
9090
stdio: 'inherit',
9191
});
9292

ContainerShip/scripts/run-android-docker-instrumentation-tests.sh renamed to .circleci/Dockerfiles/scripts/run-android-docker-instrumentation-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ node cli.js bundle --platform android --dev true --entry-file ReactAndroid/src/a
3838
source ./scripts/android-setup.sh && NO_BUCKD=1 retry3 buck install ReactAndroid/src/androidTest/buck-runner:instrumentation-tests --config build.threads=1
3939

4040
# run installed apk with tests
41-
node ./ContainerShip/scripts/run-android-ci-instrumentation-tests.js "$*"
41+
node ./.circleci/Dockerfiles/scripts/run-android-ci-instrumentation-tests.js "$*"
4242
exit $?

0 commit comments

Comments
 (0)