vars -> let/const react-native IntegrationTests

Reviewed By: yungsters

Differential Revision: D7986752

fbshipit-source-id: 1f9b129ce19e052584a2cd1240686b6099c64416
This commit is contained in:
Eli White 2018-05-14 00:09:36 -07:00 committed by Facebook Github Bot
parent 75ad71ee24
commit 398f1d8ddd
18 changed files with 143 additions and 140 deletions

View File

@ -10,14 +10,14 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {NativeAppEventEmitter, StyleSheet, Text, View} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const React = require('react');
const ReactNative = require('react-native');
const {NativeAppEventEmitter, StyleSheet, Text, View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
var deepDiffer = require('deepDiffer');
const deepDiffer = require('deepDiffer');
var TEST_PAYLOAD = {foo: 'bar'};
const TEST_PAYLOAD = {foo: 'bar'};
type AppEvent = {data: Object, ts: number};
type State = {
@ -31,7 +31,7 @@ class AppEventsTest extends React.Component<{}, State> {
componentDidMount() {
NativeAppEventEmitter.addListener('testEvent', this.receiveEvent);
var event = {data: TEST_PAYLOAD, ts: Date.now()};
const event = {data: TEST_PAYLOAD, ts: Date.now()};
TestModule.sendAppEvent('testEvent', event);
this.setState({sent: event});
}
@ -40,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';
const elapsed = Date.now() - event.ts + 'ms';
this.setState({received: event, elapsed}, () => {
TestModule.markTestCompleted();
});
@ -57,7 +57,7 @@ class AppEventsTest extends React.Component<{}, State> {
AppEventsTest.displayName = 'AppEventsTest';
var styles = StyleSheet.create({
const styles = StyleSheet.create({
container: {
margin: 40,
},

View File

@ -10,27 +10,27 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {AsyncStorage, Text, View} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const React = require('react');
const ReactNative = require('react-native');
const {AsyncStorage, Text, View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
var deepDiffer = require('deepDiffer');
const deepDiffer = require('deepDiffer');
var DEBUG = false;
const DEBUG = false;
var KEY_1 = 'key_1';
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}};
const KEY_1 = 'key_1';
const VAL_1 = 'val_1';
const KEY_2 = 'key_2';
const VAL_2 = 'val_2';
const KEY_MERGE = 'key_merge';
const VAL_MERGE_1 = {foo: 1, bar: {hoo: 1, boo: 1}, moo: {a: 3}};
const VAL_MERGE_2 = {bar: {hoo: 2}, baz: 2, moo: {a: 3}};
const 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) => {};
let done = (result: ?boolean) => {};
let updateMessage = (message: string) => {};
function runTestCase(description: string, fn) {
updateMessage(description);

View File

@ -10,10 +10,10 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {Image, View, Text, StyleSheet} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const React = require('react');
const ReactNative = require('react-native');
const {Image, View, Text, StyleSheet} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
/*
* The reload and force-cache tests don't actually verify that the complete functionality.

View File

@ -10,10 +10,10 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {Image, View} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const React = require('react');
const ReactNative = require('react-native');
const {Image, View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
class ImageSnapshotTest extends React.Component<{}> {
componentDidMount() {

View File

@ -13,12 +13,12 @@
/* $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. */
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;
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;
class IntegrationTestHarnessTest extends React.Component<
{

View File

@ -10,9 +10,9 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {
const React = require('react');
const ReactNative = require('react-native');
const {
AppRegistry,
ScrollView,
StyleSheet,
@ -22,7 +22,7 @@ var {
} = ReactNative;
// Keep this list in sync with RNTesterIntegrationTests.m
var TESTS = [
const TESTS = [
require('./IntegrationTestHarnessTest'),
require('./TimersTest'),
require('./AsyncStorageTest'),
@ -89,7 +89,7 @@ class IntegrationTestsApp extends React.Component<{}, $FlowFixMeState> {
}
}
var styles = StyleSheet.create({
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
marginTop: 40,

View File

@ -10,13 +10,13 @@
'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;
const React = require('react');
const createReactClass = require('create-react-class');
const ReactNative = require('react-native');
const {Image, LayoutAnimation, StyleSheet, Text, View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
var deepDiffer = require('deepDiffer');
const deepDiffer = require('deepDiffer');
function debug(...args) {
// console.log.apply(null, arguments);
@ -42,7 +42,7 @@ type State = {
containerStyle?: Style,
};
var LayoutEventsTest = createReactClass({
const LayoutEventsTest = createReactClass({
displayName: 'LayoutEventsTest',
getInitialState(): State {
return {
@ -93,7 +93,7 @@ var LayoutEventsTest = createReactClass({
},
compare: function(node: string, measured: any, onLayout: any): void {
if (deepDiffer(measured, onLayout)) {
var data = {measured, onLayout};
const data = {measured, onLayout};
throw new Error(
node +
' onLayout mismatch with measure ' +
@ -114,9 +114,9 @@ var LayoutEventsTest = createReactClass({
this.setState({imageLayout: e.nativeEvent.layout}, this.checkLayout);
},
render: function() {
var viewStyle = [styles.view, this.state.viewStyle];
var textLayout = this.state.textLayout || {width: '?', height: '?'};
var imageLayout = this.state.imageLayout || {x: '?', y: '?'};
const viewStyle = [styles.view, this.state.viewStyle];
const textLayout = this.state.textLayout || {width: '?', height: '?'};
const imageLayout = this.state.imageLayout || {x: '?', y: '?'};
debug('viewLayout', this.state.viewLayout);
return (
<View style={[styles.container, this.state.containerStyle]}>
@ -141,7 +141,7 @@ var LayoutEventsTest = createReactClass({
},
});
var styles = StyleSheet.create({
const styles = StyleSheet.create({
container: {
margin: 40,
},

View File

@ -9,12 +9,12 @@
'use strict';
var BatchedBridge = require('BatchedBridge');
const BatchedBridge = require('BatchedBridge');
var warning = require('fbjs/lib/warning');
var invariant = require('fbjs/lib/invariant');
const warning = require('fbjs/lib/warning');
const invariant = require('fbjs/lib/invariant');
var LoggingTestModule = {
const LoggingTestModule = {
logToConsole: function(str) {
console.log(str);
},

View File

@ -10,10 +10,10 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {View} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const React = require('react');
const ReactNative = require('react-native');
const {View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
class PromiseTest extends React.Component<{}> {
shouldResolve = false;

View File

@ -9,11 +9,11 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {View} = ReactNative;
const React = require('react');
const ReactNative = require('react-native');
const {View} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const {TestModule} = ReactNative.NativeModules;
class PropertiesUpdateTest extends React.Component {
render() {

View File

@ -11,10 +11,10 @@
require('regenerator-runtime/runtime');
var React = require('react');
var ReactNative = require('react-native');
const React = require('react');
const ReactNative = require('react-native');
var {
const {
AppRegistry,
ScrollView,
StyleSheet,
@ -24,7 +24,7 @@ var {
} = ReactNative;
/* Keep this list in sync with RCTRootViewIntegrationTests.m */
var TESTS = [
const TESTS = [
require('./PropertiesUpdateTest'),
require('./ReactContentSizeUpdateTest'),
require('./SizeFlexibilityUpdateTest'),
@ -70,7 +70,7 @@ class RCTRootViewIntegrationTestApp extends React.Component {
}
}
var styles = StyleSheet.create({
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
marginTop: 40,

View File

@ -9,23 +9,23 @@
'use strict';
var React = require('react');
var createReactClass = require('create-react-class');
var ReactNative = require('react-native');
var RCTNativeAppEventEmitter = require('RCTNativeAppEventEmitter');
var Subscribable = require('Subscribable');
var TimerMixin = require('react-timer-mixin');
const React = require('react');
const createReactClass = require('create-react-class');
const ReactNative = require('react-native');
const RCTNativeAppEventEmitter = require('RCTNativeAppEventEmitter');
const Subscribable = require('Subscribable');
const TimerMixin = require('react-timer-mixin');
var {View} = ReactNative;
const {View} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const {TestModule} = ReactNative.NativeModules;
var reactViewWidth = 101;
var reactViewHeight = 102;
var newReactViewWidth = 201;
var newReactViewHeight = 202;
const reactViewWidth = 101;
const reactViewHeight = 102;
const newReactViewWidth = 201;
const newReactViewHeight = 202;
var ReactContentSizeUpdateTest = createReactClass({
const ReactContentSizeUpdateTest = createReactClass({
displayName: 'ReactContentSizeUpdateTest',
mixins: [Subscribable.Mixin, TimerMixin],

View File

@ -10,15 +10,15 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
const React = require('react');
const ReactNative = require('react-native');
/* $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. */
var requestAnimationFrame = require('fbjs/lib/requestAnimationFrame');
const requestAnimationFrame = require('fbjs/lib/requestAnimationFrame');
var {StyleSheet, View} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const {StyleSheet, View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
class SimpleSnapshotTest extends React.Component<{}> {
componentDidMount() {
@ -42,7 +42,7 @@ class SimpleSnapshotTest extends React.Component<{}> {
}
}
var styles = StyleSheet.create({
const styles = StyleSheet.create({
box1: {
width: 80,
height: 50,

View File

@ -9,21 +9,21 @@
'use strict';
var React = require('react');
var createReactClass = require('create-react-class');
var ReactNative = require('react-native');
var RCTNativeAppEventEmitter = require('RCTNativeAppEventEmitter');
var Subscribable = require('Subscribable');
var {View} = ReactNative;
const React = require('react');
const createReactClass = require('create-react-class');
const ReactNative = require('react-native');
const RCTNativeAppEventEmitter = require('RCTNativeAppEventEmitter');
const Subscribable = require('Subscribable');
const {View} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const {TestModule} = ReactNative.NativeModules;
var reactViewWidth = 111;
var reactViewHeight = 222;
const reactViewWidth = 111;
const reactViewHeight = 222;
var finalState = false;
let finalState = false;
var SizeFlexibilityUpdateTest = createReactClass({
const SizeFlexibilityUpdateTest = createReactClass({
displayName: 'SizeFlexibilityUpdateTest',
mixins: [Subscribable.Mixin],

View File

@ -10,9 +10,9 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {View} = ReactNative;
const React = require('react');
const ReactNative = require('react-native');
const {View} = ReactNative;
const {TestModule, RNTesterTestModule} = ReactNative.NativeModules;

View File

@ -10,18 +10,18 @@
'use strict';
var React = require('react');
var createReactClass = require('create-react-class');
var ReactNative = require('react-native');
const React = require('react');
const createReactClass = require('create-react-class');
const ReactNative = require('react-native');
/* $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. */
var TimerMixin = require('react-timer-mixin');
const TimerMixin = require('react-timer-mixin');
var {StyleSheet, Text, View} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const {StyleSheet, Text, View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
var TimersTest = createReactClass({
const TimersTest = createReactClass({
displayName: 'TimersTest',
mixins: [TimerMixin],
@ -70,22 +70,25 @@ var TimersTest = createReactClass({
},
testClearTimeout0() {
var timeout = this.setTimeout(() => this._fail('testClearTimeout0'), 0);
const timeout = this.setTimeout(() => this._fail('testClearTimeout0'), 0);
this.clearTimeout(timeout);
this.testClearTimeout30();
},
testClearTimeout30() {
var timeout = this.setTimeout(() => this._fail('testClearTimeout30'), 30);
const timeout = this.setTimeout(() => this._fail('testClearTimeout30'), 30);
this.clearTimeout(timeout);
this.setTimeout(this.testClearMulti, 50);
},
testClearMulti() {
var fails = [];
const fails = [];
fails.push(this.setTimeout(() => this._fail('testClearMulti-1'), 20));
fails.push(this.setTimeout(() => this._fail('testClearMulti-2'), 50));
var delayClear = this.setTimeout(() => this._fail('testClearMulti-3'), 50);
const delayClear = this.setTimeout(
() => this._fail('testClearMulti-3'),
50,
);
fails.push(this.setTimeout(() => this._fail('testClearMulti-4'), 0));
fails.push(this.setTimeout(() => this._fail('testClearMulti-5'), 10));
@ -97,7 +100,7 @@ var TimersTest = createReactClass({
testOrdering() {
// Clear timers are set first because it's more likely to uncover bugs.
var fail0;
let fail0;
this.setImmediate(() => this.clearTimeout(fail0));
fail0 = this.setTimeout(
() =>
@ -107,7 +110,7 @@ var TimersTest = createReactClass({
),
0,
);
var failAnim; // This should fail without the t=0 fastpath feature.
let failAnim; // This should fail without the t=0 fastpath feature.
this.setTimeout(() => this.cancelAnimationFrame(failAnim), 0);
failAnim = this.requestAnimationFrame(() =>
this._fail(
@ -115,7 +118,7 @@ var TimersTest = createReactClass({
'requestAnimationFrame',
),
);
var fail25;
let fail25;
this.setTimeout(() => {
this.clearTimeout(fail25);
}, 20);
@ -165,7 +168,7 @@ var TimersTest = createReactClass({
},
});
var styles = StyleSheet.create({
const styles = StyleSheet.create({
container: {
backgroundColor: 'white',
padding: 40,

View File

@ -10,10 +10,10 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {View} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const React = require('react');
const ReactNative = require('react-native');
const {View} = ReactNative;
const {TestModule} = ReactNative.NativeModules;
const DEFAULT_WS_URL = 'ws://localhost:5555/';
@ -49,9 +49,9 @@ class WebSocketTest extends React.Component<{}, State> {
};
_waitFor = (condition: any, timeout: any, callback: any) => {
var remaining = timeout;
var t;
var timeoutFunction = function() {
let remaining = timeout;
let t;
const timeoutFunction = function() {
if (condition()) {
callback(true);
return;
@ -121,7 +121,7 @@ class WebSocketTest extends React.Component<{}, State> {
}
testConnect = () => {
var component = this;
const component = this;
component._connect();
component._waitFor(component._socketIsConnected, 5, function(
connectSucceeded,
@ -135,7 +135,7 @@ class WebSocketTest extends React.Component<{}, State> {
};
testSendAndReceive = () => {
var component = this;
const component = this;
component._sendTestMessage();
component._waitFor(component._receivedTestExpectedResponse, 5, function(
messageReceived,
@ -149,7 +149,7 @@ class WebSocketTest extends React.Component<{}, State> {
};
testDisconnect = () => {
var component = this;
const component = this;
component._disconnect();
component._waitFor(component._socketIsDisconnected, 5, function(
disconnectSucceeded,

View File

@ -9,18 +9,18 @@
'use strict';
var React = require('react');
var ReactNative = require('react-native');
var {WebView} = ReactNative;
const React = require('react');
const ReactNative = require('react-native');
const {WebView} = ReactNative;
var {TestModule} = ReactNative.NativeModules;
const {TestModule} = ReactNative.NativeModules;
class WebViewTest extends React.Component {
render() {
var firstMessageReceived = false;
var secondMessageReceived = false;
let firstMessageReceived = false;
let secondMessageReceived = false;
function processMessage(e) {
var message = e.nativeEvent.data;
const message = e.nativeEvent.data;
if (message === 'First') {
firstMessageReceived = true;
}
@ -41,7 +41,7 @@ class WebViewTest extends React.Component {
throw new Error('First message got lost');
}
}
var html =
const html =
'Hello world' +
'<script>' +
"window.setTimeout(function(){window.postMessage('First'); window.postMessage('Second')}, 0)" +
@ -56,7 +56,7 @@ class WebViewTest extends React.Component {
);
}, 10000);
var source = {
const source = {
html: html,
};