2015-12-10 22:12:45 +00:00
|
|
|
/**
|
|
|
|
* Sample React Native App
|
|
|
|
* https://github.com/facebook/react-native
|
2015-11-24 06:14:50 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
var React = require('react-native');
|
|
|
|
var {
|
|
|
|
AppRegistry,
|
|
|
|
StyleSheet,
|
2016-01-22 18:05:34 +00:00
|
|
|
Image,
|
2015-11-24 06:14:50 +00:00
|
|
|
Text,
|
|
|
|
View,
|
2015-12-10 22:12:45 +00:00
|
|
|
TouchableNativeFeedback,
|
2015-11-24 06:14:50 +00:00
|
|
|
} = React;
|
|
|
|
|
2016-01-06 04:36:03 +00:00
|
|
|
var Realm = require('realm');
|
|
|
|
var RealmTests = require('realm-tests');
|
2016-01-22 18:05:34 +00:00
|
|
|
var builder = require('xmlbuilder');
|
|
|
|
var RNFS = require('react-native-fs');
|
2015-12-10 22:12:45 +00:00
|
|
|
|
2016-01-09 00:33:53 +00:00
|
|
|
function runTests() {
|
2016-01-22 18:05:34 +00:00
|
|
|
var rootXml = builder.create('testsuites');
|
2016-01-09 00:33:53 +00:00
|
|
|
let testNames = RealmTests.getTestNames();
|
|
|
|
|
|
|
|
for (let suiteName in testNames) {
|
2016-01-22 18:05:34 +00:00
|
|
|
var itemTestsuite = rootXml.ele('testsuite');
|
|
|
|
let nbrTests = 0;
|
|
|
|
let nbrFailures = 0;
|
|
|
|
|
2016-01-09 00:33:53 +00:00
|
|
|
let testSuite = RealmTests[suiteName];
|
|
|
|
|
2016-01-22 18:05:34 +00:00
|
|
|
console.log('Starting suite ' + suiteName);
|
2016-01-09 00:33:53 +00:00
|
|
|
|
|
|
|
var suiteTestNames = testNames[suiteName];
|
|
|
|
for (var index in suiteTestNames) {
|
2016-01-22 18:05:34 +00:00
|
|
|
nbrTests++;
|
2016-01-09 00:33:53 +00:00
|
|
|
var testName = suiteTestNames[index];
|
2016-01-22 18:05:34 +00:00
|
|
|
|
|
|
|
var itemTest = itemTestsuite.ele('testcase');
|
|
|
|
itemTest.att('name', testName);
|
|
|
|
|
2016-01-09 00:33:53 +00:00
|
|
|
console.log('Starting ' + testName);
|
|
|
|
|
|
|
|
if (testSuite.beforeEach) {
|
|
|
|
testSuite.beforeEach();
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
testSuite[testName]();
|
|
|
|
console.log('+ ' + testName);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
console.log('- ' + testName);
|
|
|
|
console.warn(e.message);
|
2016-01-22 18:05:34 +00:00
|
|
|
|
|
|
|
itemTest.ele('error', {'message': ''}, e.message);
|
|
|
|
nbrFailures++;
|
2016-01-09 00:33:53 +00:00
|
|
|
}
|
|
|
|
finally {
|
|
|
|
if (testSuite.afterEach) {
|
|
|
|
testSuite.afterEach();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-01-22 18:05:34 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2016-01-09 00:33:53 +00:00
|
|
|
}
|
2016-01-22 18:05:34 +00:00
|
|
|
// export unit tests results
|
|
|
|
var xmlString = rootXml.end({ pretty: true, indent: ' ', newline: '\n' });
|
2016-01-26 20:23:26 +00:00
|
|
|
var path = '/sdcard/tests.xml';
|
2016-01-22 18:05:34 +00:00
|
|
|
|
|
|
|
// write the unit tests reports
|
|
|
|
RNFS.writeFile(path, xmlString , 'utf8')
|
|
|
|
.then((success) => {
|
2016-01-26 20:23:26 +00:00
|
|
|
console.log('__REALM_REACT_ANDROID_TESTS_COMPLETED__');
|
2016-01-22 18:05:34 +00:00
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.log(err.message);
|
|
|
|
});
|
|
|
|
|
2016-01-09 00:33:53 +00:00
|
|
|
}
|
|
|
|
|
2016-02-11 01:03:16 +00:00
|
|
|
class ReactTests extends React.Component {
|
|
|
|
render() {
|
2015-12-10 22:12:45 +00:00
|
|
|
return (
|
2016-01-22 18:05:34 +00:00
|
|
|
<View style={styles.container}>
|
|
|
|
<Text style={styles.button} onPress={runTests}>
|
|
|
|
Running Tests...
|
|
|
|
</Text>
|
|
|
|
|
|
|
|
<Image
|
|
|
|
style={styles.icon}
|
|
|
|
source={require('image!ic_launcher')}
|
|
|
|
onLoad={() => runTests()}
|
|
|
|
/>
|
|
|
|
</View>
|
2015-12-10 22:12:45 +00:00
|
|
|
);
|
|
|
|
}
|
2016-02-11 01:03:16 +00:00
|
|
|
}
|
2015-11-24 06:14:50 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
2015-12-10 22:12:45 +00:00
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
backgroundColor: '#F5FCFF',
|
|
|
|
},
|
|
|
|
welcome: {
|
|
|
|
fontSize: 20,
|
|
|
|
textAlign: 'center',
|
|
|
|
margin: 10,
|
|
|
|
},
|
|
|
|
instructions: {
|
|
|
|
textAlign: 'center',
|
|
|
|
color: '#333333',
|
|
|
|
marginBottom: 5,
|
|
|
|
},
|
2015-11-24 06:14:50 +00:00
|
|
|
});
|
|
|
|
|
2016-02-11 01:03:16 +00:00
|
|
|
AppRegistry.registerComponent('ReactTests', () => ReactTests);
|