2015-03-14 17:52:40 +00:00
|
|
|
/**
|
2015-03-23 22:07:33 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2015-11-18 16:25:30 +00:00
|
|
|
*
|
2018-05-10 22:44:55 +00:00
|
|
|
* @format
|
2015-11-18 16:25:30 +00:00
|
|
|
* @flow
|
2015-03-14 17:52:40 +00:00
|
|
|
*/
|
2018-05-10 22:44:55 +00:00
|
|
|
|
2015-03-14 17:52:40 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
|
|
|
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
|
|
|
* run Flow. */
|
2018-05-14 07:09:36 +00:00
|
|
|
const requestAnimationFrame = require('fbjs/lib/requestAnimationFrame');
|
|
|
|
const React = require('react');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const ReactNative = require('react-native');
|
|
|
|
const {Text, View} = ReactNative;
|
|
|
|
const {TestModule} = ReactNative.NativeModules;
|
2015-03-14 17:52:40 +00:00
|
|
|
|
2018-05-10 22:44:55 +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>
|
2018-05-10 22:44:55 +00:00
|
|
|
{/* $FlowFixMe(>=0.54.0 site=react_native_fb,react_native_oss) This
|
2017-09-06 10:25:01 +00:00
|
|
|
* comment suppresses an error found when Flow v0.54 was deployed.
|
|
|
|
* To see the error delete this comment and run Flow. */
|
2018-05-10 22:44:55 +00:00
|
|
|
this.constructor.displayName + ': '}
|
2015-03-14 17:52:40 +00:00
|
|
|
{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;
|