Skip to content

Commit

Permalink
Core: Add memory to the error event to allow late event listeners
Browse files Browse the repository at this point in the history
Cherry-picked from 15acb36 (3.0.0-dev).
> HTML Reporter: Add support for displaying early errors
> Ref #1786.
  • Loading branch information
Krinkle committed Jan 26, 2025
1 parent 01f7780 commit 7c2f871
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const SUPPORTED_EVENTS = [
'runEnd'
];
const MEMORY_EVENTS = [
'error',
'runEnd'
];

Expand Down Expand Up @@ -40,7 +41,7 @@ export function emit (eventName, data) {
callbacks[i](data);
}

if (inArray(MEMORY_EVENTS, eventName)) {
if (inArray(eventName, MEMORY_EVENTS)) {
config._event_memory[eventName] = data;
}
}
Expand Down
26 changes: 26 additions & 0 deletions test/cli/fixtures/event-error-memory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
QUnit.on('error', function (error) {
console.log(`# early error ${error}`);

Promise.resolve().then(function () {
QUnit.on('error', function (error) {
console.log(`# late error ${error}`);
});
});
});

setTimeout(function () {
boom(); // eslint-disable-line
});

QUnit.module('First', function () {
QUnit.test('A', function (assert) {
assert.true(true);
});
QUnit.test('B', function (assert) {
const done = assert.async();
setTimeout(function () {
assert.true(true);
done();
});
});
});
24 changes: 24 additions & 0 deletions test/cli/fixtures/event-error-memory.tap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# command: ["qunit", "event-error-memory.js"]

TAP version 13
not ok 1 global failure
---
message: ReferenceError: boom is not defined
severity: failed
stack: |
ReferenceError: boom is not defined
at /qunit/test/cli/fixtures/event-error-memory.js:12:3
at internal
...
Bail out! ReferenceError: boom is not defined
# early error ReferenceError: boom is not defined
# late error ReferenceError: boom is not defined
ok 2 First > A
ok 3 First > B
1..3
# pass 2
# skip 0
# todo 0
# fail 1

# exit code: 1

0 comments on commit 7c2f871

Please sign in to comment.