forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for out-of-tree platform support (facebook#20932)
Summary: This PR is a WIP for adding tests for out-of-tree platform support. [I originally had issues](facebook#20825 (comment)) 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: facebook#20932 Reviewed By: axe-fb Differential Revision: D9818112 Pulled By: hramos fbshipit-source-id: 0b53359b84430fdefb972587c95d19f85773c5fa
- Loading branch information
1 parent
d9643e2
commit f6d2074
Showing
5 changed files
with
1,293 additions
and
860 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,12 @@ RUN_IOS=0 | |
RUN_JS=0 | ||
|
||
RETRY_COUNT=${RETRY_COUNT:-2} | ||
AVD_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1) | ||
|
||
AVD_UUID=$(< /dev/urandom tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1) | ||
ANDROID_NPM_DEPS="[email protected] [email protected] [email protected] [email protected] [email protected]" | ||
CLI_PACKAGE=$ROOT/react-native-cli/react-native-cli-*.tgz | ||
PACKAGE=$ROOT/react-native-*.tgz | ||
CLI_PACKAGE="$ROOT/react-native-cli/react-native-cli-*.tgz" | ||
PACKAGE="$ROOT/react-native-*.tgz" | ||
# Version of react-native-dummy to test against | ||
[email protected] | ||
|
||
# solve issue with max user watches limit | ||
echo 65536 | tee -a /proc/sys/fs/inotify/max_user_watches | ||
|
@@ -27,7 +28,7 @@ watchman shutdown-server | |
# $2 -- command to run | ||
function retry() { | ||
local -r -i max_attempts="$1"; shift | ||
local -r cmd="$@" | ||
local -r cmd="$*" | ||
local -i attempt_num=1 | ||
|
||
until $cmd; do | ||
|
@@ -75,7 +76,7 @@ while :; do | |
done | ||
|
||
function e2e_suite() { | ||
cd $ROOT | ||
cd "$ROOT" | ||
|
||
if [ $RUN_ANDROID -eq 0 ] && [ $RUN_IOS -eq 0 ] && [ $RUN_JS -eq 0 ]; then | ||
echo "No e2e tests specified!" | ||
|
@@ -88,8 +89,8 @@ function e2e_suite() { | |
# To make sure we actually installed the local version | ||
# of react-native, we will create a temp file inside the template | ||
# and check that it exists after `react-native init | ||
IOS_MARKER=$(mktemp $ROOT/local-cli/templates/HelloWorld/ios/HelloWorld/XXXXXXXX) | ||
ANDROID_MARKER=$(mktemp ${ROOT}/local-cli/templates/HelloWorld/android/XXXXXXXX) | ||
IOS_MARKER="$(mktemp "$ROOT"/local-cli/templates/HelloWorld/ios/HelloWorld/XXXXXXXX)" | ||
ANDROID_MARKER="$(mktemp "$ROOT"/local-cli/templates/HelloWorld/android/XXXXXXXX)" | ||
|
||
# install CLI | ||
cd react-native-cli | ||
|
@@ -98,8 +99,8 @@ function e2e_suite() { | |
|
||
# can skip cli install for non sudo mode | ||
if [ $RUN_CLI_INSTALL -ne 0 ]; then | ||
npm install -g $CLI_PACKAGE | ||
if [ $? -ne 0 ]; then | ||
if ! npm install -g "$CLI_PACKAGE" | ||
then | ||
echo "Could not install react-native-cli globally, please run in su mode" | ||
echo "Or with --skip-cli-install to skip this step" | ||
return 1 | ||
|
@@ -111,7 +112,7 @@ function e2e_suite() { | |
|
||
# create virtual device | ||
if ! android list avd | grep "$AVD_UUID" > /dev/null; then | ||
echo no | android create avd -n $AVD_UUID -f -t android-19 --abi default/armeabi-v7a | ||
echo no | android create avd -n "$AVD_UUID" -f -t android-19 --abi default/armeabi-v7a | ||
fi | ||
|
||
# newline at end of adb devices call and first line is headers | ||
|
@@ -124,7 +125,7 @@ function e2e_suite() { | |
fi | ||
|
||
# emulator setup | ||
emulator64-arm -avd $AVD_UUID -no-skin -no-audio -no-window -no-boot-anim & | ||
emulator64-arm -avd "$AVD_UUID" -no-skin -no-audio -no-window -no-boot-anim & | ||
|
||
bootanim="" | ||
until [[ "$bootanim" =~ "stopped" ]]; do | ||
|
@@ -135,23 +136,23 @@ function e2e_suite() { | |
|
||
set -ex | ||
|
||
./gradlew :ReactAndroid:installArchives -Pjobs=1 -Dorg.gradle.jvmargs="-Xmx512m -XX:+HeapDumpOnOutOfMemoryError" | ||
if [ $? -ne 0 ]; then | ||
if ! ./gradlew :ReactAndroid:installArchives -Pjobs=1 -Dorg.gradle.jvmargs="-Xmx512m -XX:+HeapDumpOnOutOfMemoryError" | ||
then | ||
echo "Failed to compile Android binaries" | ||
return 1 | ||
fi | ||
fi | ||
|
||
npm pack | ||
if [ $? -ne 0 ]; then | ||
if ! npm pack | ||
then | ||
echo "Failed to pack react-native" | ||
return 1 | ||
fi | ||
|
||
cd $TEMP_DIR | ||
cd "$TEMP_DIR" | ||
|
||
retry $RETRY_COUNT react-native init EndToEndTest --version $PACKAGE --npm | ||
if [ $? -ne 0 ]; then | ||
if ! retry "$RETRY_COUNT" react-native init EndToEndTest --version "$PACKAGE" --npm | ||
then | ||
echo "Failed to execute react-native init" | ||
echo "Most common reason is npm registry connectivity, try again" | ||
return 1 | ||
|
@@ -164,20 +165,21 @@ function e2e_suite() { | |
echo "Running an Android e2e test" | ||
echo "Installing e2e framework" | ||
|
||
retry $RETRY_COUNT npm install --save-dev $ANDROID_NPM_DEPS --silent >> /dev/null | ||
if [ $? -ne 0 ]; then | ||
if ! retry "$RETRY_COUNT" npm install --save-dev "$ANDROID_NPM_DEPS" --silent >> /dev/null | ||
then | ||
echo "Failed to install appium" | ||
echo "Most common reason is npm registry connectivity, try again" | ||
return 1 | ||
fi | ||
|
||
cp $SCRIPTS/android-e2e-test.js android-e2e-test.js | ||
cp "$SCRIPTS/android-e2e-test.js" android-e2e-test.js | ||
|
||
cd android | ||
( | ||
cd android || exit | ||
echo "Downloading Maven deps" | ||
./gradlew :app:copyDownloadableDepsToLibs | ||
) | ||
|
||
cd .. | ||
keytool -genkey -v -keystore android/keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US" | ||
|
||
node ./node_modules/.bin/appium >> /dev/null & | ||
|
@@ -188,9 +190,8 @@ function e2e_suite() { | |
buck build android/app | ||
|
||
# hack to get node unhung (kill buckd) | ||
kill -9 $(pgrep java) | ||
|
||
if [ $? -ne 0 ]; then | ||
if ! kill -9 "$(pgrep java)" | ||
then | ||
echo "could not execute Buck build, is it installed and in PATH?" | ||
return 1 | ||
fi | ||
|
@@ -201,8 +202,8 @@ function e2e_suite() { | |
sleep 15 | ||
|
||
echo "Executing android e2e test" | ||
retry $RETRY_COUNT node node_modules/.bin/_mocha android-e2e-test.js | ||
if [ $? -ne 0 ]; then | ||
if ! retry "$RETRY_COUNT" node node_modules/.bin/_mocha android-e2e-test.js | ||
then | ||
echo "Failed to run Android e2e tests" | ||
echo "Most likely the code is broken" | ||
return 1 | ||
|
@@ -230,24 +231,37 @@ function e2e_suite() { | |
# js tests | ||
if [ $RUN_JS -ne 0 ]; then | ||
# Check the packager produces a bundle (doesn't throw an error) | ||
react-native bundle --max-workers 1 --platform android --dev true --entry-file index.js --bundle-output android-bundle.js | ||
if [ $? -ne 0 ]; then | ||
if ! react-native bundle --max-workers 1 --platform android --dev true --entry-file index.js --bundle-output android-bundle.js | ||
then | ||
echo "Could not build android bundle" | ||
return 1 | ||
fi | ||
|
||
react-native bundle --max-workers 1 --platform ios --dev true --entry-file index.js --bundle-output ios-bundle.js | ||
if [ $? -ne 0 ]; then | ||
if ! react-native bundle --max-workers 1 --platform ios --dev true --entry-file index.js --bundle-output ios-bundle.js | ||
then | ||
echo "Could not build iOS bundle" | ||
return 1 | ||
fi | ||
|
||
if ! retry "$RETRY_COUNT" npm install --save "$REACT_DUMMY_PLATFORM" --silent >> /dev/null | ||
then | ||
echo "Failed to install react-native-dummy" | ||
echo "Most common reason is npm registry connectivity, try again" | ||
return 1 | ||
fi | ||
|
||
if ! react-native bundle --max-workers 1 --platform dummy --dev true --entry-file index.js --bundle-output dummy-bundle.js | ||
then | ||
echo "Could not build dummy bundle" | ||
return 1 | ||
fi | ||
fi | ||
|
||
# directory cleanup | ||
rm $IOS_MARKER | ||
rm $ANDROID_MARKER | ||
rm "$IOS_MARKER" | ||
rm "$ANDROID_MARKER" | ||
|
||
return 0 | ||
} | ||
|
||
retry $RETRY_COUNT e2e_suite | ||
retry "$RETRY_COUNT" e2e_suite |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.