Skip to content

Commit c6c92c2

Browse files
committed
test: refactor test_runner tests to change default reporter
This commit updates the test runner tests in order to switch the default reporter from tap to spec. This commit can be backported, while changing the default reporter cannot. Refs: nodejs#54540
1 parent 4e68b54 commit c6c92c2

15 files changed

+230
-110
lines changed

test/common/assertSnapshot.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,11 @@ async function spawnAndAssert(filename, transform = (x) => x, { tty = false, ...
7777
test({ skip: 'Skipping pseudo-tty tests, as pseudo terminals are not available on Windows.' });
7878
return;
7979
}
80-
const flags = common.parseTestFlags(filename);
80+
let flags = common.parseTestFlags(filename);
81+
if (options.flags) {
82+
flags = [...options.flags, ...flags];
83+
}
84+
8185
const executable = tty ? (process.env.PYTHON || 'python3') : process.execPath;
8286
const args =
8387
tty ?

test/parallel/test-runner-cli.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ for (const isolation of ['none', 'process']) {
2626
{
2727
// Default behavior. node_modules is ignored. Files that don't match the
2828
// pattern are ignored except in test/ directories.
29-
const args = ['--test', `--experimental-test-isolation=${isolation}`];
29+
const args = ['--test', '--test-reporter=tap',
30+
`--experimental-test-isolation=${isolation}`];
3031
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'default-behavior') });
3132

