diff --git a/tests/react-test-app/android/app/build.gradle b/tests/react-test-app/android/app/build.gradle index 2619a983..19f9b0b0 100644 --- a/tests/react-test-app/android/app/build.gradle +++ b/tests/react-test-app/android/app/build.gradle @@ -75,4 +75,5 @@ dependencies { compile 'com.android.support:appcompat-v7:23.0.1' compile 'com.facebook.react:react-native:0.18.0-patched' compile 'io.realm.react:realm-react-native:0.0.1-SNAPSHOT' + compile project(':react-native-fs') } diff --git a/tests/react-test-app/android/app/src/main/java/com/demo/MainActivity.java b/tests/react-test-app/android/app/src/main/java/com/demo/MainActivity.java index 749d9146..687a22ef 100644 --- a/tests/react-test-app/android/app/src/main/java/com/demo/MainActivity.java +++ b/tests/react-test-app/android/app/src/main/java/com/demo/MainActivity.java @@ -14,6 +14,7 @@ import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; import com.facebook.react.shell.MainReactPackage; import com.facebook.react.uimanager.ViewManager; +import com.rnfs.RNFSPackage; import java.util.ArrayList; import java.util.Collections; @@ -36,6 +37,7 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand .setBundleAssetName("index.android.bundle") .setJSMainModuleName("index.android") .addPackage(new MainReactPackage()) + .addPackage(new RNFSPackage()) .addPackage(new AnExampleReactPackage()) .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) diff --git a/tests/react-test-app/android/app/src/main/res/drawable-hdpi/ic_launcher.png b/tests/react-test-app/android/app/src/main/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 00000000..cde69bcc Binary files /dev/null and b/tests/react-test-app/android/app/src/main/res/drawable-hdpi/ic_launcher.png differ diff --git a/tests/react-test-app/android/settings.gradle b/tests/react-test-app/android/settings.gradle index 673b698c..f13c7f69 100644 --- a/tests/react-test-app/android/settings.gradle +++ b/tests/react-test-app/android/settings.gradle @@ -1,3 +1,5 @@ rootProject.name = 'Demo' include ':app' +include ':react-native-fs' +project(':react-native-fs').projectDir = new File(settingsDir, '../node_modules/react-native-fs/android') diff --git a/tests/react-test-app/index.android.js b/tests/react-test-app/index.android.js index f1ec3c14..58f6e224 100644 --- a/tests/react-test-app/index.android.js +++ b/tests/react-test-app/index.android.js @@ -8,6 +8,7 @@ var React = require('react-native'); var { AppRegistry, StyleSheet, + Image, Text, View, TouchableNativeFeedback, @@ -16,18 +17,33 @@ var { var RealmReactAndroid = require('NativeModules').RealmReactAndroid; var Realm = require('realm'); var RealmTests = require('realm-tests'); +var builder = require('xmlbuilder'); +var RNFS = require('react-native-fs'); function runTests() { + var rootXml = builder.create('testsuites'); + + let testNames = RealmTests.getTestNames(); + for (let suiteName in testNames) { + var itemTestsuite = rootXml.ele('testsuite'); + let nbrTests = 0; + let nbrFailures = 0; + let testSuite = RealmTests[suiteName]; - console.log('Starting ' + suiteName); + console.log('Starting suite ' + suiteName); var suiteTestNames = testNames[suiteName]; for (var index in suiteTestNames) { + nbrTests++; var testName = suiteTestNames[index]; + + var itemTest = itemTestsuite.ele('testcase'); + itemTest.att('name', testName); + console.log('Starting ' + testName); if (testSuite.beforeEach) { @@ -41,6 +57,9 @@ function runTests() { catch (e) { console.log('- ' + testName); console.warn(e.message); + + itemTest.ele('error', {'message': ''}, e.message); + nbrFailures++; } finally { if (testSuite.afterEach) { @@ -48,20 +67,46 @@ function runTests() { } } } + + // update Junit XML report + itemTestsuite.att('name', suiteName); + itemTestsuite.att('tests', nbrTests); + itemTestsuite.att('failures', nbrFailures); + itemTestsuite.att('timestamp', "2016-01-22T14:40:44.874443-05:00");//TODO use real timestamp + } + // export unit tests results + var xmlString = rootXml.end({ pretty: true, indent: ' ', newline: '\n' }); + var path = RNFS.DocumentDirectoryPath + '/tests.xml'; + + // write the unit tests reports + RNFS.writeFile(path, xmlString , 'utf8') + .then((success) => { + console.log('FILE WRITTEN!!'); + }) + .catch((err) => { + console.log(err.message); + }); + } var Demo = React.createClass({ render: function() { return ( - - - Tap to Run Tests - - + + + Running Tests... + + + runTests()} + /> + ); } -}); +}); var styles = StyleSheet.create({ container: { diff --git a/tests/react-test-app/package.json b/tests/react-test-app/package.json index a0a9159e..7161122b 100644 --- a/tests/react-test-app/package.json +++ b/tests/react-test-app/package.json @@ -7,6 +7,7 @@ }, "dependencies": { "react-native": "^0.18.0-rc", + "react-native-fs": "^1.1.0", "realm": "file:../..", "realm-tests": "file:../lib" } diff --git a/tests/react-test-app/run-android.sh b/tests/react-test-app/run-android.sh index 56ceafa4..882d966d 100755 --- a/tests/react-test-app/run-android.sh +++ b/tests/react-test-app/run-android.sh @@ -3,5 +3,4 @@ rm -rf node_modules/realm node_modules/realm-tests npm install realm realm-tests cp ../../src/object-store/parser/queryTests.json node_modules/realm-tests/query-tests.json adb forward tcp:8082 tcp:8082 -adb reverse tcp:8081 tcp:8081 react-native run-android