Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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$/, '')}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking it to the next level with \r? 🪟

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course - always keeping the cartridge return in mind! But only sometimes 😉

});

// 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