Skip to content

Commit 527589b

Browse files
authored
test_runner: disallow array in run options
PR-URL: #49935 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent c5de3b4 commit 527589b

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

‎lib/internal/test_runner/runner.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,9 @@ function watchFiles(testFiles, opts){
435435
returnfilesWatcher;
436436
}
437437

438-
functionrun(options){
439-
if(options===null||typeofoptions!=='object'){
440-
options=kEmptyObject;
441-
}
438+
functionrun(options=kEmptyObject){
439+
validateObject(options,'options');
440+
442441
let{ testNamePatterns, shard }=options;
443442
const{ concurrency, timeout, signal, files, inspectPort, watch, setup, only }=options;
444443

‎test/parallel/test-runner-run.mjs‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import assert from 'node:assert'
88
consttestFixtures=fixtures.path('test-runner');
99

1010
describe('require(\'node:test\').run',{concurrency: true},()=>{
11-
1211
it('should run with no tests',async()=>{
1312
conststream=run({files: []});
1413
stream.on('test:fail',common.mustNotCall());
@@ -65,13 +64,6 @@ describe('require(\'node:test\').run',{concurrency: true }, () =>{
6564
forawait(const_ofstream);
6665
});
6766

68-
it('should validate files',async()=>{
69-
[Symbol(),{},()=>{},0,1,0n,1n,'','1',Promise.resolve([]),true,false]
70-
.forEach((files)=>assert.throws(()=>run({ files }),{
71-
code: 'ERR_INVALID_ARG_TYPE'
72-
}));
73-
});
74-
7567
it('should be piped with dot',async()=>{
7668
constresult=awaitrun({
7769
files: [join(testFixtures,'default-behavior/test/random.cjs')]
@@ -437,4 +429,20 @@ describe('require(\'node:test\').run',{concurrency: true }, () =>{
437429
assert.deepStrictEqual(executedTestFiles.sort(),[...shardsTestsFiles].sort());
438430
});
439431
});
432+
433+
describe('validation',()=>{
434+
it('should only allow array in options.files',async()=>{
435+
[Symbol(),{},()=>{},0,1,0n,1n,'','1',Promise.resolve([]),true,false]
436+
.forEach((files)=>assert.throws(()=>run({ files }),{
437+
code: 'ERR_INVALID_ARG_TYPE'
438+
}));
439+
});
440+
441+
it('should only allow object as options',()=>{
442+
[Symbol(),[],()=>{},0,1,0n,1n,'','1',true,false]
443+
.forEach((options)=>assert.throws(()=>run(options),{
444+
code: 'ERR_INVALID_ARG_TYPE'
445+
}));
446+
});
447+
});
440448
});

0 commit comments

Comments
(0)