Skip to content

Commit e459598

Browse files
MoLowtargos
authored andcommitted
test_runner: fix test runner watch mode when no positional arguments
PR-URL: #49578Fixes: #49617 Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]>
1 parent 059b194 commit e459598

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

‎src/node_options.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
188188
} elseif (force_repl){
189189
errors->push_back("either --watch or --interactive "
190190
"can be used, not both");
191-
} elseif (argv->size() < 1 || (*argv)[1].empty()){
191+
} elseif (!test_runner && (argv->size() < 1 || (*argv)[1].empty())){
192192
errors->push_back("--watch requires specifying a file");
193193
}
194194

‎test/parallel/test-runner-watch-mode.mjs‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tmpdir.refresh();
1818
constfixtureContent={
1919
'dependency.js': 'module.exports ={};',
2020
'dependency.mjs': 'export const a = 1;',
21-
'dependent.js': `
21+
'test.js': `
2222
const test = require('node:test');
2323
require('./dependency.js');
2424
import('./dependency.mjs');
@@ -30,12 +30,12 @@ const fixturePaths = Object.keys(fixtureContent)
3030
Object.entries(fixtureContent)
3131
.forEach(([file,content])=>writeFileSync(fixturePaths[file],content));
3232

33-
asyncfunctiontestWatch({ fileToUpdate }){
33+
asyncfunctiontestWatch({ fileToUpdate, file}){
3434
constran1=util.createDeferredPromise();
3535
constran2=util.createDeferredPromise();
3636
constchild=spawn(process.execPath,
37-
['--watch','--test','--no-warnings',fixturePaths['dependent.js']],
38-
{encoding: 'utf8',stdio: 'pipe'});
37+
['--watch','--test',file ? fixturePaths[file] : undefined].filter(Boolean),
38+
{encoding: 'utf8',stdio: 'pipe',cwd: tmpdir.path});
3939
letstdout='';
4040

4141
child.stdout.on('data',(data)=>{
@@ -48,25 +48,26 @@ async function testWatch({fileToUpdate }){
4848
awaitran1.promise;
4949
constcontent=fixtureContent[fileToUpdate];
5050
constpath=fixturePaths[fileToUpdate];
51-
constinterval=setInterval(()=>{
52-
console.log(`Updating ${path}`);
53-
writeFileSync(path,content);
54-
},50);
51+
constinterval=setInterval(()=>writeFileSync(path,content),common.platformTimeout(1000));
5552
awaitran2.promise;
5653
clearInterval(interval);
5754
child.kill();
5855
}
5956

6057
describe('test runner watch mode',()=>{
6158
it('should run tests repeatedly',async()=>{
62-
awaittestWatch({fileToUpdate: 'dependent.js'});
59+
awaittestWatch({file: 'test.js',fileToUpdate: 'test.js'});
6360
});
6461

6562
it('should run tests with dependency repeatedly',async()=>{
66-
awaittestWatch({fileToUpdate: 'dependency.js'});
63+
awaittestWatch({file: 'test.js',fileToUpdate: 'dependency.js'});
6764
});
6865

6966
it('should run tests with ESM dependency',async()=>{
70-
awaittestWatch({fileToUpdate: 'dependency.mjs'});
67+
awaittestWatch({file: 'test.js',fileToUpdate: 'dependency.mjs'});
68+
});
69+
70+
it('should support running tests without a file',async()=>{
71+
awaittestWatch({fileToUpdate: 'test.js'});
7172
});
7273
});

0 commit comments

Comments
(0)