Skip to content

Commit f6d2074

Browse files
empyricalfacebook-github-bot
authored andcommitted
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
1 parent d9643e2 commit f6d2074

File tree

5 files changed

+1293
-860
lines changed

5 files changed

+1293
-860
lines changed

ContainerShip/scripts/run-ci-e2e-tests.sh

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ RUN_IOS=0
1212
RUN_JS=0
1313

1414
RETRY_COUNT=${RETRY_COUNT:-2}
15-
AVD_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)
16-
15+
AVD_UUID=$(< /dev/urandom tr -dc 'a-zA-Z0-9' | fold -w 8 | head -n 1)
1716
ANDROID_NPM_DEPS="appium@1.5.1 mocha@2.4.5 wd@0.3.11 colors@1.0.3 pretty-data2@0.40.1"
18-
CLI_PACKAGE=$ROOT/react-native-cli/react-native-cli-*.tgz
19-
PACKAGE=$ROOT/react-native-*.tgz
17+
CLI_PACKAGE="$ROOT/react-native-cli/react-native-cli-*.tgz"
18+
PACKAGE="$ROOT/react-native-*.tgz"
19+
# Version of react-native-dummy to test against
20+
REACT_DUMMY_PLATFORM=react-native-dummy@0.1.0
2021

2122
# solve issue with max user watches limit
2223
echo 65536 | tee -a /proc/sys/fs/inotify/max_user_watches
@@ -27,7 +28,7 @@ watchman shutdown-server
2728
# $2 -- command to run
2829
function retry() {
2930
local -r -i max_attempts="$1"; shift
30-
local -r cmd="$@"
31+
local -r cmd="$*"
3132
local -i attempt_num=1
3233

3334
until $cmd; do
@@ -75,7 +76,7 @@ while :; do
7576
done
7677

7778
function e2e_suite() {
78-
cd $ROOT
79+
cd "$ROOT"
7980

8081
if [ $RUN_ANDROID -eq 0 ] && [ $RUN_IOS -eq 0 ] && [ $RUN_JS -eq 0 ]; then
8182
echo "No e2e tests specified!"
@@ -88,8 +89,8 @@ function e2e_suite() {
8889
# To make sure we actually installed the local version
8990
# of react-native, we will create a temp file inside the template
9091
# and check that it exists after `react-native init
91-
IOS_MARKER=$(mktemp $ROOT/local-cli/templates/HelloWorld/ios/HelloWorld/XXXXXXXX)
92-
ANDROID_MARKER=$(mktemp ${ROOT}/local-cli/templates/HelloWorld/android/XXXXXXXX)
92+
IOS_MARKER="$(mktemp "$ROOT"/local-cli/templates/HelloWorld/ios/HelloWorld/XXXXXXXX)"
93+
ANDROID_MARKER="$(mktemp "$ROOT"/local-cli/templates/HelloWorld/android/XXXXXXXX)"
9394

9495
# install CLI
9596
cd react-native-cli
@@ -98,8 +99,8 @@ function e2e_suite() {
9899

99100
# can skip cli install for non sudo mode
100101
if [ $RUN_CLI_INSTALL -ne 0 ]; then
101-
npm install -g $CLI_PACKAGE
102-
if [ $? -ne 0 ]; then
102+
if ! npm install -g "$CLI_PACKAGE"
103+
then
103104
echo "Could not install react-native-cli globally, please run in su mode"
104105
echo "Or with --skip-cli-install to skip this step"
105106
return 1
@@ -111,7 +112,7 @@ function e2e_suite() {
111112

112113
# create virtual device
113114
if ! android list avd | grep "$AVD_UUID" > /dev/null; then
114-
echo no | android create avd -n $AVD_UUID -f -t android-19 --abi default/armeabi-v7a
115+
echo no | android create avd -n "$AVD_UUID" -f -t android-19 --abi default/armeabi-v7a
115116
fi
116117

117118
# newline at end of adb devices call and first line is headers
@@ -124,7 +125,7 @@ function e2e_suite() {
124125
fi
125126

126127
# emulator setup
127-
emulator64-arm -avd $AVD_UUID -no-skin -no-audio -no-window -no-boot-anim &
128+
emulator64-arm -avd "$AVD_UUID" -no-skin -no-audio -no-window -no-boot-anim &
128129

129130
bootanim=""
130131
until [[ "$bootanim" =~ "stopped" ]]; do
@@ -135,23 +136,23 @@ function e2e_suite() {
135136

136137
set -ex
137138

138-
./gradlew :ReactAndroid:installArchives -Pjobs=1 -Dorg.gradle.jvmargs="-Xmx512m -XX:+HeapDumpOnOutOfMemoryError"
139-
if [ $? -ne 0 ]; then
139+
if ! ./gradlew :ReactAndroid:installArchives -Pjobs=1 -Dorg.gradle.jvmargs="-Xmx512m -XX:+HeapDumpOnOutOfMemoryError"
140+
then
140141
echo "Failed to compile Android binaries"
141142
return 1
142143
fi
143144
fi
144145

145-
npm pack
146-
if [ $? -ne 0 ]; then
146+
if ! npm pack
147+
then
147148
echo "Failed to pack react-native"
148149
return 1
149150
fi
150151

151-
cd $TEMP_DIR
152+
cd "$TEMP_DIR"
152153

153-
retry $RETRY_COUNT react-native init EndToEndTest --version $PACKAGE --npm
154-
if [ $? -ne 0 ]; then
154+
if ! retry "$RETRY_COUNT" react-native init EndToEndTest --version "$PACKAGE" --npm
155+
then
155156
echo "Failed to execute react-native init"
156157
echo "Most common reason is npm registry connectivity, try again"
157158
return 1
@@ -164,20 +165,21 @@ function e2e_suite() {
164165
echo "Running an Android e2e test"
165166
echo "Installing e2e framework"
166167

167-
retry $RETRY_COUNT npm install --save-dev $ANDROID_NPM_DEPS --silent >> /dev/null
168-
if [ $? -ne 0 ]; then
168+
if ! retry "$RETRY_COUNT" npm install --save-dev "$ANDROID_NPM_DEPS" --silent >> /dev/null
169+
then
169170
echo "Failed to install appium"
170171
echo "Most common reason is npm registry connectivity, try again"
171172
return 1
172173
fi
173174

174-
cp $SCRIPTS/android-e2e-test.js android-e2e-test.js
175+
cp "$SCRIPTS/android-e2e-test.js" android-e2e-test.js
175176

176-
cd android
177+
(
178+
cd android || exit
177179
echo "Downloading Maven deps"
178180
./gradlew :app:copyDownloadableDepsToLibs
181+
)
179182

180-
cd ..
181183
keytool -genkey -v -keystore android/keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"
182184

183185
node ./node_modules/.bin/appium >> /dev/null &
@@ -188,9 +190,8 @@ function e2e_suite() {
188190
buck build android/app
189191

190192
# hack to get node unhung (kill buckd)
191-
kill -9 $(pgrep java)
192-
193-
if [ $? -ne 0 ]; then
193+
if ! kill -9 "$(pgrep java)"
194+
then
194195
echo "could not execute Buck build, is it installed and in PATH?"
195196
return 1
196197
fi
@@ -201,8 +202,8 @@ function e2e_suite() {
201202
sleep 15
202203

203204
echo "Executing android e2e test"
204-
retry $RETRY_COUNT node node_modules/.bin/_mocha android-e2e-test.js
205-
if [ $? -ne 0 ]; then
205+
if ! retry "$RETRY_COUNT" node node_modules/.bin/_mocha android-e2e-test.js
206+
then
206207
echo "Failed to run Android e2e tests"
207208
echo "Most likely the code is broken"
208209
return 1
@@ -230,24 +231,37 @@ function e2e_suite() {
230231
# js tests
231232
if [ $RUN_JS -ne 0 ]; then
232233
# Check the packager produces a bundle (doesn't throw an error)
233-
react-native bundle --max-workers 1 --platform android --dev true --entry-file index.js --bundle-output android-bundle.js
234-
if [ $? -ne 0 ]; then
234+
if ! react-native bundle --max-workers 1 --platform android --dev true --entry-file index.js --bundle-output android-bundle.js
235+
then
235236
echo "Could not build android bundle"
236237
return 1
237238
fi
238239

239-
react-native bundle --max-workers 1 --platform ios --dev true --entry-file index.js --bundle-output ios-bundle.js
240-
if [ $? -ne 0 ]; then
240+
if ! react-native bundle --max-workers 1 --platform ios --dev true --entry-file index.js --bundle-output ios-bundle.js
241+
then
241242
echo "Could not build iOS bundle"
242243
return 1
243244
fi
245+
246+
if ! retry "$RETRY_COUNT" npm install --save "$REACT_DUMMY_PLATFORM" --silent >> /dev/null
247+
then
248+
echo "Failed to install react-native-dummy"
249+
echo "Most common reason is npm registry connectivity, try again"
250+
return 1
251+
fi
252+
253+
if ! react-native bundle --max-workers 1 --platform dummy --dev true --entry-file index.js --bundle-output dummy-bundle.js
254+
then
255+
echo "Could not build dummy bundle"
256+
return 1
257+
fi
244258
fi
245259

246260
# directory cleanup
247-
rm $IOS_MARKER
248-
rm $ANDROID_MARKER
261+
rm "$IOS_MARKER"
262+
rm "$ANDROID_MARKER"
249263

250264
return 0
251265
}
252266

253-
retry $RETRY_COUNT e2e_suite
267+
retry "$RETRY_COUNT" e2e_suite

jest/__tests__/hasteImpl-test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,23 @@
1111
'use strict';
1212

1313
const path = require('path');
14+
const fs = require('fs');
1415

1516
const {getHasteName} = require('../hasteImpl');
1617

18+
// RNPM currently does not support plugins when using Yarn Plug 'n Play
19+
const testIfNotPnP = fs.existsSync(
20+
path.join(
21+
__dirname,
22+
'../..',
23+
'node_modules',
24+
'react-native-dummy',
25+
'package.json',
26+
),
27+
)
28+
? test
29+
: test.skip;
30+
1731
function getPath(...parts) {
1832
return path.join(__dirname, '..', '..', ...parts);
1933
}
@@ -46,6 +60,24 @@ it('returns the correct haste name for a file with a platform suffix', () => {
4660
}
4761
});
4862

63+
testIfNotPnP(
64+
'returns the correct haste name for a file with an out-of-tree platform suffix',
65+
() => {
66+
for (const platform of ['dummy']) {
67+
expect(
68+
getHasteName(
69+
getPath(
70+
'Libraries',
71+
'Components',
72+
'AccessibilityInfo',
73+
`AccessibilityInfo.${platform}.js`,
74+
),
75+
),
76+
).toEqual('AccessibilityInfo');
77+
}
78+
},
79+
);
80+
4981
it('returns the correct haste name for a file with a flow suffix', () => {
5082
expect(
5183
getHasteName(

jest/hasteImpl.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@
1313
const path = require('path');
1414
const findPlugins = require('../local-cli/core/findPlugins');
1515

16-
const plugins = findPlugins([path.resolve(__dirname, '../../../')]);
16+
const REACT_NATIVE_CI = process.cwd() === path.resolve(__dirname, '..');
17+
18+
let pluginsPath;
19+
20+
if (REACT_NATIVE_CI) {
21+
pluginsPath = '..';
22+
} else {
23+
pluginsPath = '../../../';
24+
}
25+
26+
const plugins = findPlugins([path.resolve(__dirname, pluginsPath)]);
1727

1828
// Detect out-of-tree platforms and add them to the whitelists
1929
const pluginRoots /*: Array<

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@
224224
"jest-junit": "5.1.0",
225225
"prettier": "1.13.6",
226226
"react": "16.5.0",
227+
"react-native-dummy": "0.1.0",
227228
"react-test-renderer": "16.5.0",
228229
"shelljs": "^0.7.8",
229230
"sinon": "^2.2.0"

0 commit comments

Comments
 (0)