Skip to content

Commit 85dabca

Browse files
committed
fixup! test: fix skipping behavior for test-runner-run-files-undefined
1 parent 7feccda commit 85dabca

1 file changed

Lines changed: 25 additions & 52 deletions

File tree

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,31 @@
1-
import * as common from '../common/index.mjs';
1+
import '../common/index.mjs';
22
import tmpdir from '../common/tmpdir.js';
3-
import { describe, it, run, beforeEach } from 'node:test';
4-
import { dot, spec, tap } from 'node:test/reporters';
5-
import { fork } from 'node:child_process';
6-
import assert from 'node:assert';
7-
8-
if (common.isAIX) {
9-
common.skip('test runner without specifying files fails on AIX');
10-
}
11-
12-
if (process.env.CHILD === 'true') {
13-
describe('require(\'node:test\').run with no files', { concurrency: true }, () => {
14-
beforeEach(() => {
15-
tmpdir.refresh();
16-
process.chdir(tmpdir.path);
3+
import { spawnSyncAndExitWithoutError } from '../common/child_process.js';
4+
5+
async function runTests(run, reporters) {
6+
for (const reporterName of Object.keys(reporters)) {
7+
if (reporterName === 'default') continue;
8+
console.log({ reporterName });
9+
10+
const stream = run({
11+
files: undefined
12+
}).compose(reporters[reporterName]);
13+
stream.on('test:fail', () => {
14+
throw new Error('Received test:fail with ' + reporterName);
1715
});
18-
19-
it('should neither pass or fail', async () => {
20-
const stream = run({
21-
files: undefined
22-
}).compose(tap);
23-
stream.on('test:fail', common.mustNotCall());
24-
stream.on('test:pass', common.mustNotCall());
25-
26-
// eslint-disable-next-line no-unused-vars
27-
for await (const _ of stream);
16+
stream.on('test:pass', () => {
17+
throw new Error('Received test:pass with ' + reporterName);
2818
});
2919

30-
it('can use the spec reporter', async () => {
31-
const stream = run({
32-
files: undefined
33-
}).compose(spec);
34-
stream.on('test:fail', common.mustNotCall());
35-
stream.on('test:pass', common.mustNotCall());
36-
37-
// eslint-disable-next-line no-unused-vars
38-
for await (const _ of stream);
39-
});
20+
// eslint-disable-next-line no-unused-vars
21+
for await (const _ of stream);
22+
}
23+
}
4024

41-
it('can use the dot reporter', async () => {
42-
const stream = run({
43-
files: undefined
44-
}).compose(dot);
45-
stream.on('test:fail', common.mustNotCall());
46-
stream.on('test:pass', common.mustNotCall());
25+
tmpdir.refresh();
26+
spawnSyncAndExitWithoutError(process.execPath, ['--input-type=module', '-e', `
27+
import { run } from 'node:test';
28+
import * as reporters from 'node:test/reporters';
4729
48-
// eslint-disable-next-line no-unused-vars
49-
for await (const _ of stream);
50-
});
51-
});
52-
} else {
53-
fork(import.meta.filename, [], {
54-
env: { ...process.env, CHILD: 'true' }
55-
}).on('exit', common.mustCall((code) => {
56-
assert.strictEqual(code, 0);
57-
}));
58-
}
30+
await (${runTests})(run, reporters);
31+
`], { cwd: tmpdir.path });

0 commit comments

Comments
 (0)