Skip to content

Commit e65e5bb

Browse files
committed
fix test runner: properly catch unhandled exceptions/rejections & exit process
previously, if some error occurred, would just continue running, unless: a) a node arg `--unhandled-rejections=strict` was specified, or b) node version was >= 15 (but would get stuck, instead of exiting properly) for A, see: https://nodejs.org/api/cli.html#--unhandled-rejectionsmode now, always exits properly.
1 parent e1f1b19 commit e65e5bb

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

test/run.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import { cleanupTmpRepos } from "./util/tmpdir";
1111

1212
main();
1313
function main() {
14+
process.on("uncaughtException", (e) => {
15+
printErrorAndExit(e);
16+
});
17+
18+
process.on("unhandledRejection", (e) => {
19+
printErrorAndExit(e);
20+
});
21+
1422
// TODO Promise.all
1523
sequentialResolve([
1624
testCase, //
@@ -24,8 +32,15 @@ function main() {
2432
process.stdout.write("\nsuccess\n\n");
2533
process.exit(0);
2634
})
27-
.catch((e) => {
28-
process.stderr.write("\nfailure: " + e + "\n\n");
29-
process.exit(1);
30-
});
35+
.catch(printErrorAndExit);
36+
}
37+
38+
function printErrorAndExit(e: unknown) {
39+
console.error(e);
40+
41+
console.log("\nfull trace:");
42+
console.trace(e);
43+
44+
process.stdout.write("\nfailure\n\n");
45+
process.exit(1);
3146
}

0 commit comments

Comments
 (0)