Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 5 additions & 53 deletions test/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,15 @@ class RNAndroid extends Platform.Android implements RNPlatform {
return TestUtil.getProcessOutput("adb install -r " + this.getBinaryPath(projectDirectory), { cwd: androidDirectory }).then(() => { return null; });
}

/**
* Build function of the test application, the command depends on the OS
*/
buildFunction(androidDirectory: string): Q.Promise<void> {

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just inline this to the 1 remaining callsite

const gradlewCommand = process.platform === "darwin" || process.platform === "linux" ? "./gradlew" : "gradlew";
return TestUtil.getProcessOutput(`${gradlewCommand} assembleRelease`, { noLogStdOut: true, cwd: androidDirectory })
.then(() => { return null; });
}

/**
* Builds the binary of the project on this platform.
*/
buildApp(projectDirectory: string): Q.Promise<void> {
// In order to run on Android without the package manager, we must create a release APK and then sign it with the debug certificate.
const androidDirectory: string = path.join(projectDirectory, TestConfig.TestAppName, "android");
// If the build fails for the first time, try rebuild app again
try {
return this.buildFunction(androidDirectory);
} catch {
return this.buildFunction(androidDirectory);
}
const gradlewCommand = process.platform === "darwin" || process.platform === "linux" ? "./gradlew" : "gradlew";
return TestUtil.getProcessOutput(`${gradlewCommand} assembleRelease`, { noLogStdOut: true, cwd: androidDirectory })
.then(() => { return null; });
}
}

Expand Down Expand Up @@ -280,19 +268,6 @@ class RNIOS extends Platform.IOS implements RNPlatform {
return TestUtil.getProcessOutput("xcrun simctl install booted " + this.getBinaryPath(projectDirectory)).then(() => { return null; });
}

/**
* Maps project directories to whether or not they have built an IOS project before.
*
* The first build of an IOS project does not always succeed, so we always try again when it fails.
*
* EXAMPLE:
* {
* "TEMP_DIR/test-run": true,
* "TEMP_DIR/updates": false
* }
*/
private static iosFirstBuild: any = {};

/**
* Maps project directories to whether or not a real `xcodebuild` has completed for them yet.
* Once true, subsequent scenario switches only need their JS bundle re-packaged, not a full
Expand All @@ -310,15 +285,7 @@ class RNIOS extends Platform.IOS implements RNPlatform {
}
return this.realBuildApp(projectDirectory)
.then(() => {
// realBuildApp can resolve even after a failed build (it swallows a failed
// retry into a resolved null - pre-existing behavior, unchanged here). Only
// mark this project as built if the .app it's supposed to have produced
// actually exists, so a swallowed failure doesn't cause every subsequent
// scenario switch to bundleOnly against a missing/stale binary - the next
// buildApp call will instead retry a real xcodebuild.
if (fs.existsSync(this.getBinaryPath(projectDirectory))) {
RNIOS.hasBuiltOnce[projectDirectory] = true;
}
RNIOS.hasBuiltOnce[projectDirectory] = true;
});
}

Expand Down Expand Up @@ -363,22 +330,7 @@ class RNIOS extends Platform.IOS implements RNPlatform {
return TestUtil.getProcessOutput("xcodebuild -workspace " + path.join(iOSProject, TestConfig.TestAppName) + ".xcworkspace -scheme " + TestConfig.TestAppName +
" -configuration Release -destination \"platform=iOS Simulator,id=" + targetEmulator + "\" -derivedDataPath build", { cwd: iOSProject, timeout: 10 * 60 * 1000, maxBuffer: 1024 * 1024 * 5000, noLogStdOut: true });
})
.then<void>(
() => { return null; },
(error: any) => {
console.info(error);
// The first time an iOS project is built, it fails because it does not finish building libReact.a before it builds the test app.
// Simply build again to fix the issue.
if (!RNIOS.iosFirstBuild[projectDirectory]) {
const iosBuildFolder = path.join(iOSProject, "build");
if (fs.existsSync(iosBuildFolder)) {
del.sync([iosBuildFolder], { force: true });
}
RNIOS.iosFirstBuild[projectDirectory] = true;
return this.realBuildApp(projectDirectory);
}
return null;
});
.then<void>(() => { return null; });
}
}

Expand Down