Skip to content

Commit 1d4a031

Browse files
alan-agius4clydin
authored andcommitted
test: don't show stderr and stdout multiple times durning errors
Previously, the stderr and stdout were displayed multiple times, This caused a lot of bloat in the output. (cherry picked from commit b7193d2)
1 parent 034dea1 commit 1d4a031

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

tests/legacy-cli/e2e/utils/process.ts

+29-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as ansiColors from 'ansi-colors';
2-
import { SpawnOptions } from 'child_process';
2+
import { spawn, SpawnOptions } from 'child_process';
33
import * as child_process from 'child_process';
44
import { concat, defer, EMPTY, from } from 'rxjs';
55
import { repeat, takeLast } from 'rxjs/operators';
@@ -121,7 +121,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
121121
.forEach((line) => console.error(colors.yellow(' ' + line)));
122122
});
123123

124-
childProcess.on('close', (code: number) => {
124+
childProcess.on('close', (code) => {
125125
_processes = _processes.filter((p) => p !== childProcess);
126126

127127
if (options.waitForMatch && !matched) {
@@ -371,7 +371,7 @@ export function silentGit(...args: string[]) {
371371
* the PATH variable only referencing the local node_modules and local NPM
372372
* registry (not the test runner or standard global node_modules).
373373
*/
374-
export async function launchTestProcess(entry: string, ...args: any[]) {
374+
export async function launchTestProcess(entry: string, ...args: any[]): Promise<void> {
375375
const tempRoot: string = getGlobalVariable('tmp-root');
376376

377377
// Extract explicit environment variables for the test process.
@@ -382,13 +382,30 @@ export async function launchTestProcess(entry: string, ...args: any[]) {
382382
};
383383

384384
// Modify the PATH environment variable...
385-
let paths = (env.PATH || process.env.PATH)!.split(delimiter);
386-
387-
// Only include paths within the sandboxed test environment or external
388-
// non angular-cli paths such as /usr/bin for generic commands.
389-
paths = paths.filter((p) => p.startsWith(tempRoot) || !p.includes('angular-cli'));
390-
391-
env.PATH = paths.join(delimiter);
392-
393-
return _exec({ env }, process.execPath, [resolve(__dirname, 'run_test_process'), entry, ...args]);
385+
env.PATH = (env.PATH || process.env.PATH)
386+
?.split(delimiter)
387+
// Only include paths within the sandboxed test environment or external
388+
// non angular-cli paths such as /usr/bin for generic commands.
389+
.filter((p) => p.startsWith(tempRoot) || !p.includes('angular-cli'))
390+
.join(delimiter);
391+
392+
const testProcessArgs = [resolve(__dirname, 'run_test_process'), entry, ...args];
393+
394+
return new Promise<void>((resolve, reject) => {
395+
spawn(process.execPath, testProcessArgs, {
396+
stdio: 'inherit',
397+
env,
398+
})
399+
.on('close', (code) => {
400+
if (!code) {
401+
resolve();
402+
return;
403+
}
404+
405+
reject(`Process error - "${testProcessArgs}`);
406+
})
407+
.on('error', (err) => {
408+
reject(`Process exit error - "${testProcessArgs}]\n\n${err}`);
409+
});
410+
});
394411
}

0 commit comments

Comments
 (0)