Skip to content

Commit

Permalink
Don't override errored state on close event (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavohenke committed Jan 11, 2024
1 parent a2e5b19 commit aedebc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/command.spec.ts
Expand Up @@ -151,6 +151,14 @@ describe('#start()', () => {
expect(command.state).toBe('exited');
});

it('does not change state if there was an error', () => {
const { command } = createCommand();
command.start();
process.emit('error', 'foo');
process.emit('close', 0, null);
expect(command.state).toBe('errored');
});

it('shares start and close timing events to the timing stream', async () => {
const { command, values } = createCommand();
const startDate = new Date();
Expand Down
6 changes: 5 additions & 1 deletion src/command.ts
Expand Up @@ -169,7 +169,11 @@ export class Command implements CommandInfo {
.pipe(Rx.map((event) => event as [number | null, NodeJS.Signals | null]))
.subscribe(([exitCode, signal]) => {
this.process = undefined;
this.state = 'exited';

// Don't override error event
if (this.state !== 'errored') {
this.state = 'exited';
}

const endDate = new Date(Date.now());
this.timer.next({ startDate, endDate });
Expand Down

0 comments on commit aedebc1

Please sign in to comment.