Skip to content

Commit

Permalink
fix: prevent premature exit of test suites (#660)
Browse files Browse the repository at this point in the history
fix: prevent premature exit of test suite
  • Loading branch information
wellwelwel authored Aug 7, 2024
1 parent fc26a20 commit 46d068a
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/modules/helpers/exit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { format } from '../../services/format.js';
import { Write } from '../../services/write.js';
import { fileResults, finalResults } from '../../configs/files.js';
import { parseTime, parseTimeToSecs } from '../../parsers/time.js';
import { AssertionError } from 'node:assert';

export const exit = (code: Code, quiet?: boolean): never => {
export const exit = (code: Code, quiet?: boolean) => {
const isPoku = results.success > 0 || results.fail > 0;
const success = ` PASS › ${results.success - results.skip || 0} `;
const failure = ` FAIL › ${results.fail} `;
Expand Down Expand Up @@ -59,17 +60,23 @@ export const exit = (code: Code, quiet?: boolean): never => {
);
});

process.exit(code === 0 ? 0 : 1);
process.exitCode = code === 0 ? 0 : 1;
};

/* c8 ignore next 4 */ // Unknown external error
process.on('unhandledRejection', (reason) => {
console.error('unhandledRejection', reason);
process.exit(1);
/* c8 ignore start */ // Unknown external error
process.on('unhandledRejection', (err) => {
if (!(err instanceof AssertionError)) {
console.error('unhandledRejection', err);
}

process.exitCode = 1;
});

/* c8 ignore next 4 */ // Unknown external error
process.on('uncaughtException', (err) => {
console.error('uncaughtException', err);
process.exit(1);
if (!(err instanceof AssertionError)) {
console.error('uncaughtException', err);
}

process.exitCode = 1;
});
/* c8 ignore stop */

0 comments on commit 46d068a

Please sign in to comment.