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