Merge pull request #33119 from backstage/freben/cli-common-runcheck-stdio-ignore

Fix runCheck to ignore stdio of spawned process
This commit is contained in:
Fredrik Adelöw
2026-03-04 19:48:19 +01:00
committed by GitHub
3 changed files with 27 additions and 1 deletions
@@ -0,0 +1,5 @@
---
'@backstage/cli-common': patch
---
Fixed `runCheck` to ignore stdio of the spawned process, preventing unwanted output from leaking to the terminal.
+21
View File
@@ -338,5 +338,26 @@ describe('run', () => {
const result = await runCheck(['nonexistent-command-12345']);
expect(result).toBe(false);
});
it('should not leak stdout or stderr from the child process', async () => {
const stdoutSpy = jest.spyOn(process.stdout, 'write');
const stderrSpy = jest.spyOn(process.stderr, 'write');
const stdoutBefore = stdoutSpy.mock.calls.length;
const stderrBefore = stderrSpy.mock.calls.length;
await runCheck([
'node',
'--eval',
'console.log("leaked stdout"); console.error("leaked stderr")',
]);
const stdoutCalls = stdoutSpy.mock.calls.slice(stdoutBefore);
const stderrCalls = stderrSpy.mock.calls.slice(stderrBefore);
const stdout = stdoutCalls.map(c => String(c[0])).join('');
const stderr = stderrCalls.map(c => String(c[0])).join('');
expect(stdout).not.toContain('leaked stdout');
expect(stderr).not.toContain('leaked stderr');
});
});
});
+1 -1
View File
@@ -211,7 +211,7 @@ export async function runOutput(
*/
export async function runCheck(args: string[]): Promise<boolean> {
try {
await run(args).waitForExit();
await run(args, { stdio: 'ignore' }).waitForExit();
return true;
} catch {
return false;