Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 50 additions & 36 deletions ContainerShip/scripts/run-ci-e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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!"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 &
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
15 changes: 15 additions & 0 deletions jest/__tests__/hasteImpl-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,21 @@ it('returns the correct haste name for a file with a platform suffix', () => {
}
});

it('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(
Expand Down
12 changes: 11 additions & 1 deletion jest/hasteImpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,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"
Expand Down