Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't override errored state on close event #461

Merged
merged 1 commit into from
Jan 11, 2024
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
8 changes: 8 additions & 0 deletions src/command.spec.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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