Skip to content

Commit

Permalink
test(wpt): handle uncaught exceptions (#1965)
Browse files Browse the repository at this point in the history
  • Loading branch information
KhafraDev committed Feb 23, 2023
1 parent 178a97c commit 0faf03e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/wpt/runner/runner/runner.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export class WPTRunner extends EventEmitter {
/** Tests that have expectedly failed mapped by file name */
#statusOutput = {}

#uncaughtExceptions = []

#stats = {
completed: 0,
failed: 0,
Expand Down Expand Up @@ -58,6 +60,13 @@ export class WPTRunner extends EventEmitter {
this.emit('completion')
})
}

this.once('completion', () => {
for (const exception of this.#uncaughtExceptions) {
console.log(colors(`Uncaught exception: ${exception.stack}`, 'red'))
console.log('='.repeat(96))
}
})
}

static walk (dir, fn) {
Expand Down Expand Up @@ -148,6 +157,10 @@ export class WPTRunner extends EventEmitter {
this.handleIndividualTestCompletion(message, status, test)
} else if (message.type === 'completion') {
this.handleTestCompletion(worker)
} else if (message.type === 'error') {
this.#uncaughtExceptions.push(message.error)
this.#stats.failed += 1
this.#stats.success -= 1
}
})

Expand Down Expand Up @@ -196,7 +209,7 @@ export class WPTRunner extends EventEmitter {
if (!file.allowUnexpectedFailures && !topLevel.allowUnexpectedFailures) {
if (Array.isArray(file.fail)) {
this.#statusOutput[path] ??= []
this.#statusOutput[path].push(file.fail)
this.#statusOutput[path].push(name)
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/wpt/runner/runner/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,17 @@ import { CloseEvent } from '../../../../lib/websocket/events.js'

const { initScripts, meta, test, url, path } = workerData

process.on('uncaughtException', (err) => {
parentPort.postMessage({
type: 'error',
error: {
message: err.message,
name: err.name,
stack: err.stack
}
})
})

const basePath = join(process.cwd(), 'test/wpt/tests')
const urlPath = path.slice(basePath.length)

Expand Down
1 change: 1 addition & 0 deletions test/wpt/tests/fetch/api/abort/general.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ promise_test(async t => {
const fetchPromise = fetch('../resources/empty.txt', {
body, signal,
method: 'POST',
duplex: 'half',
headers: {
'Content-Type': 'text/plain'
}
Expand Down

0 comments on commit 0faf03e

Please sign in to comment.