From f03fef085d050128c1b1d9a072a683efe28f2513 Mon Sep 17 00:00:00 2001 From: Adam A Date: Thu, 11 Jan 2024 22:55:11 +0200 Subject: [PATCH] feat(1.6): report uncaught exceptions and unhandled rejections --- ensuite.mjs | 19 +++++++++++++------ package.json | 2 +- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ensuite.mjs b/ensuite.mjs index fceb478..0c144db 100644 --- a/ensuite.mjs +++ b/ensuite.mjs @@ -9,6 +9,14 @@ main(...process.argv.slice(2)) export async function main (root = process.cwd(), ...specs) { + // Handle exceptions and rejections + process.on('uncaughtExceptionMonitor', (error, origin) => { + console.warn('Uncaught exception:', { error, origin }) + }) + process.on('unhandledRejection', (reason, promise) => { + console.warn('Unhandled promise rejection:', { reason, promise }) + }) + // If tests don't exit, press "?" to see why if (process.env.ENSUITE_WHY) { if (process.stdin.setRawMode) process.stdin.setRawMode(true) @@ -24,15 +32,14 @@ export async function main (root = process.cwd(), ...specs) { }) } - // Run tests + // Load and run tests const index = resolve(process.cwd(), root) const { default: suite } = await import(index) if (resolve(process.argv[2]) === index) { - await new Promise(resolve=>{ - setImmediate(async ()=>{ - await Promise.resolve(suite.run({ argv: process.argv.slice(3) })) - resolve() - }) + await new Promise((resolve, reject)=>{ + setImmediate(()=>Promise.resolve(suite.run({ + argv: process.argv.slice(3) + })).then(resolve, reject)) }) } diff --git a/package.json b/package.json index 7c4033e..fb60e42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hackbg/ensuite", - "version": "1.5.4", + "version": "1.6.0", "main": "ensuite.mjs", "type": "module", "types": "ensuite.d.ts",