Skip to content

Commit fbc1499

Browse files
authored
Reduce test-suite log noise, always surface output on failure (#19)
Passing stdout/stderr straight through to the console for every child process (npm/pod installs, expo/RN CLI invocations, bundling) buries the handful of log lines that actually matter under megabytes of routine install output, making CI logs painful to read. Silence stdout (and, for a few especially noisy commands, stderr) on the success path with noLogStdOut/noLogStdErr. Doing that exposed a latent bug in getProcessOutput: on failure it only printed the error object, honoring noLogStdErr even for failures - so a silenced failing command left no way to diagnose why it failed. Fix it to always print the error plus full stdout/stderr on failure, regardless of the noLog flags.
1 parent 307b43a commit fbc1499

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

code-push-plugin-testing-framework/script/testUtil.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ var TestUtil = (function () {
5555
var execProcess = child_process.exec(command, options, function (error, stdout, stderr) {
5656
console.log("[TIMING] exec \"" + timingLabel + "\" took " + (Date.now() - timingStart) + "ms");
5757
if (error) {
58-
if (!options.noLogStdErr)
59-
console.error("" + error);
58+
console.error("" + error);
59+
// Only dump the buffered output here if it was silenced on the success path
60+
// above - otherwise it was already live-piped to the console as it streamed,
61+
// and re-printing it here would just duplicate (and potentially reorder) it.
62+
if (options.noLogStdOut && stdout)
63+
console.error("\n----- stdout -----\n" + stdout);
64+
if (options.noLogStdErr && stderr)
65+
console.error("\n----- stderr -----\n" + stderr);
6066
deferred.reject(error);
6167
}
6268
else {
@@ -68,8 +74,7 @@ var TestUtil = (function () {
6874
if (!options.noLogStdErr)
6975
execProcess.stderr.pipe(process.stderr);
7076
execProcess.on('error', function (error) {
71-
if (!options.noLogStdErr)
72-
console.error("" + error);
77+
console.error("" + error);
7378
deferred.reject(error);
7479
});
7580
return deferred.promise;

test/test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function installExpoBundleTooling(projectPath: string): Q.Promise<void> {
4646

4747
return TestUtil.getProcessOutput(
4848
`npm install --save-dev @react-native/metro-config@${reactNativeVersion}`,
49-
{ cwd: projectPath }
49+
{ cwd: projectPath, noLogStdOut: true }
5050
).then(() => { return null; });
5151
}
5252

@@ -231,7 +231,7 @@ class RNIOS extends Platform.IOS implements RNPlatform {
231231
} else {
232232
// Install the Podfile
233233
return TestUtil.copyFile(path.join(TestConfig.templatePath, "ios", "Podfile"), podfilePath, true)
234-
.then(() => TestUtil.getProcessOutput(`pod install`, { cwd: iOSProject }))
234+
.then(() => TestUtil.getProcessOutput(`pod install`, { cwd: iOSProject, noLogStdOut: true }))
235235
// Put the IOS deployment key in the Info.plist
236236
.then(TestUtil.replaceString.bind(undefined, infoPlistPath,
237237
"</dict>\n</plist>",
@@ -366,23 +366,23 @@ class RNProjectManager extends ProjectManager {
366366
mkdirp.sync(projectDirectory);
367367

368368
if (TestConfig.isExpoApp) {
369-
return TestUtil.getProcessOutput(`npx create-expo-app@latest ${appName} --template blank@sdk-55`, { cwd: projectDirectory, timeout: 30 * 60 * 1000 })
369+
return TestUtil.getProcessOutput(`npx create-expo-app@latest ${appName} --template blank@sdk-55`, { cwd: projectDirectory, timeout: 30 * 60 * 1000, noLogStdOut: true })
370370
.then((e) => { console.log(`"npx expo init ${appName}" success. cwd=${projectDirectory}`); return e; })
371371
.then(this.copyTemplate.bind(this, templatePath, projectDirectory))
372-
.then<void>(TestUtil.getProcessOutput.bind(undefined, TestConfig.thisPluginInstallString, { cwd: path.join(projectDirectory, TestConfig.TestAppName) }))
372+
.then<void>(TestUtil.getProcessOutput.bind(undefined, TestConfig.thisPluginInstallString, { cwd: path.join(projectDirectory, TestConfig.TestAppName), noLogStdOut: true, noLogStdErr: true }))
373373
.then(installExpoBundleTooling.bind(undefined, path.join(projectDirectory, TestConfig.TestAppName)))
374-
.then<void>(TestUtil.getProcessOutput.bind(undefined, "npx expo install expo-build-properties", { cwd: path.join(projectDirectory, TestConfig.TestAppName) }))
375-
.then(TestUtil.getProcessOutput.bind(undefined, `npx expo prebuild --clean`, { cwd: path.join(projectDirectory, TestConfig.TestAppName) }))
374+
.then<void>(TestUtil.getProcessOutput.bind(undefined, "npx expo install expo-build-properties", { cwd: path.join(projectDirectory, TestConfig.TestAppName), noLogStdOut: true }))
375+
.then(TestUtil.getProcessOutput.bind(undefined, `npx expo prebuild --clean`, { cwd: path.join(projectDirectory, TestConfig.TestAppName), noLogStdOut: true }))
376376
.then(() => {
377377
ensureAndroidCleartextTraffic(path.join(projectDirectory, TestConfig.TestAppName, "android", "app", "src", "main", "AndroidManifest.xml"));
378378
return null;
379379
})
380380
.then(() => { return null; });
381381
} else {
382-
return TestUtil.getProcessOutput("npx @react-native-community/cli init " + appName + " --version 0.86.2 --install-pods", { cwd: projectDirectory, timeout: 30 * 60 * 1000 })
382+
return TestUtil.getProcessOutput("npx @react-native-community/cli init " + appName + " --version 0.86.2 --install-pods", { cwd: projectDirectory, timeout: 30 * 60 * 1000, noLogStdOut: true })
383383
.then((e) => { console.log(`"npx @react-native-community/cli init ${appName}" success. cwd=${projectDirectory}`); return e; })
384384
.then(this.copyTemplate.bind(this, templatePath, projectDirectory))
385-
.then<void>(TestUtil.getProcessOutput.bind(undefined, TestConfig.thisPluginInstallString, { cwd: path.join(projectDirectory, TestConfig.TestAppName) }))
385+
.then<void>(TestUtil.getProcessOutput.bind(undefined, TestConfig.thisPluginInstallString, { cwd: path.join(projectDirectory, TestConfig.TestAppName), noLogStdOut: true, noLogStdErr: true }))
386386
.then(() => { return null; })
387387
.catch((error) => {
388388
console.log(`"npx @react-native-community/cli init ${appName} failed". cwd=${projectDirectory}`, error);
@@ -466,7 +466,7 @@ class RNProjectManager extends ProjectManager {
466466
} else {
467467
return deferred.promise
468468
.then(TestUtil.getProcessOutput.bind(undefined, "npx react-native bundle --entry-file index.js --platform " + targetPlatform.getName() + " --bundle-output " + bundlePath + " --assets-dest " + bundleFolder + " --dev false",
469-
{ cwd: path.join(projectDirectory, TestConfig.TestAppName) }))
469+
{ cwd: path.join(projectDirectory, TestConfig.TestAppName), noLogStdOut: true }))
470470
.then<string>(TestUtil.archiveFolder.bind(undefined, bundleFolder, "", path.join(projectDirectory, TestConfig.TestAppName, "update.zip"), isDiff))
471471
.then((result) => { console.log(`[TIMING] createUpdateArchive(${projectDirectory}, ${targetPlatform.getName()}) took ${Date.now() - t0}ms`); return result; });
472472
}

0 commit comments

Comments
 (0)