Skip to content

Commit ae29501

Browse files
committed
test_runner: cover non-randomized cancelled subtest report order
1 parent cd9a8ee commit ae29501

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import test from 'node:test';
2+
import { setTimeout as sleep } from 'node:timers/promises';
3+
4+
test('parent', { timeout: 50, concurrency: 1 }, async (t) => {
5+
t.test('first', async () => {
6+
await sleep(1000);
7+
});
8+
9+
t.test('second', async () => {});
10+
t.test('third', async () => {});
11+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
require('../../../common');
3+
const fixtures = require('../../../common/fixtures');
4+
const spawn = require('node:child_process').spawn;
5+
6+
spawn(
7+
process.execPath,
8+
[
9+
'--no-warnings',
10+
'--test-reporter', 'spec',
11+
'--test-concurrency', '1',
12+
'--test-random-seed=12345',
13+
'--test-isolation=none',
14+
'--test',
15+
fixtures.path('test-runner/shards/a.cjs'),
16+
fixtures.path('test-runner/shards/b.cjs'),
17+
fixtures.path('test-runner/shards/c.cjs'),
18+
fixtures.path('test-runner/shards/d.cjs'),
19+
fixtures.path('test-runner/shards/e.cjs'),
20+
fixtures.path('test-runner/shards/f.cjs'),
21+
fixtures.path('test-runner/shards/g.cjs'),
22+
fixtures.path('test-runner/shards/h.cjs'),
23+
fixtures.path('test-runner/shards/i.cjs'),
24+
fixtures.path('test-runner/shards/j.cjs'),
25+
],
26+
{ stdio: 'inherit' },
27+
);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
✔ j.cjs this should pass (*ms)
2+
✔ c.cjs this should pass (*ms)
3+
✔ e.cjs this should pass (*ms)
4+
✔ h.cjs this should pass (*ms)
5+
✔ f.cjs this should pass (*ms)
6+
✔ b.cjs this should pass (*ms)
7+
✔ a.cjs this should pass (*ms)
8+
✔ i.cjs this should pass (*ms)
9+
✔ g.cjs this should pass (*ms)
10+
✔ d.cjs this should pass (*ms)
11+
ℹ Randomized test order seed: 12345
12+
ℹ tests 10
13+
ℹ suites 0
14+
ℹ pass 10
15+
ℹ fail 0
16+
ℹ cancelled 0
17+
ℹ skipped 0
18+
ℹ todo 0
19+
ℹ duration_ms *

test/parallel/test-runner-run.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,28 @@ describe('require(\'node:test\').run', { concurrency: true }, () => {
100100
for await (const _ of stream);
101101
});
102102

103+
for (const isolation of ['process', 'none']) {
104+
it(`should preserve cancelled queued subtest order without randomization (${isolation})`, async () => {
105+
const stream = run({
106+
files: [fixtures.path('test-runner', 'cancelled-report-order.mjs')],
107+
isolation,
108+
});
109+
const cancelledNames = [];
110+
111+
stream.on('test:fail', ({ name, details }) => {
112+
if (name === 'second' || name === 'third') {
113+
cancelledNames.push(name);
114+
assert.strictEqual(details.error.failureType, 'cancelledByParent');
115+
}
116+
});
117+
118+
// eslint-disable-next-line no-unused-vars
119+
for await (const _ of stream);
120+
121+
assert.deepStrictEqual(cancelledNames, ['second', 'third']);
122+
});
123+
}
124+
103125
it('should be piped with dot', async () => {
104126
const result = await run({
105127
files: [join(testFixtures, 'default-behavior/test/random.cjs')]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Test that the output of test-runner/output/randomize_output_cli_none.js matches
2+
// test-runner/output/randomize_output_cli_none.snapshot
3+
import '../common/index.mjs';
4+
import * as fixtures from '../common/fixtures.mjs';
5+
import { spawnAndAssert, specTransform, ensureCwdIsProjectRoot } from '../common/assertSnapshot.js';
6+
7+
ensureCwdIsProjectRoot();
8+
await spawnAndAssert(
9+
fixtures.path('test-runner/output/randomize_output_cli_none.js'),
10+
specTransform,
11+
);

0 commit comments

Comments
 (0)