Skip to content

Commit cebe424

Browse files
authored
test_runner: fix suite diagnostic chanel end
Signed-off-by: Moshe Atlow <moshe@atlow.co.il> PR-URL: #63533 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 85d4a5f commit cebe424

2 files changed

Lines changed: 33 additions & 7 deletions

File tree

lib/internal/test_runner/test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,15 +1812,22 @@ class Suite extends Test {
18121812
publishError(err);
18131813
}
18141814
this.fail(new ERR_TEST_FAILURE(err, kTestCodeFailure));
1815-
} finally {
1816-
if (testChannel.end.hasSubscribers) {
1817-
publishEnd();
1818-
}
18191815
}
18201816

1817+
this.#publishEnd = publishEnd;
18211818
this.buildPhaseFinished = true;
18221819
}
18231820

1821+
#publishEnd = null;
1822+
1823+
#publishSuiteEnd() {
1824+
const publishEnd = this.#publishEnd;
1825+
this.#publishEnd = null;
1826+
if (publishEnd !== null && testChannel.end.hasSubscribers) {
1827+
publishEnd();
1828+
}
1829+
}
1830+
18241831
#ctx;
18251832
getCtx() {
18261833
this.#ctx ??= new TestContext(this);
@@ -1872,6 +1879,7 @@ class Suite extends Test {
18721879
}
18731880
} finally {
18741881
stopPromise?.[SymbolDispose]();
1882+
this.#publishSuiteEnd();
18751883
}
18761884

18771885
this.postRun();

test/parallel/test-runner-diagnostics-channel.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ const { join } = require('path');
99

1010
const events = [];
1111

12-
dc.subscribe('tracing:node.test:start', (data) => events.push({ event: 'start', name: data.name }));
13-
dc.subscribe('tracing:node.test:end', (data) => events.push({ event: 'end', name: data.name }));
14-
dc.subscribe('tracing:node.test:error', (data) => events.push({ event: 'error', name: data.name }));
12+
dc.subscribe('tracing:node.test:start', (data) => events.push({ event: 'start', name: data.name, type: data.type }));
13+
dc.subscribe('tracing:node.test:end', (data) => events.push({ event: 'end', name: data.name, type: data.type }));
14+
dc.subscribe('tracing:node.test:error', (data) => events.push({ event: 'error', name: data.name, type: data.type }));
15+
16+
describe('suite end ordering', () => {
17+
it('child a', async () => { await new Promise((r) => setTimeout(r, 5)); });
18+
it('child b', () => {});
19+
});
1520

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

@@ -54,6 +59,19 @@ process.on('exit', () => {
5459
const asyncEnd = events.filter((e) => e.event === 'end' && e.name === asyncTestName);
5560
assert.strictEqual(asyncStart.length, 1);
5661
assert.strictEqual(asyncEnd.length, 1);
62+
63+
const suiteNames = new Set(['suite end ordering', 'child a', 'child b']);
64+
const suiteSequence = events
65+
.filter((e) => suiteNames.has(e.name))
66+
.map((e) => `${e.event}:${e.name}`);
67+
assert.deepStrictEqual(suiteSequence, [
68+
'start:suite end ordering',
69+
'start:child a',
70+
'end:child a',
71+
'start:child b',
72+
'end:child b',
73+
'end:suite end ordering',
74+
]);
5775
});
5876

5977
// Test bindStore context propagation

0 commit comments

Comments
 (0)