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
This commit is contained in:
empyrical
2018-09-27 13:08:00 -07:00
committed by Facebook Github Bot
parent 77e6c5e7cf
commit 57041ee44f
5 changed files with 1294 additions and 861 deletions

View File

@@ -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="appium@1.5.1 mocha@2.4.5 wd@0.3.11 colors@1.0.3 pretty-data2@0.40.1"
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
REACT_DUMMY_PLATFORM=react-native-dummy@0.1.0
# 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

View File

@@ -11,9 +11,23 @@
'use strict';
const path = require('path');
const fs = require('fs');
const {getHasteName} = require('../hasteImpl');
// RNPM currently does not support plugins when using Yarn Plug 'n Play
const testIfNotPnP = fs.existsSync(
path.join(
__dirname,
'../..',
'node_modules',
'react-native-dummy',
'package.json',
),
)
? test
: test.skip;
function getPath(...parts) {
return path.join(__dirname, '..', '..', ...parts);
}
@@ -46,6 +60,24 @@ it('returns the correct haste name for a file with a platform suffix', () => {
}
});
testIfNotPnP(
'returns the correct haste name for a file with an out-of-tree platform suffix',
() => {
for (const platform of ['dummy']) {
expect(
getHasteName(
getPath(
'Libraries',
'Components',
'AccessibilityInfo',
`AccessibilityInfo.${platform}.js`,
),
),
).toEqual('AccessibilityInfo');
}
},
);
it('returns the correct haste name for a file with a flow suffix', () => {
expect(
getHasteName(

View File

@@ -13,7 +13,17 @@
const path = require('path');
const findPlugins = require('../local-cli/core/findPlugins');
const plugins = findPlugins([path.resolve(__dirname, '../../../')]);
const REACT_NATIVE_CI = process.cwd() === path.resolve(__dirname, '..');
let pluginsPath;
if (REACT_NATIVE_CI) {
pluginsPath = '..';
} else {
pluginsPath = '../../../';
}
const plugins = findPlugins([path.resolve(__dirname, pluginsPath)]);
// Detect out-of-tree platforms and add them to the whitelists
const pluginRoots /*: Array<

View File

@@ -224,6 +224,7 @@
"jest-junit": "5.1.0",
"prettier": "1.13.6",
"react": "16.5.0",
"react-native-dummy": "0.1.0",
"react-test-renderer": "16.5.0",
"shelljs": "^0.7.8",
"sinon": "^2.2.0"

2024
yarn.lock

File diff suppressed because it is too large Load Diff