2015-03-14 17:52:40 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
2015-11-18 16:25:30 +00:00
|
|
|
*
|
|
|
|
* @flow
|
2017-02-25 11:05:32 +00:00
|
|
|
* @providesModule IntegrationTestHarnessTest
|
2015-03-14 17:52:40 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-03-02 12:27:13 +00:00
|
|
|
var requestAnimationFrame = require('fbjs/lib/requestAnimationFrame');
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
2017-04-12 23:09:48 +00:00
|
|
|
var PropTypes = require('prop-types');
|
2016-04-09 03:36:40 +00:00
|
|
|
var ReactNative = require('react-native');
|
2015-03-14 17:52:40 +00:00
|
|
|
var {
|
|
|
|
Text,
|
|
|
|
View,
|
2016-04-09 03:36:40 +00:00
|
|
|
} = ReactNative;
|
|
|
|
var { TestModule } = ReactNative.NativeModules;
|
2015-03-14 17:52:40 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class IntegrationTestHarnessTest extends React.Component<{
|
|
|
|
shouldThrow?: boolean,
|
|
|
|
waitOneFrame?: boolean,
|
|
|
|
}, $FlowFixMeState> {
|
2016-07-26 08:00:02 +00:00
|
|
|
static propTypes = {
|
2017-04-12 23:09:48 +00:00
|
|
|
shouldThrow: PropTypes.bool,
|
|
|
|
waitOneFrame: PropTypes.bool,
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-14 17:52:40 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
done: false,
|
|
|
|
};
|
2015-03-14 17:52:40 +00:00
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
if (this.props.waitOneFrame) {
|
|
|
|
requestAnimationFrame(this.runTest);
|
|
|
|
} else {
|
|
|
|
this.runTest();
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-14 17:52:40 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
runTest = () => {
|
2015-03-14 17:52:40 +00:00
|
|
|
if (this.props.shouldThrow) {
|
|
|
|
throw new Error('Throwing error because shouldThrow');
|
|
|
|
}
|
2015-11-18 16:25:30 +00:00
|
|
|
if (!TestModule) {
|
2015-03-14 17:52:40 +00:00
|
|
|
throw new Error('RCTTestModule is not registered.');
|
2015-11-18 16:25:30 +00:00
|
|
|
} else if (!TestModule.markTestCompleted) {
|
2015-03-14 17:52:40 +00:00
|
|
|
throw new Error('RCTTestModule.markTestCompleted not defined.');
|
|
|
|
}
|
2016-11-04 12:40:26 +00:00
|
|
|
this.setState({done: true}, () => {
|
|
|
|
TestModule.markTestCompleted();
|
|
|
|
});
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-14 17:52:40 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={{backgroundColor: 'white', padding: 40}}>
|
|
|
|
<Text>
|
|
|
|
{this.constructor.displayName + ': '}
|
|
|
|
{this.state.done ? 'Done' : 'Testing...'}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-14 17:52:40 +00:00
|
|
|
|
2015-06-24 02:12:51 +00:00
|
|
|
IntegrationTestHarnessTest.displayName = 'IntegrationTestHarnessTest';
|
|
|
|
|
2015-03-14 17:52:40 +00:00
|
|
|
module.exports = IntegrationTestHarnessTest;
|