From 97d695d61560699062e4c1c02a56278d136ebdbd Mon Sep 17 00:00:00 2001 From: blagoev Date: Thu, 14 Dec 2017 12:17:49 +0200 Subject: [PATCH] fix android test app build and the script for android tests address review comments --- .gitignore | 1 + .../ReactExample/components/items-screen.js | 2 +- examples/ReactExample/components/styles.js | 2 -- examples/ReactExample/components/todo-app.js | 4 +--- scripts/react-tests-android.js | 2 +- scripts/test.sh | 23 +++++++++++++------ tests/react-test-app/android/app/build.gradle | 4 ++-- .../realm/react/testapp/MainApplication.java | 2 +- tests/react-test-app/android/settings.gradle | 1 + tests/react-test-app/index.android.js | 15 +++++++++--- tests/react-test-app/index.ios.js | 4 ++-- 11 files changed, 38 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 779d6a36..742ae0ae 100644 --- a/.gitignore +++ b/.gitignore @@ -56,3 +56,4 @@ packager_out.txt build.log.* realm-object-server/ tests/react-test-app/ios/out.txt +*.iml diff --git a/examples/ReactExample/components/items-screen.js b/examples/ReactExample/components/items-screen.js index 5d7abfc9..15bba8cb 100644 --- a/examples/ReactExample/components/items-screen.js +++ b/examples/ReactExample/components/items-screen.js @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////// // -// Copyright 2016 Realm Inc. +// Copyright 2017 Realm Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/examples/ReactExample/components/styles.js b/examples/ReactExample/components/styles.js index 32f8f00b..25a9eecf 100644 --- a/examples/ReactExample/components/styles.js +++ b/examples/ReactExample/components/styles.js @@ -22,9 +22,7 @@ import { Platform, StyleSheet } from 'react-native'; -// import NavigationExperimental from 'react-native-deprecated-custom-components'; -// const { NavBarHeight, TotalNavHeight } = NavigationExperimental.Navigator.NavigationBar.Styles.General; const iOS = (Platform.OS == 'ios'); diff --git a/examples/ReactExample/components/todo-app.js b/examples/ReactExample/components/todo-app.js index cd8b4bd6..30cb5dd5 100644 --- a/examples/ReactExample/components/todo-app.js +++ b/examples/ReactExample/components/todo-app.js @@ -35,7 +35,6 @@ import ItemsScreen from './items-screen' import realm from './realm'; import styles from './styles'; -// import NavigationExperimental from 'react-native-deprecated-custom-components'; import { StackNavigator } from 'react-navigation'; import RNExitApp from 'react-native-exit-app-no-history'; @@ -59,7 +58,7 @@ class HomeScreen extends React.Component { this.todoLists.addListener((name, changes) => { console.log("changed: " + JSON.stringify(changes)); if (params) { - console.error("params.json indicate a test run. Exiting application"); + console.error("params.json indicates a test run. Exiting application"); RNExitApp.exitApp(); } }); @@ -67,7 +66,6 @@ class HomeScreen extends React.Component { // Bind all the methods that we will be passing as props. - // this.renderScene = this.renderScene.bind(this); this._addNewTodoList = this._addNewTodoList.bind(this); this._onPressTodoList = this._onPressTodoList.bind(this); diff --git a/scripts/react-tests-android.js b/scripts/react-tests-android.js index 798619d0..124d5e1e 100644 --- a/scripts/react-tests-android.js +++ b/scripts/react-tests-android.js @@ -64,6 +64,6 @@ shell.exec("adb shell am start -n io.realm.react.testapp/.MainActivity"); shell.popd(); -shell.exec("adb shell \"logcat -c && logcat | grep -m 1 __REALM_REACT_ANDROID_TESTS_COMPLETED__\""); +shell.exec("adb shell \"logcat -c && logcat | grep -m 1 __REALM_JS_TESTS_COMPLETED__\""); shell.exec("adb pull /sdcard/tests.xml"); \ No newline at end of file diff --git a/scripts/test.sh b/scripts/test.sh index df92e5fc..59c871b3 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -66,7 +66,7 @@ stop_server() { echo stopping server if [[ ${SERVER_PID} -gt 0 ]] ; then echo server is running. killing it - kill -9 ${SERVER_PID} || true + kill -9 ${SERVER_PID} >/dev/null 2>&1 || true fi } @@ -104,7 +104,7 @@ cleanup() { open_chrome() { if [ $CONFIGURATION == 'Release' ]; then - break + return; fi local dir @@ -152,6 +152,10 @@ xctest() { echo "Shuttting down ${SIM_DEVICE_NAME} simulator. (device is not deleted. you can use it to debug the app)" shutdown_ios_simulator + check_test_results $1 +} + +check_test_results() { echo "Checking tests results" if grep -q "REALM_FAILING_TESTS" $(pwd)/build/out.txt; then echo "*** REALM JS TESTS FAILED. See tests results above ***" @@ -167,7 +171,7 @@ setup_ios_simulator() { delete_ios_simulator >/dev/null 2>&1 #parse devices - IOS_RUNTIME=$(xcrun simctl list runtimes | grep -m1 -o '(com.apple.CoreSimulator.SimRuntime.iOS.*)' | sed 's/[()]//g') + IOS_RUNTIME=$(xcrun simctl list runtimes | grep -m1 -o 'com.apple.CoreSimulator.SimRuntime.iOS.*' | sed 's/[()]//g') echo using iOS Runtime ${IOS_RUNTIME} to create new simulator ${SIM_DEVICE_NAME} #create new test simulator @@ -271,21 +275,25 @@ case "$TARGET" in [[ $CONFIGURATION == 'Debug' ]] && exit 0 XCPRETTY='' - pushd tests/react-test-app + pushd react-native/android + $(pwd)/gradlew publishAndroid + popd + pushd tests/react-test-app npm install echo "Resetting logcat" # Despite the docs claiming -c to work, it doesn't, so `-T 1` alleviates that. + mkdir -p $(pwd)/build || true adb logcat -c - adb logcat -T 1 | tee "$LOGCAT_OUT" & + adb logcat -T 1 | tee "$LOGCAT_OUT" | tee $(pwd)/build/out.txt & ./run-android.sh echo "Start listening for Test completion" while :; do - if grep -q "__REALM_REACT_ANDROID_TESTS_COMPLETED__" "$LOGCAT_OUT"; then + if grep -q "__REALM_JS_TESTS_COMPLETED__" "$LOGCAT_OUT"; then break else echo "Waiting for tests." @@ -301,7 +309,8 @@ case "$TARGET" in echo "********* TESTS COMPLETED *********"; echo "********* File location: $(pwd)/tests.xml *********"; cat tests.xml - + + check_test_results ReactTests ;; "node") npm run check-environment diff --git a/tests/react-test-app/android/app/build.gradle b/tests/react-test-app/android/app/build.gradle index bec27402..02f202a0 100644 --- a/tests/react-test-app/android/app/build.gradle +++ b/tests/react-test-app/android/app/build.gradle @@ -137,13 +137,13 @@ android { } dependencies { - compile project(':react-native-exception-handler') - compile project(':react-native-exit-app-no-history') compile fileTree(dir: "libs", include: ["*.jar"]) compile "com.android.support:appcompat-v7:23.0.1" compile "com.facebook.react:react-native:+" // From node_modules compile project(":realm") compile project(":react-native-fs") + compile project(':react-native-exception-handler') + compile project(':react-native-exit-app-no-history') } // Run this once to be able to run the application with BUCK diff --git a/tests/react-test-app/android/app/src/main/java/io/realm/react/testapp/MainApplication.java b/tests/react-test-app/android/app/src/main/java/io/realm/react/testapp/MainApplication.java index 977b654f..5e7a2ca2 100644 --- a/tests/react-test-app/android/app/src/main/java/io/realm/react/testapp/MainApplication.java +++ b/tests/react-test-app/android/app/src/main/java/io/realm/react/testapp/MainApplication.java @@ -22,7 +22,7 @@ public class MainApplication extends Application implements ReactApplication { private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override - protected boolean getUseDeveloperSupport() { + public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } diff --git a/tests/react-test-app/android/settings.gradle b/tests/react-test-app/android/settings.gradle index 98eee976..9c5c13ed 100644 --- a/tests/react-test-app/android/settings.gradle +++ b/tests/react-test-app/android/settings.gradle @@ -10,5 +10,6 @@ project(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/ include ':react-native-exception-handler' project(':react-native-exception-handler').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exception-handler/android') + include ':react-native-exit-app-no-history' project(':react-native-exit-app-no-history').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-exit-app-no-history/android') diff --git a/tests/react-test-app/index.android.js b/tests/react-test-app/index.android.js index 6e01d26b..3380a2f0 100644 --- a/tests/react-test-app/index.android.js +++ b/tests/react-test-app/index.android.js @@ -33,13 +33,13 @@ import { getTestNames, runTest } from './tests'; async function runTests() { let testNames = getTestNames(); let rootXml = builder.create('testsuites'); - + let failingTests = []; for (let suiteName in testNames) { let itemTestsuite = rootXml.ele('testsuite'); let nbrTests = 0; let nbrFailures = 0; - console.log('Starting ' + suiteName); + console.error('Starting ' + suiteName); for (let testName of testNames[suiteName]) { nbrTests++; @@ -51,6 +51,7 @@ async function runTests() { await runTest(suiteName, testName); } catch (e) { + failingTests.push(`${suiteName}: ${testName} : Error ${e.message}`); itemTest.ele('error', {'message': e.message, 'stacktrace': e.stack}, e.toString()); nbrFailures++; } @@ -73,11 +74,19 @@ async function runTests() { // write the unit tests reports try { await RNFS.writeFile('/sdcard/tests.xml', xmlString, 'utf8'); - console.log('__REALM_REACT_ANDROID_TESTS_COMPLETED__'); + console.log('__REALM_JS_TESTS_COMPLETED__'); + if (failingTests.length !== 0) { + console.error('\n\nREALM_FAILING_TESTS\n'); + console.error(failingTests); + } } catch (e) { console.error(e); } + finally { + console.warn("Realm Tests App finished. Exiting. Disable this to debug the app locally"); + RNExitApp.exitApp(); + } } class ReactTests extends React.Component { diff --git a/tests/react-test-app/index.ios.js b/tests/react-test-app/index.ios.js index f12ced2b..b7bc0e70 100644 --- a/tests/react-test-app/index.ios.js +++ b/tests/react-test-app/index.ios.js @@ -99,7 +99,7 @@ async function runTests() { //using console.log output is not shown in Release builds. using console.warn console.warn(xmlString); - console.warn('__REALM_REACT_IOS_TESTS_COMPLETED__'); + console.warn('__REALM_JS_TESTS_COMPLETED__'); if (failingTests.length !== 0) { console.error('\n\nREALM_FAILING_TESTS\n'); console.error(failingTests); @@ -109,7 +109,7 @@ async function runTests() { console.error(e); } finally { - console.warn("Realm iOS Tests App finished. Exiting. Disable this to debug the app locally"); + console.warn("Realm Tests App finished. Exiting. Disable this to debug the app locally"); RNExitApp.exitApp(); } }