Prettier the rest of ReactNative

Reviewed By: yungsters

Differential Revision: D7974340

fbshipit-source-id: 5fe457a8a9be4bd360fc3af9acb5c1136b2be0d7
This commit is contained in:
Eli White
2018-05-11 13:32:37 -07:00
committed by Facebook Github Bot
parent aba4ec0c09
commit 36fcbaa56d
170 changed files with 5132 additions and 3995 deletions

View File

@@ -21,9 +21,11 @@
* - (cd android && ./gradlew :app:copyDownloadableDepsToLibs)
* - buck build android/app
* - node ../node_modules/.bin/_mocha ../android-e2e-test.js
*
* @format
*/
/* eslint-env mocha */
/* eslint-env mocha */
'use strict';
@@ -35,27 +37,32 @@ require('colors');
// value in ms to print out screen contents, set this value in CI to debug if tests are failing
const appiumDebugInterval = process.env.APPIUM_DEBUG_INTERVAL;
describe('Android Test App', function () {
describe('Android Test App', function() {
this.timeout(600000);
let driver;
let debugIntervalId;
before(function () {
before(function() {
driver = wd.promiseChainRemote({
host: 'localhost',
port: 4723
port: 4723,
});
driver.on('status', function (info) {
driver.on('status', function(info) {
console.log(info.cyan);
});
driver.on('command', function (method, path, data) {
driver.on('command', function(method, path, data) {
if (path === 'source()' && data) {
console.log(' > ' + method.yellow, 'Screen contents'.grey, '\n', pd.xml(data).yellow);
console.log(
' > ' + method.yellow,
'Screen contents'.grey,
'\n',
pd.xml(data).yellow,
);
} else {
console.log(' > ' + method.yellow, path.grey, data || '');
}
});
driver.on('http', function (method, path, data) {
driver.on('http', function(method, path, data) {
console.log(' > ' + method.magenta, path, (data || '').grey);
});
@@ -70,7 +77,7 @@ describe('Android Test App', function () {
const desired = {
platformName: 'Android',
deviceName: 'Android Emulator',
app: path.resolve('buck-out/gen/android/app/app.apk')
app: path.resolve('buck-out/gen/android/app/app.apk'),
};
// React Native in dev mode often starts with Red Box "Can't fibd variable __fbBatchedBridge..."
@@ -78,56 +85,79 @@ describe('Android Test App', function () {
return driver
.init(desired)
.setImplicitWaitTimeout(5000)
.waitForElementByXPath('//android.widget.Button[@text="Reload JS"]').
then((elem) => {
elem.click();
}, (err) => {
// ignoring if Reload JS button can't be located
})
.waitForElementByXPath('//android.widget.Button[@text="Reload JS"]')
.then(
elem => {
elem.click();
},
err => {
// ignoring if Reload JS button can't be located
},
)
.setImplicitWaitTimeout(150000);
});
after(function () {
after(function() {
if (debugIntervalId) {
clearInterval(debugIntervalId);
}
return driver.quit();
});
it('should have Hot Module Reloading working', function () {
it('should have Hot Module Reloading working', function() {
const androidAppCode = fs.readFileSync('index.js', 'utf-8');
let intervalToUpdate;
return driver
.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]')
// http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_MENU
.pressDeviceKey(82)
.elementByXPath('//android.widget.TextView[starts-with(@text, "Enable Hot Reloading")]')
.click()
.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]')
.then(() => {
let iteration = 0;
// CI environment can be quite slow and we can't guarantee that it can consistently motice a file change
// so we change the file every few seconds just in case
intervalToUpdate = setInterval(() => {
fs.writeFileSync('index.js', androidAppCode.replace('Welcome to React Native!', 'Welcome to React Native with HMR!' + iteration), 'utf-8');
}, 3000);
})
.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Welcome to React Native with HMR!")]')
.finally(() => {
clearInterval(intervalToUpdate);
fs.writeFileSync('index.js', androidAppCode, 'utf-8');
});
return (
driver
.waitForElementByXPath(
'//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]',
)
// http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_MENU
.pressDeviceKey(82)
.elementByXPath(
'//android.widget.TextView[starts-with(@text, "Enable Hot Reloading")]',
)
.click()
.waitForElementByXPath(
'//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]',
)
.then(() => {
let iteration = 0;
// CI environment can be quite slow and we can't guarantee that it can consistently motice a file change
// so we change the file every few seconds just in case
intervalToUpdate = setInterval(() => {
fs.writeFileSync(
'index.js',
androidAppCode.replace(
'Welcome to React Native!',
'Welcome to React Native with HMR!' + iteration,
),
'utf-8',
);
}, 3000);
})
.waitForElementByXPath(
'//android.widget.TextView[starts-with(@text, "Welcome to React Native with HMR!")]',
)
.finally(() => {
clearInterval(intervalToUpdate);
fs.writeFileSync('index.js', androidAppCode, 'utf-8');
})
);
});
it('should have Debug In Chrome working', function () {
it('should have Debug In Chrome working', function() {
const androidAppCode = fs.readFileSync('index.js', 'utf-8');
// http://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_MENU
return driver
.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]')
.waitForElementByXPath(
'//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]',
)
.pressDeviceKey(82)
.elementByXPath('//android.widget.TextView[starts-with(@text, "Debug")]')
.click()
.waitForElementByXPath('//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]');
.waitForElementByXPath(
'//android.widget.TextView[starts-with(@text, "Welcome to React Native!")]',
);
});
});

View File

@@ -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';
/**
@@ -60,17 +63,24 @@ if (buildBranch.indexOf('-stable') !== -1) {
// 34c034298dc9cad5a4553964a5a324450fda0385
const currentCommit = exec('git rev-parse HEAD', {silent: true}).stdout.trim();
// [34c034298dc9cad5a4553964a5a324450fda0385, refs/heads/0.33-stable, refs/tags/latest, refs/tags/v0.33.1, refs/tags/v0.34.1-rc]
const tagsWithVersion = exec(`git ls-remote origin | grep ${currentCommit}`, {silent: true})
const tagsWithVersion = exec(`git ls-remote origin | grep ${currentCommit}`, {
silent: true,
})
.stdout.split(/\s/)
// ['refs/tags/v0.33.0', 'refs/tags/v0.33.0-rc', 'refs/tags/v0.33.0-rc1', 'refs/tags/v0.33.0-rc2', 'refs/tags/v0.34.0']
.filter(version => !!version && version.indexOf(`refs/tags/v${branchVersion}`) === 0)
.filter(
version =>
!!version && version.indexOf(`refs/tags/v${branchVersion}`) === 0,
)
// ['refs/tags/v0.33.0', 'refs/tags/v0.33.0-rc', 'refs/tags/v0.33.0-rc1', 'refs/tags/v0.33.0-rc2']
.filter(version => version.indexOf(branchVersion) !== -1)
// ['v0.33.0', 'v0.33.0-rc', 'v0.33.0-rc1', 'v0.33.0-rc2']
.map(version => version.slice('refs/tags/'.length));
if (tagsWithVersion.length === 0) {
echo('Error: Can\'t find version tag in current commit. To deploy to NPM you must add tag v0.XY.Z[-rc] to your commit');
echo(
"Error: Can't find version tag in current commit. To deploy to NPM you must add tag v0.XY.Z[-rc] to your commit",
);
exit(1);
}
let releaseVersion;
@@ -86,7 +96,7 @@ if (tagsWithVersion[0].indexOf('-rc') === -1) {
// -------- Generating Android Artifacts with JavaDoc
if (exec('./gradlew :ReactAndroid:installArchives').code) {
echo('Couldn\'t generate artifacts');
echo("Couldn't generate artifacts");
exit(1);
}
@@ -95,12 +105,17 @@ exec('git checkout ReactAndroid/gradle.properties');
echo('Generated artifacts for Maven');
let artifacts = ['-javadoc.jar', '-sources.jar', '.aar', '.pom'].map((suffix) => {
let artifacts = ['-javadoc.jar', '-sources.jar', '.aar', '.pom'].map(suffix => {
return `react-native-${releaseVersion}${suffix}`;
});
artifacts.forEach((name) => {
if (!test('-e', `./android/com/facebook/react/react-native/${releaseVersion}/${name}`)) {
artifacts.forEach(name => {
if (
!test(
'-e',
`./android/com/facebook/react/react-native/${releaseVersion}/${name}`,
)
) {
echo(`file ${name} was not generated`);
exit(1);
}

View File

@@ -3,6 +3,8 @@
*
* 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';
@@ -19,12 +21,7 @@
* --retries [num] - how many times to retry possible flaky commands: npm install and running tests, default 1
*/
const {
echo,
exec,
exit,
ls,
} = require('shelljs');
const {echo, exec, exit, ls} = require('shelljs');
const argv = require('yargs').argv;
const numberOfRetries = argv.retries || 1;
@@ -34,33 +31,39 @@ const path = require('path');
// Flaky tests ignored on Circle CI. They still run internally at fb.
const ignoredTests = [
'ReactScrollViewTestCase',
'ReactHorizontalScrollViewTestCase'
'ReactHorizontalScrollViewTestCase',
];
// ReactAndroid/src/androidTest/java/com/facebook/react/tests/ReactHorizontalScrollViewTestCase.java
const testClasses = ls(`${argv.path}/*.java`)
.map(javaFile => {
// ReactHorizontalScrollViewTestCase
return path.basename(javaFile, '.java');
}).filter(className => {
return ignoredTests.indexOf(className) === -1;
}).map(className => {
// com.facebook.react.tests.ReactHorizontalScrollViewTestCase
return argv.package + '.' + className;
});
.map(javaFile => {
// ReactHorizontalScrollViewTestCase
return path.basename(javaFile, '.java');
})
.filter(className => {
return ignoredTests.indexOf(className) === -1;
})
.map(className => {
// com.facebook.react.tests.ReactHorizontalScrollViewTestCase
return argv.package + '.' + className;
});
let exitCode = 0;
testClasses.forEach((testClass) => {
if (tryExecNTimes(
() => {
testClasses.forEach(testClass => {
if (
tryExecNTimes(() => {
echo(`Starting ${testClass}`);
// any faster means Circle CI crashes
exec('sleep 10s');
return exec(`./scripts/run-instrumentation-tests-via-adb-shell.sh ${argv.package} ${testClass}`).code;
},
numberOfRetries)) {
echo(`${testClass} failed ${numberOfRetries} times`);
exitCode = 1;
return exec(
`./scripts/run-instrumentation-tests-via-adb-shell.sh ${
argv.package
} ${testClass}`,
).code;
}, numberOfRetries)
) {
echo(`${testClass} failed ${numberOfRetries} times`);
exitCode = 1;
}
});

View File

@@ -3,6 +3,8 @@
*
* 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';
@@ -32,8 +34,12 @@ const TEMP = exec('mktemp -d /tmp/react-native-XXXXXXXX').stdout.trim();
// To make sure we actually installed the local version
// of react-native, we will create a temp file inside the template
// and check that it exists after `react-native init
const MARKER_IOS = exec(`mktemp ${ROOT}/local-cli/templates/HelloWorld/ios/HelloWorld/XXXXXXXX`).stdout.trim();
const MARKER_ANDROID = exec(`mktemp ${ROOT}/local-cli/templates/HelloWorld/android/XXXXXXXX`).stdout.trim();
const MARKER_IOS = exec(
`mktemp ${ROOT}/local-cli/templates/HelloWorld/ios/HelloWorld/XXXXXXXX`,
).stdout.trim();
const MARKER_ANDROID = exec(
`mktemp ${ROOT}/local-cli/templates/HelloWorld/android/XXXXXXXX`,
).stdout.trim();
const numberOfRetries = argv.retries || 1;
let SERVER_PID;
let APPIUM_PID;
@@ -43,7 +49,11 @@ try {
// install CLI
cd('react-native-cli');
exec('yarn pack');
const CLI_PACKAGE = path.join(ROOT, 'react-native-cli', 'react-native-cli-*.tgz');
const CLI_PACKAGE = path.join(
ROOT,
'react-native-cli',
'react-native-cli-*.tgz',
);
cd('..');
if (!argv['skip-cli-install']) {
@@ -56,7 +66,11 @@ try {
}
if (argv.android) {
if (exec('./gradlew :ReactAndroid:installArchives -Pjobs=1 -Dorg.gradle.jvmargs="-Xmx512m -XX:+HeapDumpOnOutOfMemoryError"').code) {
if (
exec(
'./gradlew :ReactAndroid:installArchives -Pjobs=1 -Dorg.gradle.jvmargs="-Xmx512m -XX:+HeapDumpOnOutOfMemoryError"',
).code
) {
echo('Failed to compile Android binaries');
exitCode = 1;
throw Error(exitCode);
@@ -71,17 +85,20 @@ try {
const PACKAGE = path.join(ROOT, 'react-native-*.tgz');
cd(TEMP);
if (tryExecNTimes(
() => {
exec('sleep 10s');
return exec(`react-native init EndToEndTest --version ${PACKAGE}`).code;
},
numberOfRetries,
() => rm('-rf', 'EndToEndTest'))) {
echo('Failed to execute react-native init');
echo('Most common reason is npm registry connectivity, try again');
exitCode = 1;
throw Error(exitCode);
if (
tryExecNTimes(
() => {
exec('sleep 10s');
return exec(`react-native init EndToEndTest --version ${PACKAGE}`).code;
},
numberOfRetries,
() => rm('-rf', 'EndToEndTest'),
)
) {
echo('Failed to execute react-native init');
echo('Most common reason is npm registry connectivity, try again');
exitCode = 1;
throw Error(exitCode);
}
cd('EndToEndTest');
@@ -89,13 +106,20 @@ try {
if (argv.android) {
echo('Running an Android e2e test');
echo('Installing e2e framework');
if (tryExecNTimes(
() => exec('yarn add --dev appium@1.5.1 mocha@2.4.5 wd@0.3.11 colors@1.0.3 pretty-data2@0.40.1', { silent: true }).code,
numberOfRetries)) {
echo('Failed to install appium');
echo('Most common reason is npm registry connectivity, try again');
exitCode = 1;
throw Error(exitCode);
if (
tryExecNTimes(
() =>
exec(
'yarn add --dev appium@1.5.1 mocha@2.4.5 wd@0.3.11 colors@1.0.3 pretty-data2@0.40.1',
{silent: true},
).code,
numberOfRetries,
)
) {
echo('Failed to install appium');
echo('Most common reason is npm registry connectivity, try again');
exitCode = 1;
throw Error(exitCode);
}
cp(`${SCRIPTS}/android-e2e-test.js`, 'android-e2e-test.js');
cd('android');
@@ -108,7 +132,9 @@ try {
throw Error(exitCode);
}
cd('..');
exec('keytool -genkey -v -keystore android/keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"');
exec(
'keytool -genkey -v -keystore android/keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"',
);
echo(`Starting appium server, ${APPIUM_PID}`);
const appiumProcess = spawn('node', ['./node_modules/.bin/appium']);
@@ -124,27 +150,27 @@ try {
echo(`Starting packager server, ${SERVER_PID}`);
// shelljs exec('', {async: true}) does not emit stdout events, so we rely on good old spawn
const packagerProcess = spawn('yarn', ['start', '--max-workers 1'], {
env: process.env
env: process.env,
});
SERVER_PID = packagerProcess.pid;
// wait a bit to allow packager to startup
exec('sleep 15s');
echo('Executing android e2e test');
if (tryExecNTimes(
() => {
if (
tryExecNTimes(() => {
exec('sleep 10s');
return exec('node node_modules/.bin/_mocha android-e2e-test.js').code;
},
numberOfRetries)) {
echo('Failed to run Android e2e tests');
echo('Most likely the code is broken');
exitCode = 1;
throw Error(exitCode);
}, numberOfRetries)
) {
echo('Failed to run Android e2e tests');
echo('Most likely the code is broken');
exitCode = 1;
throw Error(exitCode);
}
}
if (argv.ios || argv.tvos) {
var iosTestType = (argv.tvos ? 'tvOS' : 'iOS');
var iosTestType = argv.tvos ? 'tvOS' : 'iOS';
echo('Running the ' + iosTestType + 'app');
cd('ios');
// Make sure we installed local version of react-native
@@ -156,43 +182,56 @@ try {
// shelljs exec('', {async: true}) does not emit stdout events, so we rely on good old spawn
const packagerEnv = Object.create(process.env);
packagerEnv.REACT_NATIVE_MAX_WORKERS = 1;
const packagerProcess = spawn('yarn', ['start', '--nonPersistent'],
{
stdio: 'inherit',
env: packagerEnv
});
const packagerProcess = spawn('yarn', ['start', '--nonPersistent'], {
stdio: 'inherit',
env: packagerEnv,
});
SERVER_PID = packagerProcess.pid;
exec('sleep 15s');
// prepare cache to reduce chances of possible red screen "Can't fibd variable __fbBatchedBridge..."
exec('response=$(curl --write-out %{http_code} --silent --output /dev/null localhost:8081/index.bundle?platform=ios&dev=true)');
exec(
'response=$(curl --write-out %{http_code} --silent --output /dev/null localhost:8081/index.bundle?platform=ios&dev=true)',
);
echo(`Starting packager server, ${SERVER_PID}`);
echo('Executing ' + iosTestType + ' e2e test');
if (tryExecNTimes(
() => {
if (
tryExecNTimes(() => {
exec('sleep 10s');
if (argv.tvos) {
return exec('xcodebuild -destination "platform=tvOS Simulator,name=Apple TV 1080p,OS=10.0" -scheme EndToEndTest-tvOS -sdk appletvsimulator test | xcpretty && exit ${PIPESTATUS[0]}').code;
return exec(
'xcodebuild -destination "platform=tvOS Simulator,name=Apple TV 1080p,OS=10.0" -scheme EndToEndTest-tvOS -sdk appletvsimulator test | xcpretty && exit ${PIPESTATUS[0]}',
).code;
} else {
return exec('xcodebuild -destination "platform=iOS Simulator,name=iPhone 5s,OS=10.3.1" -scheme EndToEndTest -sdk iphonesimulator test | xcpretty && exit ${PIPESTATUS[0]}').code;
return exec(
'xcodebuild -destination "platform=iOS Simulator,name=iPhone 5s,OS=10.3.1" -scheme EndToEndTest -sdk iphonesimulator test | xcpretty && exit ${PIPESTATUS[0]}',
).code;
}
},
numberOfRetries)) {
echo('Failed to run ' + iosTestType + ' e2e tests');
echo('Most likely the code is broken');
exitCode = 1;
throw Error(exitCode);
}, numberOfRetries)
) {
echo('Failed to run ' + iosTestType + ' e2e tests');
echo('Most likely the code is broken');
exitCode = 1;
throw Error(exitCode);
}
cd('..');
}
if (argv.js) {
// Check the packager produces a bundle (doesn't throw an error)
if (exec('react-native bundle --max-workers 1 --platform android --dev true --entry-file index.js --bundle-output android-bundle.js').code) {
if (
exec(
'react-native bundle --max-workers 1 --platform android --dev true --entry-file index.js --bundle-output android-bundle.js',
).code
) {
echo('Could not build Android bundle');
exitCode = 1;
throw Error(exitCode);
}
if (exec('react-native --max-workers 1 bundle --platform ios --dev true --entry-file index.js --bundle-output ios-bundle.js').code) {
if (
exec(
'react-native --max-workers 1 bundle --platform ios --dev true --entry-file index.js --bundle-output ios-bundle.js',
).code
) {
echo('Could not build iOS bundle');
exitCode = 1;
throw Error(exitCode);
@@ -209,7 +248,6 @@ try {
}
}
exitCode = 0;
} finally {
cd(ROOT);
rm(MARKER_IOS);

View File

@@ -3,6 +3,8 @@
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
/* globals echo:false */