Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/internal/test_runner/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1812,15 +1812,22 @@ class Suite extends Test {
publishError(err);
}
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
} finally {
if (testChannel.end.hasSubscribers) {
publishEnd();
}
}

this.#publishEnd = publishEnd;
this.buildPhaseFinished = true;
}

#publishEnd = null;

#publishSuiteEnd() {
const publishEnd = this.#publishEnd;
this.#publishEnd = null;
if (publishEnd !== null && testChannel.end.hasSubscribers) {
publishEnd();
}
}

#ctx;
getCtx() {
this.#ctx ??= new TestContext(this);
Expand Down Expand Up @@ -1872,6 +1879,7 @@ class Suite extends Test {
}
} finally {
stopPromise?.[SymbolDispose]();
this.#publishSuiteEnd();
}

this.postRun();
Expand Down
24 changes: 21 additions & 3 deletions test/parallel/test-runner-diagnostics-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const { join } = require('path');

const events = [];

dc.subscribe('tracing:node.test:start', (data) => events.push({ event: 'start', name: data.name }));
dc.subscribe('tracing:node.test:end', (data) => events.push({ event: 'end', name: data.name }));
dc.subscribe('tracing:node.test:error', (data) => events.push({ event: 'error', name: data.name }));
dc.subscribe('tracing:node.test:start', (data) => events.push({ event: 'start', name: data.name, type: data.type }));
dc.subscribe('tracing:node.test:end', (data) => events.push({ event: 'end', name: data.name, type: data.type }));
dc.subscribe('tracing:node.test:error', (data) => events.push({ event: 'error', name: data.name, type: data.type }));
Comment thread
MoLow marked this conversation as resolved.

describe('suite end ordering', () => {
it('child a', async () => { await new Promise((r) => setTimeout(r, 5)); });
it('child b', () => {});
});

test('passing test fires start and end', async () => {});

Expand Down Expand Up @@ -54,6 +59,19 @@ process.on('exit', () => {
const asyncEnd = events.filter((e) => e.event === 'end' && e.name === asyncTestName);
assert.strictEqual(asyncStart.length, 1);
assert.strictEqual(asyncEnd.length, 1);

const suiteNames = new Set(['suite end ordering', 'child a', 'child b']);
const suiteSequence = events
.filter((e) => suiteNames.has(e.name))
.map((e) => `${e.event}:${e.name}`);
assert.deepStrictEqual(suiteSequence, [
'start:suite end ordering',
'start:child a',
'end:child a',
'start:child b',
'end:child b',
'end:suite end ordering',
]);
});

// Test bindStore context propagation
Expand Down
Loading