@@ -17,7 +17,7 @@ tmpdir.refresh();
17
17
const fixtureContent = {
18
18
'dependency.js' : 'module.exports = {};' ,
19
19
'dependency.mjs' : 'export const a = 1;' ,
20
- 'dependent .js' : `
20
+ 'test .js' : `
21
21
const test = require('node:test');
22
22
require('./dependency.js');
23
23
import('./dependency.mjs');
@@ -29,12 +29,12 @@ const fixturePaths = Object.keys(fixtureContent)
29
29
Object . entries ( fixtureContent )
30
30
. forEach ( ( [ file , content ] ) => writeFileSync ( fixturePaths [ file ] , content ) ) ;
31
31
32
- async function testWatch ( { fileToUpdate } ) {
32
+ async function testWatch ( { fileToUpdate, file } ) {
33
33
const ran1 = util . createDeferredPromise ( ) ;
34
34
const ran2 = util . createDeferredPromise ( ) ;
35
35
const child = 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 } ) ;
38
38
let stdout = '' ;
39
39
40
40
child . stdout . on ( 'data' , ( data ) => {
@@ -47,25 +47,26 @@ async function testWatch({ fileToUpdate }) {
47
47
await ran1 . promise ;
48
48
const content = fixtureContent [ fileToUpdate ] ;
49
49
const path = fixturePaths [ fileToUpdate ] ;
50
- const interval = setInterval ( ( ) => {
51
- console . log ( `Updating ${ path } ` ) ;
52
- writeFileSync ( path , content ) ;
53
- } , 50 ) ;
50
+ const interval = setInterval ( ( ) => writeFileSync ( path , content ) , common . platformTimeout ( 1000 ) ) ;
54
51
await ran2 . promise ;
55
52
clearInterval ( interval ) ;
56
53
child . kill ( ) ;
57
54
}
58
55
59
56
describe ( 'test runner watch mode' , ( ) => {
60
57
it ( 'should run tests repeatedly' , async ( ) => {
61
- await testWatch ( { fileToUpdate : 'dependent .js' } ) ;
58
+ await testWatch ( { file : 'test.js' , fileToUpdate : 'test .js' } ) ;
62
59
} ) ;
63
60
64
61
it ( 'should run tests with dependency repeatedly' , async ( ) => {
65
- await testWatch ( { fileToUpdate : 'dependency.js' } ) ;
62
+ await testWatch ( { file : 'test.js' , fileToUpdate : 'dependency.js' } ) ;
66
63
} ) ;
67
64
68
65
it ( 'should run tests with ESM dependency' , async ( ) => {
69
- await testWatch ( { fileToUpdate : 'dependency.mjs' } ) ;
66
+ await testWatch ( { file : 'test.js' , fileToUpdate : 'dependency.mjs' } ) ;
67
+ } ) ;
68
+
69
+ it ( 'should support running tests without a file' , async ( ) => {
70
+ await testWatch ( { fileToUpdate : 'test.js' } ) ;
70
71
} ) ;
71
72
} ) ;
0 commit comments