Skip to content

Commit 2874654

Browse files
authored
fix(cli-test): remove the trailing newline from parsed cli outputs (#2148)
1 parent 8e5b06d commit 2874654

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

packages/cli-test/src/cli/shell.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ describe('shell module', () => {
7272
sinon.match({ shell: true, env: fakeEnv }),
7373
);
7474
});
75+
it('should return the command outputs unchanged', () => {
76+
const fakeCmd = 'echo';
77+
const fakeArgs = ['"greetings"'];
78+
const sh = shell.spawnProcess(fakeCmd, fakeArgs);
79+
spawnProcess.stdout.emit('data', 'outputs\r\n');
80+
assert.equal(sh.output, 'outputs\r\n');
81+
});
7582
it('should raise bubble error details up', () => {
7683
runSpy.throws(new Error('this is bat country'));
7784
assert.throw(() => {
@@ -124,6 +131,15 @@ describe('shell module', () => {
124131
sinon.match({ shell: true, env: fakeEnv }),
125132
);
126133
});
134+
it('should return the command outputs unchanged', () => {
135+
const fakeCmd = 'echo';
136+
const fakeArgs = ['"greetings"'];
137+
const sh = shell.spawnProcess(fakeCmd, fakeArgs);
138+
spawnProcess.stdout.emit('data', 'outputs\r\n');
139+
spawnProcess.stderr.emit('data', 'warning\n');
140+
spawnProcess.stdout.emit('data', 'endings\r\n');
141+
assert.equal(sh.output, 'outputs\r\nwarning\nendings\r\n');
142+
});
127143
it('should raise bubble error details up', () => {
128144
spawnSpy.throws(new Error('this is bat country'));
129145
assert.throw(() => {

packages/cli-test/src/cli/shell.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ export const shell = {
4242
// Listen to data event that returns all the output and collect it
4343
// biome-ignore lint/suspicious/noExplicitAny: stdout can accept a variety of data
4444
childProcess.stdout.on('data', (data: any) => {
45-
sh.output += this.removeANSIcolors(data.toString());
46-
logger.verbose(`Output: ${this.removeANSIcolors(data.toString())}`);
45+
const output = this.removeANSIcolors(data.toString());
46+
sh.output += output;
47+
logger.verbose(`Output: ${output.replace(/\r?\n$/, '')}`);
4748
});
4849

4950
// Collect error output
5051
// biome-ignore lint/suspicious/noExplicitAny: stderr can accept a variety of data
5152
childProcess.stderr.on('data', (data: any) => {
52-
sh.output += this.removeANSIcolors(data.toString());
53-
logger.error(`Error: ${this.removeANSIcolors(data.toString())}`);
53+
const output = this.removeANSIcolors(data.toString());
54+
sh.output += output;
55+
logger.error(`Error: ${output.replace(/\r?\n$/, '')}`);
5456
});
5557

5658
// Set the finished flag to true on close event

0 commit comments

Comments
 (0)