Skip to content

Commit

Permalink
fix(cli-test): remove the trailing newline from parsed cli outputs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zimeg authored Feb 12, 2025
1 parent 8e5b06d commit 2874654
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 16 additions & 0 deletions packages/cli-test/src/cli/shell.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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(() => {
Expand Down
10 changes: 6 additions & 4 deletions packages/cli-test/src/cli/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2874654

Please sign in to comment.