Skip to content

Commit 8048e05

Browse files
committed
test: fix skipping behavior for test-runner-run-files-undefined
PR-URL: #62026 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent cc46204 commit 8048e05

1 file changed

Lines changed: 25 additions & 55 deletions

File tree

Lines changed: 25 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,31 @@
1-
import*ascommonfrom'../common/index.mjs';
1+
import'../common/index.mjs';
22
importtmpdirfrom'../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-
importassertfrom'node:assert';
7-
8-
if(common.hasCrypto){
9-
console.log('1..0 # Skipped: no crypto');
10-
process.exit(0);
11-
}
12-
13-
if(process.env.CHILD==='true'){
14-
describe('require(\'node:test\').run with no files',{concurrency: true},()=>{
15-
beforeEach(()=>{
16-
tmpdir.refresh();
17-
process.chdir(tmpdir.path);
3+
import{spawnSyncAndExitWithoutError}from'../common/child_process.js';
4+
5+
asyncfunctionrunTests(run,reporters){
6+
for(constreporterNameofObject.keys(reporters)){
7+
if(reporterName==='default')continue;
8+
console.log({ reporterName });
9+
10+
conststream=run({
11+
files: undefined
12+
}).compose(reporters[reporterName]);
13+
stream.on('test:fail',()=>{
14+
thrownewError('Received test:fail with '+reporterName);
1815
});
19-
20-
it('should neither pass or fail',async()=>{
21-
conststream=run({
22-
files: undefined
23-
}).compose(tap);
24-
stream.on('test:fail',common.mustNotCall());
25-
stream.on('test:pass',common.mustNotCall());
26-
27-
// eslint-disable-next-line no-unused-vars
28-
forawait(const_ofstream);
16+
stream.on('test:pass',()=>{
17+
thrownewError('Received test:pass with '+reporterName);
2918
});
3019

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

42-
it('can use the dot reporter',async()=>{
43-
conststream=run({
44-
files: undefined
45-
}).compose(dot);
46-
stream.on('test:fail',common.mustNotCall());
47-
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';
4829
49-
// eslint-disable-next-line no-unused-vars
50-
forawait(const_ofstream);
51-
});
52-
});
53-
}elseif(common.isAIX){
54-
console.log('1..0 # Skipped: test runner without specifying files fails on AIX');
55-
}else{
56-
fork(import.meta.filename,[],{
57-
env: {CHILD: 'true'}
58-
}).on('exit',common.mustCall((code)=>{
59-
assert.strictEqual(code,0);
60-
}));
61-
}
30+
await (${runTests})(run, reporters);
31+
`],{cwd: tmpdir.path});

0 commit comments

Comments
 (0)