3233
assert.strictEqual(child.status, 1);
@@ -47,6 +48,7 @@ for (const isolation of ['none', 'process']) {
4748
const args = [
4849
'--require', join(testFixtures, 'protoMutation.js'),
4950
'--test',
51+
'--test-reporter=tap',
5052
`--experimental-test-isolation=${isolation}`,
5153
];
5254
const child = spawnSync(process.execPath, args, { cwd: join(testFixtures, 'default-behavior') });
@@ -67,6 +69,7 @@ for (const isolation of ['none', 'process']) {
6769
// User specified files that don't match the pattern are still run.
6870
const args = [
6971
'--test',
72+
'--test-reporter=tap',
7073
`--experimental-test-isolation=${isolation}`,
7174
join(testFixtures, 'index.js'),
7275
];
@@ -83,6 +86,7 @@ for (const isolation of ['none', 'process']) {
8386
// Searches node_modules if specified.
8487
const args = [
8588
'--test',
89+
'--test-reporter=tap',
8690
`--experimental-test-isolation=${isolation}`,
8791
join(testFixtures, 'default-behavior/node_modules/*.js'),
8892
];
@@ -105,18 +109,19 @@ for (const isolation of ['none', 'process']) {
105109
assert.strictEqual(child.signal, null);
106110
assert.strictEqual(child.stderr.toString(), '');
107111
const stdout = child.stdout.toString();
108-
assert.match(stdout, /ok 1 - this should pass/);
109-
assert.match(stdout, /not ok 2 - this should fail/);
110-
assert.match(stdout, /ok 3 - subdir.+subdir_test\.js/);
111-
assert.match(stdout, /ok 4 - this should pass/);
112-
assert.match(stdout, /ok 5 - this should be skipped/);
113-
assert.match(stdout, /ok 6 - this should be executed/);
112+
assert.match(stdout, /this should pass/);
113+
assert.match(stdout, /this should fail/);
114+
assert.match(stdout, /subdir.+subdir_test\.js/);
115+
assert.match(stdout, /this should pass/);
116+
assert.match(stdout, /this should be skipped/);
117+
assert.match(stdout, /this should be executed/);
114118
}
115119

116120
{
117121
// Test combined stream outputs
118122
const args = [
119123
'--test',
124+
'--test-reporter=tap',
120125
`--experimental-test-isolation=${isolation}`,
121126
'test/fixtures/test-runner/default-behavior/index.test.js',
122127
'test/fixtures/test-runner/nested.js',
@@ -189,6 +194,7 @@ for (const isolation of ['none', 'process']) {
189194
// Test user logging in tests.
190195
const args = [
191196
'--test',
197+
'--test-reporter=tap',
192198
'test/fixtures/test-runner/user-logs.js',
193199
];
194200
const child = spawnSync(process.execPath, args);
@@ -223,7 +229,7 @@ for (const isolation of ['none', 'process']) {
223229
assert.strictEqual(child.status, 0);
224230
assert.strictEqual(child.signal, null);
225231
const stdout = child.stdout.toString();
226-
assert.match(stdout, /ok 1 - this should pass/);
232+
assert.match(stdout, /this should pass/);
227233
}
228234

229235
{
@@ -290,6 +296,7 @@ for (const isolation of ['none', 'process']) {
290296
// --test-shard option, first shard
291297
const args = [
292298
'--test',
299+
'--test-reporter=tap',
293300
'--test-shard=1/2',
294301
join(testFixtures, 'shards/*.cjs'),
295302
];
@@ -324,6 +331,7 @@ for (const isolation of ['none', 'process']) {
324331
// --test-shard option, last shard
325332
const args = [
326333
'--test',
334+
'--test-reporter=tap',
327335
'--test-shard=2/2',
328336
join(testFixtures, 'shards/*.cjs'),
329337
];

test/parallel/test-runner-exit-code.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ async function runAndKill(file) {
1212
return;
1313
}
1414
let stdout = '';
15-
const child = spawn(process.execPath, ['--test', file]);
15+
const child = spawn(process.execPath, ['--test', '--test-reporter=tap', file]);
1616
child.stdout.setEncoding('utf8');
1717
child.stdout.on('data', (chunk) => {
1818
if (!stdout.length) child.kill('SIGINT');
@@ -58,10 +58,10 @@ if (process.argv[2] === 'child') {
5858
assert.strictEqual(child.status, 0);
5959
assert.strictEqual(child.signal, null);
6060
const stdout = child.stdout.toString();
61-
assert.match(stdout, /# tests 3/);
62-
assert.match(stdout, /# pass 0/);
63-
assert.match(stdout, /# fail 0/);
64-
assert.match(stdout, /# todo 3/);
61+
assert.match(stdout, /tests 3/);
62+
assert.match(stdout, /pass 0/);
63+
assert.match(stdout, /fail 0/);
64+
assert.match(stdout, /todo 3/);
6565

6666
child = spawnSync(process.execPath, [__filename, 'child', 'fail']);
6767
assert.strictEqual(child.status, 1);

test/parallel/test-runner-extraneous-async-activity.js

+22-22
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ const { spawnSync } = require('child_process');
1010
fixtures.path('test-runner', 'extraneous_set_immediate_async.mjs'),
1111
]);
1212
const stdout = child.stdout.toString();
13-
assert.match(stdout, /^# Error: Test "extraneous async activity test" at .+extraneous_set_immediate_async\.mjs:3:1 generated asynchronous activity after the test ended/m);
14-
assert.match(stdout, /^# pass 1/m);
15-
assert.match(stdout, /^# fail 1$/m);
16-
assert.match(stdout, /^# cancelled 0$/m);
13+
assert.match(stdout, /Error: Test "extraneous async activity test" at .+extraneous_set_immediate_async\.mjs:3:1 generated asynchronous activity after the test ended/m);
14+
assert.match(stdout, /pass 1/m);
15+
assert.match(stdout, /fail 1$/m);
16+
assert.match(stdout, /cancelled 0$/m);
1717
assert.strictEqual(child.status, 1);
1818
assert.strictEqual(child.signal, null);
1919
}
@@ -24,10 +24,10 @@ const { spawnSync } = require('child_process');
2424
fixtures.path('test-runner', 'extraneous_set_timeout_async.mjs'),
2525
]);
2626
const stdout = child.stdout.toString();
27-
assert.match(stdout, /^# Error: Test "extraneous async activity test" at .+extraneous_set_timeout_async\.mjs:3:1 generated asynchronous activity after the test ended/m);
28-
assert.match(stdout, /^# pass 1$/m);
29-
assert.match(stdout, /^# fail 1$/m);
30-
assert.match(stdout, /^# cancelled 0$/m);
27+
assert.match(stdout, /Error: Test "extraneous async activity test" at .+extraneous_set_timeout_async\.mjs:3:1 generated asynchronous activity after the test ended/m);
28+
assert.match(stdout, /pass 1$/m);
29+
assert.match(stdout, /fail 1$/m);
30+
assert.match(stdout, /cancelled 0$/m);
3131
assert.strictEqual(child.status, 1);
3232
assert.strictEqual(child.signal, null);
3333
}
@@ -38,13 +38,13 @@ const { spawnSync } = require('child_process');
3838
fixtures.path('test-runner', 'async-error-in-test-hook.mjs'),
3939
]);
4040
const stdout = child.stdout.toString();
41-
assert.match(stdout, /^# Error: Test hook "before" at .+async-error-in-test-hook\.mjs:3:1 generated asynchronous activity after the test ended/m);
42-
assert.match(stdout, /^# Error: Test hook "beforeEach" at .+async-error-in-test-hook\.mjs:9:1 generated asynchronous activity after the test ended/m);
43-
assert.match(stdout, /^# Error: Test hook "after" at .+async-error-in-test-hook\.mjs:15:1 generated asynchronous activity after the test ended/m);
44-
assert.match(stdout, /^# Error: Test hook "afterEach" at .+async-error-in-test-hook\.mjs:21:1 generated asynchronous activity after the test ended/m);
45-
assert.match(stdout, /^# pass 1$/m);
46-
assert.match(stdout, /^# fail 1$/m);
47-
assert.match(stdout, /^# cancelled 0$/m);
41+
assert.match(stdout, /Error: Test hook "before" at .+async-error-in-test-hook\.mjs:3:1 generated asynchronous activity after the test ended/m);
42+
assert.match(stdout, /Error: Test hook "beforeEach" at .+async-error-in-test-hook\.mjs:9:1 generated asynchronous activity after the test ended/m);
43+
assert.match(stdout, /Error: Test hook "after" at .+async-error-in-test-hook\.mjs:15:1 generated asynchronous activity after the test ended/m);
44+
assert.match(stdout, /Error: Test hook "afterEach" at .+async-error-in-test-hook\.mjs:21:1 generated asynchronous activity after the test ended/m);
45+
assert.match(stdout, /pass 1$/m);
46+
assert.match(stdout, /fail 1$/m);
47+
assert.match(stdout, /cancelled 0$/m);
4848
assert.strictEqual(child.status, 1);
4949
assert.strictEqual(child.signal, null);
5050
}
@@ -56,13 +56,13 @@ const { spawnSync } = require('child_process');
5656
fixtures.path('test-runner', 'async-error-in-test-hook.mjs'),
5757
]);
5858
const stdout = child.stdout.toString();
59-
assert.match(stdout, /^# Error: Test hook "before" at .+async-error-in-test-hook\.mjs:3:1 generated asynchronous activity after the test ended/m);
60-
assert.match(stdout, /^# Error: Test hook "beforeEach" at .+async-error-in-test-hook\.mjs:9:1 generated asynchronous activity after the test ended/m);
61-
assert.match(stdout, /^# Error: Test hook "after" at .+async-error-in-test-hook\.mjs:15:1 generated asynchronous activity after the test ended/m);
62-
assert.match(stdout, /^# Error: Test hook "afterEach" at .+async-error-in-test-hook\.mjs:21:1 generated asynchronous activity after the test ended/m);
63-
assert.match(stdout, /^# pass 1$/m);
64-
assert.match(stdout, /^# fail 0$/m);
65-
assert.match(stdout, /^# cancelled 0$/m);
59+
assert.match(stdout, /Error: Test hook "before" at .+async-error-in-test-hook\.mjs:3:1 generated asynchronous activity after the test ended/m);
60+
assert.match(stdout, /Error: Test hook "beforeEach" at .+async-error-in-test-hook\.mjs:9:1 generated asynchronous activity after the test ended/m);
61+
assert.match(stdout, /Error: Test hook "after" at .+async-error-in-test-hook\.mjs:15:1 generated asynchronous activity after the test ended/m);
62+
assert.match(stdout, /Error: Test hook "afterEach" at .+async-error-in-test-hook\.mjs:21:1 generated asynchronous activity after the test ended/m);
63+
assert.match(stdout, /pass 1$/m);
64+
assert.match(stdout, /fail 0$/m);
65+
assert.match(stdout, /cancelled 0$/m);
6666
assert.strictEqual(child.status, 1);
6767
assert.strictEqual(child.signal, null);
6868
}

test/parallel/test-runner-force-exit-failure.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const fixture = fixtures.path('test-runner/throws_sync_and_async.js');
88
for (const isolation of ['none', 'process']) {
99
const args = [
1010
'--test',
11+
'--test-reporter=spec',
1112
'--test-force-exit',
1213
`--experimental-test-isolation=${isolation}`,
1314
fixture,
@@ -19,6 +20,6 @@ for (const isolation of ['none', 'process']) {
1920
strictEqual(r.stderr.toString(), '');
2021

2122
const stdout = r.stdout.toString();
22-
match(stdout, /error: 'fails'/);
23+
match(stdout, /Error: fails/);
2324
doesNotMatch(stdout, /this should not have a chance to be thrown/);
2425
}

test/parallel/test-runner-inspect.mjs

+5-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ tmpdir.refresh();
1212

1313
{
1414
const child = new NodeInstance(
15-
['--test', '--inspect-brk=0'],
15+
['--test', '--test-reporter=tap', '--inspect-brk=0'],
1616
undefined,
1717
fixtures.path('test-runner/default-behavior/index.test.js')
1818
);
@@ -38,7 +38,10 @@ tmpdir.refresh();
3838

3939

4040
{
41-
const args = ['--test', '--inspect=0', fixtures.path('test-runner/index.js')];
41+
const args = [
42+
'--test', '--test-reporter=tap', '--inspect=0',
43+
fixtures.path('test-runner/index.js'),
44+
];
4245
const { stderr, stdout, code, signal } = await common.spawnPromisified(process.execPath, args);
4346

4447
assert.match(stderr,

test/parallel/test-runner-misc.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ if (process.argv[2] === 'child') {
3333
} else {
3434
const child = spawnSync(process.execPath, [__filename, 'child', 'abortSignal']);
3535
const stdout = child.stdout.toString();
36-
assert.match(stdout, /^# pass 2$/m);
37-
assert.match(stdout, /^# fail 0$/m);
38-
assert.match(stdout, /^# cancelled 1$/m);
36+
assert.match(stdout, /pass 2$/m);
37+
assert.match(stdout, /fail 0$/m);
38+
assert.match(stdout, /cancelled 1$/m);
3939
assert.strictEqual(child.status, 1);
4040
assert.strictEqual(child.signal, null);
4141
}

test/parallel/test-runner-module-mocking.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ test('node_modules can be used by both module systems', async (t) => {
571571

572572
assert.strictEqual(code, 0);
573573
assert.strictEqual(signal, null);
574-
assert.match(stdout, /# pass 1/);
574+
assert.match(stdout, /pass 1/);
575575
});
576576

577577
test('file:// imports are supported in ESM only', async (t) => {

test/parallel/test-runner-no-isolation-filtering.js

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const fixture2 = fixtures.path('test-runner', 'no-isolation', 'two.test.js');
1111
test('works with --test-only', () => {
1212
const args = [
1313
'--test',
14+
'--test-reporter=tap',
1415
'--experimental-test-isolation=none',
1516
'--test-only',
1617
fixture1,
@@ -33,6 +34,7 @@ test('works with --test-only', () => {
3334
test('works with --test-name-pattern', () => {
3435
const args = [
3536
'--test',
37+
'--test-reporter=tap',
3638
'--experimental-test-isolation=none',
3739
'--test-name-pattern=/test one/',
3840
fixture1,
@@ -52,6 +54,7 @@ test('works with --test-name-pattern', () => {
5254
test('works with --test-skip-pattern', () => {
5355
const args = [
5456
'--test',
57+
'--test-reporter=tap',
5558
'--experimental-test-isolation=none',
5659
'--test-skip-pattern=/one/',
5760
fixture1,

0 commit comments

Comments
 (0)