diff --git a/IntegrationTests/AccessibilityManagerTest.js b/IntegrationTests/AccessibilityManagerTest.js index 4287094d3..41710be91 100644 --- a/IntegrationTests/AccessibilityManagerTest.js +++ b/IntegrationTests/AccessibilityManagerTest.js @@ -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); diff --git a/IntegrationTests/AppEventsTest.js b/IntegrationTests/AppEventsTest.js index af04819b3..9df430fea 100644 --- a/IntegrationTests/AppEventsTest.js +++ b/IntegrationTests/AppEventsTest.js @@ -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 ( - - {JSON.stringify(this.state, null, ' ')} - + {JSON.stringify(this.state, null, ' ')} ); } diff --git a/IntegrationTests/AsyncStorageTest.js b/IntegrationTests/AsyncStorageTest.js index 2d951dab3..9245854e2 100644 --- a/IntegrationTests/AsyncStorageTest.js +++ b/IntegrationTests/AsyncStorageTest.js @@ -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 ( - { - /* $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} diff --git a/IntegrationTests/ImageCachePolicyTest.js b/IntegrationTests/ImageCachePolicyTest.js index a095b4ec9..1c4429389 100644 --- a/IntegrationTests/ImageCachePolicyTest.js +++ b/IntegrationTests/ImageCachePolicyTest.js @@ -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 { - state = {} + state = {}; shouldComponentUpdate(nextProps: Props, nextState: State) { const results: Array = 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 { return ( Hello - this.testComplete('only-if-cached', false)} - onError={() => this.testComplete('only-if-cached', true)} - style={styles.base} - /> this.testComplete('only-if-cached', false)} + onError={() => this.testComplete('only-if-cached', true)} + style={styles.base} + /> + this.testComplete('default', true)} onError={() => this.testComplete('default', false)} style={styles.base} /> this.testComplete('reload', true)} onError={() => this.testComplete('reload', false)} style={styles.base} /> this.testComplete('force-cache', true)} onError={() => this.testComplete('force-cache', false)} style={styles.base} diff --git a/IntegrationTests/ImageSnapshotTest.js b/IntegrationTests/ImageSnapshotTest.js index 3d024d569..5c74433a9 100644 --- a/IntegrationTests/ImageSnapshotTest.js +++ b/IntegrationTests/ImageSnapshotTest.js @@ -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<{}> { TestModule.verifySnapshot(this.done)} /> + onLoad={() => TestModule.verifySnapshot(this.done)} + /> ); } } diff --git a/IntegrationTests/IntegrationTestHarnessTest.js b/IntegrationTests/IntegrationTestHarnessTest.js index 9b34065b8..2a596d068 100644 --- a/IntegrationTests/IntegrationTestHarnessTest.js +++ b/IntegrationTests/IntegrationTestHarnessTest.js @@ -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 ( - { - /* $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...'} diff --git a/IntegrationTests/IntegrationTestsApp.js b/IntegrationTests/IntegrationTestsApp.js index 62f6fa830..c59f15b3d 100644 --- a/IntegrationTests/IntegrationTestsApp.js +++ b/IntegrationTests/IntegrationTestsApp.js @@ -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> { 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. - {TESTS.map((test) => [ + {TESTS.map(test => [ this.setState({test})} style={styles.row}> - - {test.displayName} - + {test.displayName} , - + , ])} diff --git a/IntegrationTests/LayoutEventsTest.js b/IntegrationTests/LayoutEventsTest.js index 31dd1839c..b9183a34e 100644 --- a/IntegrationTests/LayoutEventsTest.js +++ b/IntegrationTests/LayoutEventsTest.js @@ -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({ ); - } + }, }); var styles = StyleSheet.create({ diff --git a/IntegrationTests/LoggingTestModule.js b/IntegrationTests/LoggingTestModule.js index df2b0e59b..76a4fbccd 100644 --- a/IntegrationTests/LoggingTestModule.js +++ b/IntegrationTests/LoggingTestModule.js @@ -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; diff --git a/IntegrationTests/PromiseTest.js b/IntegrationTests/PromiseTest.js index 21005576d..3e919a867 100644 --- a/IntegrationTests/PromiseTest.js +++ b/IntegrationTests/PromiseTest.js @@ -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 => { diff --git a/IntegrationTests/PropertiesUpdateTest.js b/IntegrationTests/PropertiesUpdateTest.js index 3d93d9d0a..e2c16f3a6 100644 --- a/IntegrationTests/PropertiesUpdateTest.js +++ b/IntegrationTests/PropertiesUpdateTest.js @@ -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 ( - - ); + return ; } } diff --git a/IntegrationTests/RCTRootViewIntegrationTestApp.js b/IntegrationTests/RCTRootViewIntegrationTestApp.js index aef56f975..8cb499f36 100644 --- a/IntegrationTests/RCTRootViewIntegrationTestApp.js +++ b/IntegrationTests/RCTRootViewIntegrationTestApp.js @@ -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 { 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. - {TESTS.map((test) => [ + {TESTS.map(test => [ this.setState({test})} style={styles.row}> - - {test.displayName} - + {test.displayName} , - + , ])} @@ -88,4 +88,7 @@ var styles = StyleSheet.create({ }, }); -AppRegistry.registerComponent('RCTRootViewIntegrationTestApp', () => RCTRootViewIntegrationTestApp); +AppRegistry.registerComponent( + 'RCTRootViewIntegrationTestApp', + () => RCTRootViewIntegrationTestApp, +); diff --git a/IntegrationTests/ReactContentSizeUpdateTest.js b/IntegrationTests/ReactContentSizeUpdateTest.js index dda42b4df..1306f8d7a 100644 --- a/IntegrationTests/ReactContentSizeUpdateTest.js +++ b/IntegrationTests/ReactContentSizeUpdateTest.js @@ -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 ( - + ); - } + }, }); ReactContentSizeUpdateTest.displayName = 'ReactContentSizeUpdateTest'; diff --git a/IntegrationTests/SimpleSnapshotTest.js b/IntegrationTests/SimpleSnapshotTest.js index dd8bf9ac8..ea32c4a9a 100644 --- a/IntegrationTests/SimpleSnapshotTest.js +++ b/IntegrationTests/SimpleSnapshotTest.js @@ -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); }; diff --git a/IntegrationTests/SizeFlexibilityUpdateTest.js b/IntegrationTests/SizeFlexibilityUpdateTest.js index ce0be9e6e..5f885ddb7 100644 --- a/IntegrationTests/SizeFlexibilityUpdateTest.js +++ b/IntegrationTests/SizeFlexibilityUpdateTest.js @@ -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 ( - - ); - } + return ; + }, }); SizeFlexibilityUpdateTest.displayName = 'SizeFlexibilityUpdateTest'; diff --git a/IntegrationTests/SyncMethodTest.js b/IntegrationTests/SyncMethodTest.js index f61f52b36..eca1df986 100644 --- a/IntegrationTests/SyncMethodTest.js +++ b/IntegrationTests/SyncMethodTest.js @@ -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) { diff --git a/IntegrationTests/TimersTest.js b/IntegrationTests/TimersTest.js index f40742c9a..86e1a9621 100644 --- a/IntegrationTests/TimersTest.js +++ b/IntegrationTests/TimersTest.js @@ -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); }, }); diff --git a/IntegrationTests/WebSocketTest.js b/IntegrationTests/WebSocketTest.js index de8428f79..33d6b2500 100644 --- a/IntegrationTests/WebSocketTest.js +++ b/IntegrationTests/WebSocketTest.js @@ -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 ; diff --git a/IntegrationTests/WebViewTest.js b/IntegrationTests/WebViewTest.js index 818b4e980..47b4544cd 100644 --- a/IntegrationTests/WebViewTest.js +++ b/IntegrationTests/WebViewTest.js @@ -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' - + ''; + var html = + 'Hello world' + + ''; // 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 ( + /> ); } }