@@ -6,7 +6,7 @@ import path from 'node:path';
6
6
import assert from 'node:assert' ;
7
7
import process from 'node:process' ;
8
8
import { describe , it , beforeEach , afterEach } from 'node:test' ;
9
- import { writeFileSync , mkdirSync } from 'node:fs' ;
9
+ import { writeFileSync , mkdirSync , appendFileSync } from 'node:fs' ;
10
10
import { setTimeout } from 'node:timers/promises' ;
11
11
import { once } from 'node:events' ;
12
12
import { spawn } from 'node:child_process' ;
@@ -51,6 +51,38 @@ describe('watch mode file watcher', () => {
51
51
assert . strictEqual ( changesCount , 1 ) ;
52
52
} ) ;
53
53
54
+ it ( 'should watch changed files with same prefix path string' , async ( ) => {
55
+ const ran1 = Promise . withResolvers ( ) ;
56
+ mkdirSync ( tmpdir . resolve ( 'subdir' ) ) ;
57
+ mkdirSync ( tmpdir . resolve ( 'sub' ) ) ;
58
+ const file1 = tmpdir . resolve ( 'subdir' , 'file1.mjs' ) ;
59
+ const file2 = tmpdir . resolve ( 'sub' , 'file2.mjs' ) ;
60
+ writeFileSync ( file2 , 'export const hello = () => { return "hello world"; };' ) ;
61
+ writeFileSync ( file1 , 'import { hello } from "../sub/file2.mjs"; console.log(hello());' ) ;
62
+
63
+ let stdout = '' ;
64
+ const child = spawn ( process . execPath ,
65
+ [ '--watch' , file1 ] ,
66
+ { encoding : 'utf8' , stdio : 'pipe' } ) ;
67
+ let completeCount = 0 ;
68
+ child . stdout . on ( 'data' , async ( data ) => {
69
+ stdout += data . toString ( ) ;
70
+ if ( stdout . match ( / C o m p l e t e / g) ) {
71
+ completeCount ++ ;
72
+ }
73
+ if ( completeCount === 1 ) {
74
+ ran1 . resolve ( ) ;
75
+ }
76
+ // The file is reloaded due to file watching
77
+ if ( completeCount === 2 ) {
78
+ child . kill ( ) ;
79
+ await once ( child , 'exit' ) ;
80
+ }
81
+ } ) ;
82
+ await ran1 . promise ;
83
+ appendFileSync ( file1 , '\n // append 1' ) ;
84
+ } ) ;
85
+
54
86
it ( 'should debounce changes' , async ( ) => {
55
87
const file = tmpdir . resolve ( 'file2' ) ;
56
88
writeFileSync ( file , 'written' ) ;
0 commit comments