Prettier IntegrationTests
Reviewed By: sahrens Differential Revision: D7958195 fbshipit-source-id: 253c0eec593228e7b6bc66606584877161c6bfc2
This commit is contained in:
parent
86b6f5d39e
commit
dca21c8f23
|
@ -4,35 +4,33 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const React = require('react');
|
||||
const ReactNative = require('react-native');
|
||||
const { View } = ReactNative;
|
||||
const {View} = ReactNative;
|
||||
const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
||||
const {
|
||||
TestModule,
|
||||
AccessibilityManager,
|
||||
} = ReactNative.NativeModules;
|
||||
|
||||
const {TestModule, AccessibilityManager} = ReactNative.NativeModules;
|
||||
|
||||
class AccessibilityManagerTest extends React.Component<{}> {
|
||||
componentDidMount() {
|
||||
AccessibilityManager.setAccessibilityContentSizeMultipliers({
|
||||
'extraSmall': 1.0,
|
||||
'small': 2.0,
|
||||
'medium': 3.0,
|
||||
'large': 4.0,
|
||||
'extraLarge': 5.0,
|
||||
'extraExtraLarge': 6.0,
|
||||
'extraExtraExtraLarge': 7.0,
|
||||
'accessibilityMedium': 8.0,
|
||||
'accessibilityLarge': 9.0,
|
||||
'accessibilityExtraLarge': 10.0,
|
||||
'accessibilityExtraExtraLarge': 11.0,
|
||||
'accessibilityExtraExtraExtraLarge': 12.0,
|
||||
extraSmall: 1.0,
|
||||
small: 2.0,
|
||||
medium: 3.0,
|
||||
large: 4.0,
|
||||
extraLarge: 5.0,
|
||||
extraExtraLarge: 6.0,
|
||||
extraExtraExtraLarge: 7.0,
|
||||
accessibilityMedium: 8.0,
|
||||
accessibilityLarge: 9.0,
|
||||
accessibilityExtraLarge: 10.0,
|
||||
accessibilityExtraExtraLarge: 11.0,
|
||||
accessibilityExtraExtraExtraLarge: 12.0,
|
||||
});
|
||||
RCTDeviceEventEmitter.addListener('didUpdateDimensions', update => {
|
||||
TestModule.markTestPassed(update.window.fontScale === 4.0);
|
||||
|
|
|
@ -4,25 +4,22 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var ReactNative = require('react-native');
|
||||
var {
|
||||
NativeAppEventEmitter,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
} = ReactNative;
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {NativeAppEventEmitter, StyleSheet, Text, View} = ReactNative;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
var deepDiffer = require('deepDiffer');
|
||||
|
||||
var TEST_PAYLOAD = {foo: 'bar'};
|
||||
|
||||
type AppEvent = { data: Object, ts: number, };
|
||||
type AppEvent = {data: Object, ts: number};
|
||||
type State = {
|
||||
sent: 'none' | AppEvent,
|
||||
received: 'none' | AppEvent,
|
||||
|
@ -43,7 +40,7 @@ class AppEventsTest extends React.Component<{}, State> {
|
|||
if (deepDiffer(event.data, TEST_PAYLOAD)) {
|
||||
throw new Error('Received wrong event: ' + JSON.stringify(event));
|
||||
}
|
||||
var elapsed = (Date.now() - event.ts) + 'ms';
|
||||
var elapsed = Date.now() - event.ts + 'ms';
|
||||
this.setState({received: event, elapsed}, () => {
|
||||
TestModule.markTestCompleted();
|
||||
});
|
||||
|
@ -52,9 +49,7 @@ class AppEventsTest extends React.Component<{}, State> {
|
|||
render() {
|
||||
return (
|
||||
<View style={styles.container}>
|
||||
<Text>
|
||||
{JSON.stringify(this.state, null, ' ')}
|
||||
</Text>
|
||||
<Text>{JSON.stringify(this.state, null, ' ')}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -4,18 +4,16 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var ReactNative = require('react-native');
|
||||
var {
|
||||
AsyncStorage,
|
||||
Text,
|
||||
View,
|
||||
} = ReactNative;
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {AsyncStorage, Text, View} = ReactNative;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
var deepDiffer = require('deepDiffer');
|
||||
|
||||
|
@ -26,31 +24,34 @@ var VAL_1 = 'val_1';
|
|||
var KEY_2 = 'key_2';
|
||||
var VAL_2 = 'val_2';
|
||||
var KEY_MERGE = 'key_merge';
|
||||
var VAL_MERGE_1 = {'foo': 1, 'bar': {'hoo': 1, 'boo': 1}, 'moo': {'a': 3}};
|
||||
var VAL_MERGE_2 = {'bar': {'hoo': 2}, 'baz': 2, 'moo': {'a': 3}};
|
||||
var VAL_MERGE_EXPECT =
|
||||
{'foo': 1, 'bar': {'hoo': 2, 'boo': 1}, 'baz': 2, 'moo': {'a': 3}};
|
||||
var VAL_MERGE_1 = {foo: 1, bar: {hoo: 1, boo: 1}, moo: {a: 3}};
|
||||
var VAL_MERGE_2 = {bar: {hoo: 2}, baz: 2, moo: {a: 3}};
|
||||
var VAL_MERGE_EXPECT = {foo: 1, bar: {hoo: 2, boo: 1}, baz: 2, moo: {a: 3}};
|
||||
|
||||
// setup in componentDidMount
|
||||
var done = (result : ?boolean) => {};
|
||||
var updateMessage = (message : string ) => {};
|
||||
var done = (result: ?boolean) => {};
|
||||
var updateMessage = (message: string) => {};
|
||||
|
||||
function runTestCase(description : string, fn) {
|
||||
function runTestCase(description: string, fn) {
|
||||
updateMessage(description);
|
||||
fn();
|
||||
}
|
||||
|
||||
function expectTrue(condition : boolean, message : string) {
|
||||
function expectTrue(condition: boolean, message: string) {
|
||||
if (!condition) {
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
function expectEqual(lhs, rhs, testname : string) {
|
||||
function expectEqual(lhs, rhs, testname: string) {
|
||||
expectTrue(
|
||||
!deepDiffer(lhs, rhs),
|
||||
'Error in test ' + testname + ': expected\n' + JSON.stringify(rhs) +
|
||||
'\ngot\n' + JSON.stringify(lhs)
|
||||
'Error in test ' +
|
||||
testname +
|
||||
': expected\n' +
|
||||
JSON.stringify(rhs) +
|
||||
'\ngot\n' +
|
||||
JSON.stringify(lhs),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -58,11 +59,14 @@ function expectAsyncNoError(place, err) {
|
|||
if (err instanceof Error) {
|
||||
err = err.message;
|
||||
}
|
||||
expectTrue(err === null, 'Unexpected error in ' + place + ': ' + JSON.stringify(err));
|
||||
expectTrue(
|
||||
err === null,
|
||||
'Unexpected error in ' + place + ': ' + JSON.stringify(err),
|
||||
);
|
||||
}
|
||||
|
||||
function testSetAndGet() {
|
||||
AsyncStorage.setItem(KEY_1, VAL_1, (err1) => {
|
||||
AsyncStorage.setItem(KEY_1, VAL_1, err1 => {
|
||||
expectAsyncNoError('testSetAndGet/setItem', err1);
|
||||
AsyncStorage.getItem(KEY_1, (err2, result) => {
|
||||
expectAsyncNoError('testSetAndGet/getItem', err2);
|
||||
|
@ -83,8 +87,8 @@ function testMissingGet() {
|
|||
}
|
||||
|
||||
function testSetTwice() {
|
||||
AsyncStorage.setItem(KEY_1, VAL_1, ()=>{
|
||||
AsyncStorage.setItem(KEY_1, VAL_1, ()=>{
|
||||
AsyncStorage.setItem(KEY_1, VAL_1, () => {
|
||||
AsyncStorage.setItem(KEY_1, VAL_1, () => {
|
||||
AsyncStorage.getItem(KEY_1, (err, result) => {
|
||||
expectAsyncNoError('testSetTwice/setItem', err);
|
||||
expectEqual(result, VAL_1, 'testSetTwice');
|
||||
|
@ -96,16 +100,16 @@ function testSetTwice() {
|
|||
}
|
||||
|
||||
function testRemoveItem() {
|
||||
AsyncStorage.setItem(KEY_1, VAL_1, ()=>{
|
||||
AsyncStorage.setItem(KEY_2, VAL_2, ()=>{
|
||||
AsyncStorage.setItem(KEY_1, VAL_1, () => {
|
||||
AsyncStorage.setItem(KEY_2, VAL_2, () => {
|
||||
AsyncStorage.getAllKeys((err, result) => {
|
||||
expectAsyncNoError('testRemoveItem/getAllKeys', err);
|
||||
expectTrue(
|
||||
result.indexOf(KEY_1) >= 0 && result.indexOf(KEY_2) >= 0,
|
||||
'Missing KEY_1 or KEY_2 in ' + '(' + result + ')'
|
||||
'Missing KEY_1 or KEY_2 in ' + '(' + result + ')',
|
||||
);
|
||||
updateMessage('testRemoveItem - add two items');
|
||||
AsyncStorage.removeItem(KEY_1, (err2) => {
|
||||
AsyncStorage.removeItem(KEY_1, err2 => {
|
||||
expectAsyncNoError('testRemoveItem/removeItem', err2);
|
||||
updateMessage('delete successful ');
|
||||
AsyncStorage.getItem(KEY_1, (err3, result2) => {
|
||||
|
@ -113,17 +117,17 @@ function testRemoveItem() {
|
|||
expectEqual(
|
||||
result2,
|
||||
null,
|
||||
'testRemoveItem: key_1 present after delete'
|
||||
'testRemoveItem: key_1 present after delete',
|
||||
);
|
||||
updateMessage('key properly removed ');
|
||||
AsyncStorage.getAllKeys((err4, result3) => {
|
||||
expectAsyncNoError('testRemoveItem/getAllKeys', err4);
|
||||
expectTrue(
|
||||
result3.indexOf(KEY_1) === -1,
|
||||
'Unexpected: KEY_1 present in ' + result3
|
||||
);
|
||||
updateMessage('proper length returned.');
|
||||
runTestCase('should merge values', testMerge);
|
||||
expectAsyncNoError('testRemoveItem/getAllKeys', err4);
|
||||
expectTrue(
|
||||
result3.indexOf(KEY_1) === -1,
|
||||
'Unexpected: KEY_1 present in ' + result3,
|
||||
);
|
||||
updateMessage('proper length returned.');
|
||||
runTestCase('should merge values', testMerge);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -133,9 +137,9 @@ function testRemoveItem() {
|
|||
}
|
||||
|
||||
function testMerge() {
|
||||
AsyncStorage.setItem(KEY_MERGE, JSON.stringify(VAL_MERGE_1), (err1) => {
|
||||
AsyncStorage.setItem(KEY_MERGE, JSON.stringify(VAL_MERGE_1), err1 => {
|
||||
expectAsyncNoError('testMerge/setItem', err1);
|
||||
AsyncStorage.mergeItem(KEY_MERGE, JSON.stringify(VAL_MERGE_2), (err2) => {
|
||||
AsyncStorage.mergeItem(KEY_MERGE, JSON.stringify(VAL_MERGE_2), err2 => {
|
||||
expectAsyncNoError('testMerge/mergeItem', err2);
|
||||
AsyncStorage.getItem(KEY_MERGE, (err3, result) => {
|
||||
expectAsyncNoError('testMerge/setItem', err3);
|
||||
|
@ -150,21 +154,23 @@ function testMerge() {
|
|||
function testOptimizedMultiGet() {
|
||||
let batch = [[KEY_1, VAL_1], [KEY_2, VAL_2]];
|
||||
let keys = batch.map(([key, value]) => key);
|
||||
AsyncStorage.multiSet(batch, (err1) => {
|
||||
AsyncStorage.multiSet(batch, err1 => {
|
||||
// yes, twice on purpose
|
||||
[1, 2].forEach((i) => {
|
||||
[1, 2].forEach(i => {
|
||||
expectAsyncNoError(`${i} testOptimizedMultiGet/multiSet`, err1);
|
||||
AsyncStorage.multiGet(keys, (err2, result) => {
|
||||
expectAsyncNoError(`${i} testOptimizedMultiGet/multiGet`, err2);
|
||||
expectEqual(result, batch, `${i} testOptimizedMultiGet multiGet`);
|
||||
updateMessage('multiGet([key_1, key_2]) correctly returned ' + JSON.stringify(result));
|
||||
updateMessage(
|
||||
'multiGet([key_1, key_2]) correctly returned ' +
|
||||
JSON.stringify(result),
|
||||
);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
class AsyncStorageTest extends React.Component<{}, $FlowFixMeState> {
|
||||
state = {
|
||||
messages: 'Initializing...',
|
||||
|
@ -172,10 +178,11 @@ class AsyncStorageTest extends React.Component<{}, $FlowFixMeState> {
|
|||
};
|
||||
|
||||
componentDidMount() {
|
||||
done = () => this.setState({done: true}, () => {
|
||||
TestModule.markTestCompleted();
|
||||
});
|
||||
updateMessage = (msg) => {
|
||||
done = () =>
|
||||
this.setState({done: true}, () => {
|
||||
TestModule.markTestCompleted();
|
||||
});
|
||||
updateMessage = msg => {
|
||||
this.setState({messages: this.state.messages.concat('\n' + msg)});
|
||||
DEBUG && console.log(msg);
|
||||
};
|
||||
|
@ -186,11 +193,10 @@ class AsyncStorageTest extends React.Component<{}, $FlowFixMeState> {
|
|||
return (
|
||||
<View style={{backgroundColor: 'white', padding: 40}}>
|
||||
<Text>
|
||||
{
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_fb,react_native_oss) This
|
||||
{/* $FlowFixMe(>=0.54.0 site=react_native_fb,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. */
|
||||
this.constructor.displayName + ': '}
|
||||
this.constructor.displayName + ': '}
|
||||
{this.state.done ? 'Done' : 'Testing...'}
|
||||
{'\n\n' + this.state.messages}
|
||||
</Text>
|
||||
|
|
|
@ -4,19 +4,16 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var ReactNative = require('react-native');
|
||||
var {
|
||||
Image,
|
||||
View,
|
||||
Text,
|
||||
StyleSheet,
|
||||
} = ReactNative;
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {Image, View, Text, StyleSheet} = ReactNative;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
/*
|
||||
* The reload and force-cache tests don't actually verify that the complete functionality.
|
||||
|
@ -30,22 +27,25 @@ var { TestModule } = ReactNative.NativeModules;
|
|||
|
||||
const TESTS = ['only-if-cached', 'default', 'reload', 'force-cache'];
|
||||
|
||||
type Props = {}
|
||||
type Props = {};
|
||||
type State = {
|
||||
'only-if-cached'?: boolean,
|
||||
'default'?: boolean,
|
||||
'reload'?: boolean,
|
||||
default?: boolean,
|
||||
reload?: boolean,
|
||||
'force-cache'?: boolean,
|
||||
}
|
||||
};
|
||||
|
||||
class ImageCachePolicyTest extends React.Component<Props, $FlowFixMeState> {
|
||||
state = {}
|
||||
state = {};
|
||||
|
||||
shouldComponentUpdate(nextProps: Props, nextState: State) {
|
||||
const results: Array<?boolean> = TESTS.map(x => nextState[x]);
|
||||
|
||||
if (!results.includes(undefined)) {
|
||||
const result: boolean = results.reduce((x,y) => x === y === true, true);
|
||||
const result: boolean = results.reduce(
|
||||
(x, y) => (x === y) === true,
|
||||
true,
|
||||
);
|
||||
TestModule.markTestPassed(result);
|
||||
}
|
||||
|
||||
|
@ -60,38 +60,46 @@ class ImageCachePolicyTest extends React.Component<Props, $FlowFixMeState> {
|
|||
return (
|
||||
<View style={{flex: 1}}>
|
||||
<Text>Hello</Text>
|
||||
<Image
|
||||
source={{
|
||||
uri: 'https://facebook.github.io/react-native/img/favicon.png?cacheBust=notinCache' + Date.now(),
|
||||
cache: 'only-if-cached'
|
||||
}}
|
||||
onLoad={() => this.testComplete('only-if-cached', false)}
|
||||
onError={() => this.testComplete('only-if-cached', true)}
|
||||
style={styles.base}
|
||||
/>
|
||||
<Image
|
||||
source={{
|
||||
uri: 'https://facebook.github.io/react-native/img/favicon.png?cacheBust=notinCache' + Date.now(),
|
||||
cache: 'default'
|
||||
}}
|
||||
uri:
|
||||
'https://facebook.github.io/react-native/img/favicon.png?cacheBust=notinCache' +
|
||||
Date.now(),
|
||||
cache: 'only-if-cached',
|
||||
}}
|
||||
onLoad={() => this.testComplete('only-if-cached', false)}
|
||||
onError={() => this.testComplete('only-if-cached', true)}
|
||||
style={styles.base}
|
||||
/>
|
||||
<Image
|
||||
source={{
|
||||
uri:
|
||||
'https://facebook.github.io/react-native/img/favicon.png?cacheBust=notinCache' +
|
||||
Date.now(),
|
||||
cache: 'default',
|
||||
}}
|
||||
onLoad={() => this.testComplete('default', true)}
|
||||
onError={() => this.testComplete('default', false)}
|
||||
style={styles.base}
|
||||
/>
|
||||
<Image
|
||||
source={{
|
||||
uri: 'https://facebook.github.io/react-native/img/favicon.png?cacheBust=notinCache' + Date.now(),
|
||||
cache: 'reload'
|
||||
}}
|
||||
uri:
|
||||
'https://facebook.github.io/react-native/img/favicon.png?cacheBust=notinCache' +
|
||||
Date.now(),
|
||||
cache: 'reload',
|
||||
}}
|
||||
onLoad={() => this.testComplete('reload', true)}
|
||||
onError={() => this.testComplete('reload', false)}
|
||||
style={styles.base}
|
||||
/>
|
||||
<Image
|
||||
source={{
|
||||
uri: 'https://facebook.github.io/react-native/img/favicon.png?cacheBust=notinCache' + Date.now(),
|
||||
cache: 'force-cache'
|
||||
}}
|
||||
uri:
|
||||
'https://facebook.github.io/react-native/img/favicon.png?cacheBust=notinCache' +
|
||||
Date.now(),
|
||||
cache: 'force-cache',
|
||||
}}
|
||||
onLoad={() => this.testComplete('force-cache', true)}
|
||||
onError={() => this.testComplete('force-cache', false)}
|
||||
style={styles.base}
|
||||
|
|
|
@ -4,17 +4,16 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var ReactNative = require('react-native');
|
||||
var {
|
||||
Image,
|
||||
View,
|
||||
} = ReactNative;
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {Image, View} = ReactNative;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
class ImageSnapshotTest extends React.Component<{}> {
|
||||
componentDidMount() {
|
||||
|
@ -23,7 +22,7 @@ class ImageSnapshotTest extends React.Component<{}> {
|
|||
}
|
||||
}
|
||||
|
||||
done = (success : boolean) => {
|
||||
done = (success: boolean) => {
|
||||
TestModule.markTestPassed(success);
|
||||
};
|
||||
|
||||
|
@ -32,7 +31,8 @@ class ImageSnapshotTest extends React.Component<{}> {
|
|||
<Image
|
||||
source={require('./blue_square.png')}
|
||||
defaultSource={require('./red_square.png')}
|
||||
onLoad={() => TestModule.verifySnapshot(this.done)} />
|
||||
onLoad={() => TestModule.verifySnapshot(this.done)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
||||
|
@ -15,16 +17,16 @@ var requestAnimationFrame = require('fbjs/lib/requestAnimationFrame');
|
|||
var React = require('react');
|
||||
var PropTypes = require('prop-types');
|
||||
var ReactNative = require('react-native');
|
||||
var {
|
||||
Text,
|
||||
View,
|
||||
} = ReactNative;
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {Text, View} = ReactNative;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
class IntegrationTestHarnessTest extends React.Component<{
|
||||
shouldThrow?: boolean,
|
||||
waitOneFrame?: boolean,
|
||||
}, $FlowFixMeState> {
|
||||
class IntegrationTestHarnessTest extends React.Component<
|
||||
{
|
||||
shouldThrow?: boolean,
|
||||
waitOneFrame?: boolean,
|
||||
},
|
||||
$FlowFixMeState,
|
||||
> {
|
||||
static propTypes = {
|
||||
shouldThrow: PropTypes.bool,
|
||||
waitOneFrame: PropTypes.bool,
|
||||
|
@ -60,11 +62,10 @@ class IntegrationTestHarnessTest extends React.Component<{
|
|||
return (
|
||||
<View style={{backgroundColor: 'white', padding: 40}}>
|
||||
<Text>
|
||||
{
|
||||
/* $FlowFixMe(>=0.54.0 site=react_native_fb,react_native_oss) This
|
||||
{/* $FlowFixMe(>=0.54.0 site=react_native_fb,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. */
|
||||
this.constructor.displayName + ': '}
|
||||
this.constructor.displayName + ': '}
|
||||
{this.state.done ? 'Done' : 'Testing...'}
|
||||
</Text>
|
||||
</View>
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
|
@ -40,7 +42,7 @@ TESTS.forEach(
|
|||
/* $FlowFixMe(>=0.54.0 site=react_native_fb,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. */
|
||||
(test) => AppRegistry.registerComponent(test.displayName, () => test)
|
||||
test => AppRegistry.registerComponent(test.displayName, () => test),
|
||||
);
|
||||
|
||||
// Modules required for integration tests
|
||||
|
@ -68,20 +70,18 @@ class IntegrationTestsApp extends React.Component<{}, $FlowFixMeState> {
|
|||
<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
|
||||
development. Run all tests in the testing environment with cmd+U in
|
||||
Xcode.
|
||||
</Text>
|
||||
<View style={styles.separator} />
|
||||
<ScrollView>
|
||||
{TESTS.map((test) => [
|
||||
{TESTS.map(test => [
|
||||
<TouchableOpacity
|
||||
onPress={() => this.setState({test})}
|
||||
style={styles.row}>
|
||||
<Text style={styles.testName}>
|
||||
{test.displayName}
|
||||
</Text>
|
||||
<Text style={styles.testName}>{test.displayName}</Text>
|
||||
</TouchableOpacity>,
|
||||
<View style={styles.separator} />
|
||||
<View style={styles.separator} />,
|
||||
])}
|
||||
</ScrollView>
|
||||
</View>
|
||||
|
|
|
@ -4,21 +4,17 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var createReactClass = require('create-react-class');
|
||||
var ReactNative = require('react-native');
|
||||
var {
|
||||
Image,
|
||||
LayoutAnimation,
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
} = ReactNative;
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {Image, LayoutAnimation, StyleSheet, Text, View} = ReactNative;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
var deepDiffer = require('deepDiffer');
|
||||
|
||||
|
@ -55,27 +51,23 @@ var LayoutEventsTest = createReactClass({
|
|||
},
|
||||
animateViewLayout: function() {
|
||||
debug('animateViewLayout invoked');
|
||||
LayoutAnimation.configureNext(
|
||||
LayoutAnimation.Presets.spring,
|
||||
() => {
|
||||
debug('animateViewLayout done');
|
||||
this.checkLayout(this.addWrapText);
|
||||
}
|
||||
);
|
||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.spring, () => {
|
||||
debug('animateViewLayout done');
|
||||
this.checkLayout(this.addWrapText);
|
||||
});
|
||||
this.setState({viewStyle: {margin: 60}});
|
||||
},
|
||||
addWrapText: function() {
|
||||
debug('addWrapText invoked');
|
||||
this.setState(
|
||||
{extraText: ' And a bunch more text to wrap around a few lines.'},
|
||||
() => this.checkLayout(this.changeContainer)
|
||||
() => this.checkLayout(this.changeContainer),
|
||||
);
|
||||
},
|
||||
changeContainer: function() {
|
||||
debug('changeContainer invoked');
|
||||
this.setState(
|
||||
{containerStyle: {width: 280}},
|
||||
() => this.checkLayout(TestModule.markTestCompleted)
|
||||
this.setState({containerStyle: {width: 280}}, () =>
|
||||
this.checkLayout(TestModule.markTestCompleted),
|
||||
);
|
||||
},
|
||||
checkLayout: function(next?: ?Function) {
|
||||
|
@ -103,8 +95,9 @@ var LayoutEventsTest = createReactClass({
|
|||
if (deepDiffer(measured, onLayout)) {
|
||||
var data = {measured, onLayout};
|
||||
throw new Error(
|
||||
node + ' onLayout mismatch with measure ' +
|
||||
JSON.stringify(data, null, ' ')
|
||||
node +
|
||||
' onLayout mismatch with measure ' +
|
||||
JSON.stringify(data, null, ' '),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
@ -145,7 +138,7 @@ var LayoutEventsTest = createReactClass({
|
|||
</View>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
var styles = StyleSheet.create({
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var BatchedBridge = require('BatchedBridge');
|
||||
|
@ -16,7 +18,7 @@ var LoggingTestModule = {
|
|||
logToConsole: function(str) {
|
||||
console.log(str);
|
||||
},
|
||||
logToConsoleAfterWait: function(str,timeout_ms) {
|
||||
logToConsoleAfterWait: function(str, timeout_ms) {
|
||||
setTimeout(function() {
|
||||
console.log(str);
|
||||
}, timeout_ms);
|
||||
|
@ -32,12 +34,9 @@ var LoggingTestModule = {
|
|||
},
|
||||
throwError: function(str) {
|
||||
throw new Error(str);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
BatchedBridge.registerCallableModule(
|
||||
'LoggingTestModule',
|
||||
LoggingTestModule
|
||||
);
|
||||
BatchedBridge.registerCallableModule('LoggingTestModule', LoggingTestModule);
|
||||
|
||||
module.exports = LoggingTestModule;
|
||||
|
|
|
@ -4,14 +4,16 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var ReactNative = require('react-native');
|
||||
var { View } = ReactNative;
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {View} = ReactNative;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
class PromiseTest extends React.Component<{}> {
|
||||
shouldResolve = false;
|
||||
|
@ -25,24 +27,26 @@ class PromiseTest extends React.Component<{}> {
|
|||
this.testShouldReject(),
|
||||
this.testShouldSucceedAsync(),
|
||||
this.testShouldThrowAsync(),
|
||||
]).then(() => TestModule.markTestPassed(
|
||||
this.shouldResolve && this.shouldReject &&
|
||||
this.shouldSucceedAsync && this.shouldThrowAsync
|
||||
));
|
||||
]).then(() =>
|
||||
TestModule.markTestPassed(
|
||||
this.shouldResolve &&
|
||||
this.shouldReject &&
|
||||
this.shouldSucceedAsync &&
|
||||
this.shouldThrowAsync,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testShouldResolve = () => {
|
||||
return TestModule
|
||||
.shouldResolve()
|
||||
.then(() => this.shouldResolve = true)
|
||||
.catch(() => this.shouldResolve = false);
|
||||
return TestModule.shouldResolve()
|
||||
.then(() => (this.shouldResolve = true))
|
||||
.catch(() => (this.shouldResolve = false));
|
||||
};
|
||||
|
||||
testShouldReject = () => {
|
||||
return TestModule
|
||||
.shouldReject()
|
||||
.then(() => this.shouldReject = false)
|
||||
.catch(() => this.shouldReject = true);
|
||||
return TestModule.shouldReject()
|
||||
.then(() => (this.shouldReject = false))
|
||||
.catch(() => (this.shouldReject = true));
|
||||
};
|
||||
|
||||
testShouldSucceedAsync = async (): Promise<any> => {
|
||||
|
|
|
@ -3,25 +3,24 @@
|
|||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var ReactNative = require('react-native');
|
||||
var {
|
||||
View,
|
||||
} = ReactNative;
|
||||
var {View} = ReactNative;
|
||||
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
class PropertiesUpdateTest extends React.Component {
|
||||
render() {
|
||||
if (this.props.markTestPassed) {
|
||||
TestModule.markTestPassed(true);
|
||||
}
|
||||
return (
|
||||
<View/>
|
||||
);
|
||||
return <View />;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,9 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
require('regenerator-runtime/runtime');
|
||||
|
@ -28,8 +30,8 @@ var TESTS = [
|
|||
require('./SizeFlexibilityUpdateTest'),
|
||||
];
|
||||
|
||||
TESTS.forEach(
|
||||
(test) => AppRegistry.registerComponent(test.displayName, () => test)
|
||||
TESTS.forEach(test =>
|
||||
AppRegistry.registerComponent(test.displayName, () => test),
|
||||
);
|
||||
|
||||
class RCTRootViewIntegrationTestApp extends React.Component {
|
||||
|
@ -49,20 +51,18 @@ class RCTRootViewIntegrationTestApp extends React.Component {
|
|||
<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
|
||||
development. Run all tests in the testing environment with cmd+U in
|
||||
Xcode.
|
||||
</Text>
|
||||
<View style={styles.separator} />
|
||||
<ScrollView>
|
||||
{TESTS.map((test) => [
|
||||
{TESTS.map(test => [
|
||||
<TouchableOpacity
|
||||
onPress={() => this.setState({test})}
|
||||
style={styles.row}>
|
||||
<Text style={styles.testName}>
|
||||
{test.displayName}
|
||||
</Text>
|
||||
<Text style={styles.testName}>{test.displayName}</Text>
|
||||
</TouchableOpacity>,
|
||||
<View style={styles.separator} />
|
||||
<View style={styles.separator} />,
|
||||
])}
|
||||
</ScrollView>
|
||||
</View>
|
||||
|
@ -88,4 +88,7 @@ var styles = StyleSheet.create({
|
|||
},
|
||||
});
|
||||
|
||||
AppRegistry.registerComponent('RCTRootViewIntegrationTestApp', () => RCTRootViewIntegrationTestApp);
|
||||
AppRegistry.registerComponent(
|
||||
'RCTRootViewIntegrationTestApp',
|
||||
() => RCTRootViewIntegrationTestApp,
|
||||
);
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
|
@ -13,9 +16,9 @@ var RCTNativeAppEventEmitter = require('RCTNativeAppEventEmitter');
|
|||
var Subscribable = require('Subscribable');
|
||||
var TimerMixin = require('react-timer-mixin');
|
||||
|
||||
var { View } = ReactNative;
|
||||
var {View} = ReactNative;
|
||||
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
var reactViewWidth = 101;
|
||||
var reactViewHeight = 102;
|
||||
|
@ -24,14 +27,13 @@ var newReactViewHeight = 202;
|
|||
|
||||
var ReactContentSizeUpdateTest = createReactClass({
|
||||
displayName: 'ReactContentSizeUpdateTest',
|
||||
mixins: [Subscribable.Mixin,
|
||||
TimerMixin],
|
||||
mixins: [Subscribable.Mixin, TimerMixin],
|
||||
|
||||
UNSAFE_componentWillMount: function() {
|
||||
this.addListenerOn(
|
||||
RCTNativeAppEventEmitter,
|
||||
'rootViewDidChangeIntrinsicSize',
|
||||
this.rootViewDidChangeIntrinsicSize
|
||||
this.rootViewDidChangeIntrinsicSize,
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -50,23 +52,25 @@ var ReactContentSizeUpdateTest = createReactClass({
|
|||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
this.setTimeout(
|
||||
() => { this.updateViewSize(); },
|
||||
1000
|
||||
);
|
||||
this.setTimeout(() => {
|
||||
this.updateViewSize();
|
||||
}, 1000);
|
||||
},
|
||||
|
||||
rootViewDidChangeIntrinsicSize: function(intrinsicSize) {
|
||||
if (intrinsicSize.height === newReactViewHeight && intrinsicSize.width === newReactViewWidth) {
|
||||
if (
|
||||
intrinsicSize.height === newReactViewHeight &&
|
||||
intrinsicSize.width === newReactViewWidth
|
||||
) {
|
||||
TestModule.markTestPassed(true);
|
||||
}
|
||||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{'height':this.state.height, 'width':this.state.width}}/>
|
||||
<View style={{height: this.state.height, width: this.state.width}} />
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
ReactContentSizeUpdateTest.displayName = 'ReactContentSizeUpdateTest';
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
|
@ -15,11 +17,8 @@ var ReactNative = require('react-native');
|
|||
* run Flow. */
|
||||
var requestAnimationFrame = require('fbjs/lib/requestAnimationFrame');
|
||||
|
||||
var {
|
||||
StyleSheet,
|
||||
View,
|
||||
} = ReactNative;
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {StyleSheet, View} = ReactNative;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
class SimpleSnapshotTest extends React.Component<{}> {
|
||||
componentDidMount() {
|
||||
|
@ -29,7 +28,7 @@ class SimpleSnapshotTest extends React.Component<{}> {
|
|||
requestAnimationFrame(() => TestModule.verifySnapshot(this.done));
|
||||
}
|
||||
|
||||
done = (success : boolean) => {
|
||||
done = (success: boolean) => {
|
||||
TestModule.markTestPassed(success);
|
||||
};
|
||||
|
||||
|
|
|
@ -3,7 +3,10 @@
|
|||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
|
@ -11,9 +14,9 @@ var createReactClass = require('create-react-class');
|
|||
var ReactNative = require('react-native');
|
||||
var RCTNativeAppEventEmitter = require('RCTNativeAppEventEmitter');
|
||||
var Subscribable = require('Subscribable');
|
||||
var { View } = ReactNative;
|
||||
var {View} = ReactNative;
|
||||
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
var reactViewWidth = 111;
|
||||
var reactViewHeight = 222;
|
||||
|
@ -28,7 +31,7 @@ var SizeFlexibilityUpdateTest = createReactClass({
|
|||
this.addListenerOn(
|
||||
RCTNativeAppEventEmitter,
|
||||
'rootViewDidChangeIntrinsicSize',
|
||||
this.rootViewDidChangeIntrinsicSize
|
||||
this.rootViewDidChangeIntrinsicSize,
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -38,7 +41,6 @@ var SizeFlexibilityUpdateTest = createReactClass({
|
|||
},
|
||||
|
||||
rootViewDidChangeIntrinsicSize: function(intrinsicSize) {
|
||||
|
||||
if (finalState) {
|
||||
// If a test reaches its final state, it is not expected to do anything more
|
||||
TestModule.markTestPassed(false);
|
||||
|
@ -46,25 +48,37 @@ var SizeFlexibilityUpdateTest = createReactClass({
|
|||
}
|
||||
|
||||
if (this.props.both) {
|
||||
if (intrinsicSize.width === reactViewWidth && intrinsicSize.height === reactViewHeight) {
|
||||
if (
|
||||
intrinsicSize.width === reactViewWidth &&
|
||||
intrinsicSize.height === reactViewHeight
|
||||
) {
|
||||
this.markPassed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.props.height) {
|
||||
if (intrinsicSize.width !== reactViewWidth && intrinsicSize.height === reactViewHeight) {
|
||||
if (
|
||||
intrinsicSize.width !== reactViewWidth &&
|
||||
intrinsicSize.height === reactViewHeight
|
||||
) {
|
||||
this.markPassed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.props.width) {
|
||||
if (intrinsicSize.width === reactViewWidth && intrinsicSize.height !== reactViewHeight) {
|
||||
if (
|
||||
intrinsicSize.width === reactViewWidth &&
|
||||
intrinsicSize.height !== reactViewHeight
|
||||
) {
|
||||
this.markPassed();
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (this.props.none) {
|
||||
if (intrinsicSize.width !== reactViewWidth && intrinsicSize.height !== reactViewHeight) {
|
||||
if (
|
||||
intrinsicSize.width !== reactViewWidth &&
|
||||
intrinsicSize.height !== reactViewHeight
|
||||
) {
|
||||
this.markPassed();
|
||||
return;
|
||||
}
|
||||
|
@ -72,10 +86,8 @@ var SizeFlexibilityUpdateTest = createReactClass({
|
|||
},
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{'height':reactViewHeight, 'width':reactViewWidth}}/>
|
||||
);
|
||||
}
|
||||
return <View style={{height: reactViewHeight, width: reactViewWidth}} />;
|
||||
},
|
||||
});
|
||||
|
||||
SizeFlexibilityUpdateTest.displayName = 'SizeFlexibilityUpdateTest';
|
||||
|
|
|
@ -4,23 +4,23 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var ReactNative = require('react-native');
|
||||
var { View } = ReactNative;
|
||||
|
||||
const {
|
||||
TestModule,
|
||||
RNTesterTestModule,
|
||||
} = ReactNative.NativeModules;
|
||||
var {View} = ReactNative;
|
||||
|
||||
const {TestModule, RNTesterTestModule} = ReactNative.NativeModules;
|
||||
|
||||
class SyncMethodTest extends React.Component<{}> {
|
||||
componentDidMount() {
|
||||
if (RNTesterTestModule.echoString('test string value') !== 'test string value') {
|
||||
if (
|
||||
RNTesterTestModule.echoString('test string value') !== 'test string value'
|
||||
) {
|
||||
throw new Error('Something wrong with sync method export');
|
||||
}
|
||||
if (RNTesterTestModule.methodThatReturnsNil() != null) {
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
|
@ -16,12 +18,8 @@ var ReactNative = require('react-native');
|
|||
* run Flow. */
|
||||
var TimerMixin = require('react-timer-mixin');
|
||||
|
||||
var {
|
||||
StyleSheet,
|
||||
Text,
|
||||
View,
|
||||
} = ReactNative;
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {StyleSheet, Text, View} = ReactNative;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
var TimersTest = createReactClass({
|
||||
displayName: 'TimersTest',
|
||||
|
@ -91,7 +89,7 @@ var TimersTest = createReactClass({
|
|||
fails.push(this.setTimeout(() => this._fail('testClearMulti-4'), 0));
|
||||
fails.push(this.setTimeout(() => this._fail('testClearMulti-5'), 10));
|
||||
|
||||
fails.forEach((timeout) => this.clearTimeout(timeout));
|
||||
fails.forEach(timeout => this.clearTimeout(timeout));
|
||||
this.setTimeout(() => this.clearTimeout(delayClear), 20);
|
||||
|
||||
this.setTimeout(this.testOrdering, 50);
|
||||
|
@ -102,22 +100,32 @@ var TimersTest = createReactClass({
|
|||
var fail0;
|
||||
this.setImmediate(() => this.clearTimeout(fail0));
|
||||
fail0 = this.setTimeout(
|
||||
() => this._fail('testOrdering-t0, setImmediate should happen before ' +
|
||||
'setTimeout 0'),
|
||||
0
|
||||
() =>
|
||||
this._fail(
|
||||
'testOrdering-t0, setImmediate should happen before ' +
|
||||
'setTimeout 0',
|
||||
),
|
||||
0,
|
||||
);
|
||||
var failAnim; // This should fail without the t=0 fastpath feature.
|
||||
this.setTimeout(() => this.cancelAnimationFrame(failAnim), 0);
|
||||
failAnim = this.requestAnimationFrame(
|
||||
() => this._fail('testOrdering-Anim, setTimeout 0 should happen before ' +
|
||||
'requestAnimationFrame')
|
||||
failAnim = this.requestAnimationFrame(() =>
|
||||
this._fail(
|
||||
'testOrdering-Anim, setTimeout 0 should happen before ' +
|
||||
'requestAnimationFrame',
|
||||
),
|
||||
);
|
||||
var fail25;
|
||||
this.setTimeout(() => { this.clearTimeout(fail25); }, 20);
|
||||
this.setTimeout(() => {
|
||||
this.clearTimeout(fail25);
|
||||
}, 20);
|
||||
fail25 = this.setTimeout(
|
||||
() => this._fail('testOrdering-t25, setTimeout 20 should happen before ' +
|
||||
'setTimeout 25'),
|
||||
25
|
||||
() =>
|
||||
this._fail(
|
||||
'testOrdering-t25, setTimeout 20 should happen before ' +
|
||||
'setTimeout 25',
|
||||
),
|
||||
25,
|
||||
);
|
||||
this.setTimeout(this.done, 50);
|
||||
},
|
||||
|
@ -152,7 +160,7 @@ var TimersTest = createReactClass({
|
|||
this.setState({count: this.state.count + 1});
|
||||
},
|
||||
|
||||
_fail(caller : string) : void {
|
||||
_fail(caller: string): void {
|
||||
throw new Error('_fail called by ' + caller);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -4,23 +4,20 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
* @flow
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var ReactNative = require('react-native');
|
||||
var { View } = ReactNative;
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {View} = ReactNative;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
const DEFAULT_WS_URL = 'ws://localhost:5555/';
|
||||
|
||||
const WS_EVENTS = [
|
||||
'close',
|
||||
'error',
|
||||
'message',
|
||||
'open',
|
||||
];
|
||||
const WS_EVENTS = ['close', 'error', 'message', 'open'];
|
||||
const WS_STATES = [
|
||||
/* 0 */ 'CONNECTING',
|
||||
/* 1 */ 'OPEN',
|
||||
|
@ -29,14 +26,14 @@ const WS_STATES = [
|
|||
];
|
||||
|
||||
type State = {
|
||||
url: string;
|
||||
fetchStatus: ?string;
|
||||
socket: ?WebSocket;
|
||||
socketState: ?number;
|
||||
lastSocketEvent: ?string;
|
||||
lastMessage: ?string | ?ArrayBuffer;
|
||||
testMessage: string;
|
||||
testExpectedResponse: string;
|
||||
url: string,
|
||||
fetchStatus: ?string,
|
||||
socket: ?WebSocket,
|
||||
socketState: ?number,
|
||||
lastSocketEvent: ?string,
|
||||
lastMessage: ?string | ?ArrayBuffer,
|
||||
testMessage: string,
|
||||
testExpectedResponse: string,
|
||||
};
|
||||
|
||||
class WebSocketTest extends React.Component<{}, State> {
|
||||
|
@ -48,13 +45,13 @@ class WebSocketTest extends React.Component<{}, State> {
|
|||
lastSocketEvent: null,
|
||||
lastMessage: null,
|
||||
testMessage: 'testMessage',
|
||||
testExpectedResponse: 'testMessage_response'
|
||||
testExpectedResponse: 'testMessage_response',
|
||||
};
|
||||
|
||||
_waitFor = (condition: any, timeout: any, callback: any) => {
|
||||
var remaining = timeout;
|
||||
var t;
|
||||
var timeoutFunction = function() {
|
||||
var timeoutFunction = function() {
|
||||
if (condition()) {
|
||||
callback(true);
|
||||
return;
|
||||
|
@ -63,11 +60,11 @@ class WebSocketTest extends React.Component<{}, State> {
|
|||
if (remaining === 0) {
|
||||
callback(false);
|
||||
} else {
|
||||
t = setTimeout(timeoutFunction,1000);
|
||||
t = setTimeout(timeoutFunction, 1000);
|
||||
}
|
||||
};
|
||||
t = setTimeout(timeoutFunction,1000);
|
||||
}
|
||||
t = setTimeout(timeoutFunction, 1000);
|
||||
};
|
||||
|
||||
_connect = () => {
|
||||
const socket = new WebSocket(this.state.url);
|
||||
|
@ -80,11 +77,11 @@ class WebSocketTest extends React.Component<{}, State> {
|
|||
|
||||
_socketIsConnected = () => {
|
||||
return this.state.socketState === 1; //'OPEN'
|
||||
}
|
||||
};
|
||||
|
||||
_socketIsDisconnected = () => {
|
||||
return this.state.socketState === 3; //'CLOSED'
|
||||
}
|
||||
};
|
||||
|
||||
_disconnect = () => {
|
||||
if (!this.state.socket) {
|
||||
|
@ -116,7 +113,7 @@ class WebSocketTest extends React.Component<{}, State> {
|
|||
};
|
||||
|
||||
_receivedTestExpectedResponse = () => {
|
||||
return (this.state.lastMessage === this.state.testExpectedResponse);
|
||||
return this.state.lastMessage === this.state.testExpectedResponse;
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
|
@ -126,34 +123,40 @@ class WebSocketTest extends React.Component<{}, State> {
|
|||
testConnect = () => {
|
||||
var component = this;
|
||||
component._connect();
|
||||
component._waitFor(component._socketIsConnected, 5, function(connectSucceeded) {
|
||||
component._waitFor(component._socketIsConnected, 5, function(
|
||||
connectSucceeded,
|
||||
) {
|
||||
if (!connectSucceeded) {
|
||||
TestModule.markTestPassed(false);
|
||||
return;
|
||||
}
|
||||
component.testSendAndReceive();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
testSendAndReceive = () => {
|
||||
var component = this;
|
||||
component._sendTestMessage();
|
||||
component._waitFor(component._receivedTestExpectedResponse, 5, function(messageReceived) {
|
||||
component._waitFor(component._receivedTestExpectedResponse, 5, function(
|
||||
messageReceived,
|
||||
) {
|
||||
if (!messageReceived) {
|
||||
TestModule.markTestPassed(false);
|
||||
return;
|
||||
}
|
||||
component.testDisconnect();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
testDisconnect = () => {
|
||||
var component = this;
|
||||
component._disconnect();
|
||||
component._waitFor(component._socketIsDisconnected, 5, function(disconnectSucceeded) {
|
||||
component._waitFor(component._socketIsDisconnected, 5, function(
|
||||
disconnectSucceeded,
|
||||
) {
|
||||
TestModule.markTestPassed(disconnectSucceeded);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
render(): React.Node {
|
||||
return <View />;
|
||||
|
|
|
@ -4,52 +4,68 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
var React = require('react');
|
||||
var ReactNative = require('react-native');
|
||||
var {
|
||||
WebView,
|
||||
} = ReactNative;
|
||||
var {WebView} = ReactNative;
|
||||
|
||||
var { TestModule } = ReactNative.NativeModules;
|
||||
var {TestModule} = ReactNative.NativeModules;
|
||||
|
||||
class WebViewTest extends React.Component {
|
||||
|
||||
render() {
|
||||
var firstMessageReceived = false;
|
||||
var secondMessageReceived = false;
|
||||
function processMessage(e) {
|
||||
var message = e.nativeEvent.data;
|
||||
if (message === 'First') {firstMessageReceived = true;}
|
||||
if (message === 'Second') {secondMessageReceived = true;}
|
||||
if (message === 'First') {
|
||||
firstMessageReceived = true;
|
||||
}
|
||||
if (message === 'Second') {
|
||||
secondMessageReceived = true;
|
||||
}
|
||||
|
||||
// got both messages
|
||||
if (firstMessageReceived && secondMessageReceived) {TestModule.markTestPassed(true);}
|
||||
if (firstMessageReceived && secondMessageReceived) {
|
||||
TestModule.markTestPassed(true);
|
||||
}
|
||||
// wait for next message
|
||||
else if (firstMessageReceived && !secondMessageReceived) {return;}
|
||||
else if (firstMessageReceived && !secondMessageReceived) {
|
||||
return;
|
||||
}
|
||||
// first message got lost
|
||||
else if (!firstMessageReceived && secondMessageReceived) {throw new Error('First message got lost');}
|
||||
else if (!firstMessageReceived && secondMessageReceived) {
|
||||
throw new Error('First message got lost');
|
||||
}
|
||||
}
|
||||
var html = 'Hello world'
|
||||
+ '<script>'
|
||||
+ "window.setTimeout(function(){window.postMessage('First'); window.postMessage('Second')}, 0)"
|
||||
+ '</script>';
|
||||
var html =
|
||||
'Hello world' +
|
||||
'<script>' +
|
||||
"window.setTimeout(function(){window.postMessage('First'); window.postMessage('Second')}, 0)" +
|
||||
'</script>';
|
||||
|
||||
// fail if messages didn't get through;
|
||||
window.setTimeout(function() { throw new Error(firstMessageReceived ? 'Both messages got lost' : 'Second message got lost');}, 10000);
|
||||
window.setTimeout(function() {
|
||||
throw new Error(
|
||||
firstMessageReceived
|
||||
? 'Both messages got lost'
|
||||
: 'Second message got lost',
|
||||
);
|
||||
}, 10000);
|
||||
|
||||
var source = {
|
||||
html: html,
|
||||
};
|
||||
};
|
||||
|
||||
return (
|
||||
<WebView
|
||||
source={source}
|
||||
onMessage = {processMessage}
|
||||
onMessage={processMessage}
|
||||
originWhitelist={['about:blank']}
|
||||
/>
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue