Skip to content

Commit 1a4ae46

Browse files
authored
test_runner: fix test runner watch mode when no positional arguments
PR-URL: #49578Fixes: #49617 Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
1 parent 22907ce commit 1a4ae46

2 files changed

Lines changed: 13 additions & 12 deletions

File tree

‎src/node_options.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
173173
} elseif (force_repl) {
174174
errors->push_back("either --watch or --interactive "
175175
"can be used, not both");
176-
} elseif (argv->size() < 1 || (*argv)[1].empty()) {
176+
} elseif (!test_runner && (argv->size() < 1 || (*argv)[1].empty())) {
177177
errors->push_back("--watch requires specifying a file");
178178
}
179179

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

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

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

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

5956
describe('test runner watch mode',()=>{
6057
it('should run tests repeatedly',async()=>{
61-
awaittestWatch({fileToUpdate: 'dependent.js'});
58+
awaittestWatch({file: 'test.js',fileToUpdate: 'test.js'});
6259
});
6360

6461
it('should run tests with dependency repeatedly',async()=>{
65-
awaittestWatch({fileToUpdate: 'dependency.js'});
62+
awaittestWatch({file: 'test.js',fileToUpdate: 'dependency.js'});
6663
});
6764

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

0 commit comments

Comments
 (0)