Skip to content

Commit

Permalink
feat(1.6): report uncaught exceptions and unhandled rejections
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed Jan 11, 2024
1 parent 26a75e6 commit f03fef0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
19 changes: 13 additions & 6 deletions ensuite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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))
})
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hackbg/ensuite",
"version": "1.5.4",
"version": "1.6.0",
"main": "ensuite.mjs",
"type": "module",
"types": "ensuite.d.ts",
Expand Down

0 comments on commit f03fef0

Please sign in to comment.