@@ -6,7 +6,8 @@ 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
+ import { createInterface } from 'node:readline' ;
10
11
import { setTimeout } from 'node:timers/promises' ;
11
12
import { once } from 'node:events' ;
12
13
import { spawn } from 'node:child_process' ;
@@ -51,6 +52,33 @@ describe('watch mode file watcher', () => {
51
52
assert . strictEqual ( changesCount , 1 ) ;
52
53
} ) ;
53
54
55
+ it ( 'should watch changed files with same prefix path string' , async ( ) => {
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
+ const child = spawn ( process . execPath ,
64
+ [ '--watch' , file1 ] ,
65
+ { stdio : [ 'ignore' , 'pipe' , 'ignore' ] } ) ;
66
+ let completeCount = 0 ;
67
+ for await ( const line of createInterface ( child . stdout ) ) {
68
+ if ( ! line . startsWith ( 'Completed running' ) ) {
69
+ continue ;
70
+ }
71
+ completeCount ++ ;
72
+ if ( completeCount === 1 ) {
73
+ appendFileSync ( file1 , '\n // append 1' ) ;
74
+ }
75
+ // The file is reloaded due to file watching
76
+ if ( completeCount === 2 ) {
77
+ child . kill ( ) ;
78
+ }
79
+ }
80
+ } ) ;
81
+
54
82
it ( 'should debounce changes' , async ( ) => {
55
83
const file = tmpdir . resolve ( 'file2' ) ;
56
84
writeFileSync ( file , 'written' ) ;
0 commit comments