vendredi 24 juin 2016

Integration Testing React-Native iOS unable to print (console.log)


So I'm currently following the format laid out by react native: (Complete side note: If you had a million hours to set up integration testing like I did let me help you out and use the code below and then all you have to do is edit the scheme and set a run argument. Check their UIExplorer application to find out what the argument was and what to set it to and stuff. You just have to set the main target. Also put IntegrationTesting.js and Tests.js in the root of the folder.) Back to the question: https://facebook.github.io/react-native/docs/testing.html And I have three main files. They are IntegrationTests.m, IntegrationTests.js, and Tests. IntegrationTests.m looks like this: #import <UIKit/UIKit.h> #import <XCTest/XCTest.h> #import <RCTTest/RCTTestRunner.h> #import "RCTAssert.h" #define RCT_TEST(name) - (void)test##name { [_runner runTest:_cmd module:@#name]; } @interface UIExplorerIntegrationTests : XCTestCase @end @implementation UIExplorerIntegrationTests { RCTTestRunner *_runner; } - (void)setUp { _runner = RCTInitRunnerForApp(@"IntegrationTests", nil); } #pragma mark - Test harness - (void)testTheTester_waitOneFrame { [_runner runTest:_cmd module:@"Tests" initialProps:@{@"waitOneFrame": @YES} configurationBlock:nil]; } #pragma mark - JS tests // This list should be kept in sync with IntegrationTestsApp.js RCT_TEST(Tests) @end IntegrationTests.js looks like this 'use strict'; var React = require('react'); var ReactNative = require('react-native'); var { AppRegistry, ScrollView, StyleSheet, Text, TouchableOpacity, View, } = ReactNative; var TESTS = [ require('./Tests'), ]; TESTS.forEach( (test) => AppRegistry.registerComponent(test.displayName, () => test) ); // Modules required for integration tests // require('LoggingTestModule'); type Test = any; var IntegrationTests = React.createClass({ getInitialState: function() { return { test: (null: ?Test), }; }, render: function() { if (this.state.test) { return ( <ScrollView> <this.state.test /> </ScrollView> ); } return ( <View style={styles.container}> <Text style={styles.row}> Click on a test to run it in this shell for easier debugging and development. Run all tests in the testing environment with cmd+U in Xcode. </Text> <View style={styles.separator} /> <ScrollView> {TESTS.map((test) => [ <TouchableOpacity onPress={() => this.setState({test})} style={styles.row}> <Text style={styles.testName}> {test.displayName} </Text> </TouchableOpacity>, <View style={styles.separator} /> ])} </ScrollView> </View> ); } }); var styles = StyleSheet.create({ container: { backgroundColor: 'white', marginTop: 40, margin: 15, }, row: { padding: 10, }, testName: { fontWeight: '500', }, separator: { height: 1, backgroundColor: '#bbbbbb', }, }); AppRegistry.registerComponent('IntegrationTests', () => IntegrationTests); Tests.js Looks like this: 'use strict'; var React = require('react'); var ReactNative = require('react-native'); var { Text, View, } = ReactNative; var { TestModule } = ReactNative.NativeModules; var Tests = React.createClass({ propTypes: { waitOneFrame: React.PropTypes.bool }, getInitialState() { return { done: false, }; }, componentDidMount() { console.log("I'll never see this print statement in the xcode console") this.runTest(); }, runTest() { async function SampleCall(){ try{ console.log("hey whatsup inside async!") }catch(e){ throw new Error("ERROR: " + e); console.log("download failed: " + e) } } SampleCall(); }, render() { return ( <View style={{backgroundColor: 'white', padding: 40}}> <Text> {this.constructor.displayName + ': '} {this.state.done ? 'Done' : 'Testing...'} </Text> </View> ); } }); Tests.displayName = 'Tests'; module.exports = Tests; For some reason I am unable to print using console.log. Whether I print inside an async function or not I am not able to print. I tried using the remote debugger method however this caused weird behavior. I was able to print but my tests would break and complain about this: Make sure Packager server is running. Make sure the JavaScript Debugger is running and not paused on a breakpoint or exception and try reloading again." And yes I tried setting localhost to my ip address and then the whole thing started freaking out more. NSString *URLString = [NSString stringWithFormat:@"http://MY.IPA.DDR.ESS:%zd/debugger-proxy?role=client", port]; failed: caught "NSInternalInconsistencyException", "RedBox error: Runtime is not ready for debugging. If you either know why my console.log statements are invisible in the xcode console upon running xctests in the format that react-native has set up their integration tests, or you know why I'm unable to set up the remote debugger, please help me out! Thanks

Aucun commentaire:

Enregistrer un commentaire