diff --git a/packages/cli-test/src/cli/shell.spec.ts b/packages/cli-test/src/cli/shell.spec.ts index 69d0f15f0..6bc652096 100644 --- a/packages/cli-test/src/cli/shell.spec.ts +++ b/packages/cli-test/src/cli/shell.spec.ts @@ -72,6 +72,13 @@ describe('shell module', () => { sinon.match({ shell: true, env: fakeEnv }), ); }); + it('should return the command outputs unchanged', () => { + const fakeCmd = 'echo'; + const fakeArgs = ['"greetings"']; + const sh = shell.spawnProcess(fakeCmd, fakeArgs); + spawnProcess.stdout.emit('data', 'outputs\r\n'); + assert.equal(sh.output, 'outputs\r\n'); + }); it('should raise bubble error details up', () => { runSpy.throws(new Error('this is bat country')); assert.throw(() => { @@ -124,6 +131,15 @@ describe('shell module', () => { sinon.match({ shell: true, env: fakeEnv }), ); }); + it('should return the command outputs unchanged', () => { + const fakeCmd = 'echo'; + const fakeArgs = ['"greetings"']; + const sh = shell.spawnProcess(fakeCmd, fakeArgs); + spawnProcess.stdout.emit('data', 'outputs\r\n'); + spawnProcess.stderr.emit('data', 'warning\n'); + spawnProcess.stdout.emit('data', 'endings\r\n'); + assert.equal(sh.output, 'outputs\r\nwarning\nendings\r\n'); + }); it('should raise bubble error details up', () => { spawnSpy.throws(new Error('this is bat country')); assert.throw(() => { diff --git a/packages/cli-test/src/cli/shell.ts b/packages/cli-test/src/cli/shell.ts index 99354e606..cb0fd1585 100644 --- a/packages/cli-test/src/cli/shell.ts +++ b/packages/cli-test/src/cli/shell.ts @@ -42,15 +42,17 @@ export const shell = { // Listen to data event that returns all the output and collect it // biome-ignore lint/suspicious/noExplicitAny: stdout can accept a variety of data childProcess.stdout.on('data', (data: any) => { - sh.output += this.removeANSIcolors(data.toString()); - logger.verbose(`Output: ${this.removeANSIcolors(data.toString())}`); + const output = this.removeANSIcolors(data.toString()); + sh.output += output; + logger.verbose(`Output: ${output.replace(/\r?\n$/, '')}`); }); // Collect error output // biome-ignore lint/suspicious/noExplicitAny: stderr can accept a variety of data childProcess.stderr.on('data', (data: any) => { - sh.output += this.removeANSIcolors(data.toString()); - logger.error(`Error: ${this.removeANSIcolors(data.toString())}`); + const output = this.removeANSIcolors(data.toString()); + sh.output += output; + logger.error(`Error: ${output.replace(/\r?\n$/, '')}`); }); // Set the finished flag to true on close event