1- import  {  describe ,  expect ,  it  }  from  'vitest' 
1+ import  {  resolve  }  from  'node:path' 
2+ import  { 
3+   type  MockInstance , 
4+   afterEach , 
5+   beforeEach , 
6+   describe , 
7+   expect , 
8+   it , 
9+   vi , 
10+ }  from  'vitest' 
11+ import  chokidar  from  'chokidar' 
212import  {  createServer  }  from  '../index' 
313
414const  stubGetWatchedCode  =  / g e t W a t c h e d \( \)   \{ .+ ?r e t u r n   \{ \} ; .+ ?\} / s
515
16+ let  watchSpy : MockInstance < 
17+   Parameters < typeof  chokidar . watch > , 
18+   ReturnType < typeof  chokidar . watch > 
19+ > 
20+ 
21+ vi . mock ( '../../config' ,  async  ( )  =>  { 
22+   const  config : typeof  import ( '../../config' )  = 
23+     await  vi . importActual ( '../../config' ) 
24+   const  resolveConfig  =  config . resolveConfig 
25+   vi . spyOn ( config ,  'resolveConfig' ) . mockImplementation ( async  ( ...args )  =>  { 
26+     const  resolved : Awaited < ReturnType < typeof  resolveConfig > >  = 
27+       await  resolveConfig . call ( config ,  ...args ) 
28+     resolved . configFileDependencies . push ( 
29+       resolve ( 'fake/config/dependency.js' ) . replace ( / \\ / g,  '/' ) , 
30+     ) 
31+     return  resolved 
32+   } ) 
33+   return  config 
34+ } ) 
35+ 
636describe ( 'watcher configuration' ,  ( )  =>  { 
37+   beforeEach ( ( )  =>  { 
38+     watchSpy  =  vi . spyOn ( chokidar ,  'watch' ) 
39+   } ) 
40+ 
41+   afterEach ( ( )  =>  { 
42+     watchSpy . mockRestore ( ) 
43+   } ) 
44+ 
745  it ( 'when watcher is disabled, return noop watcher' ,  async  ( )  =>  { 
846    const  server  =  await  createServer ( { 
947      server : { 
@@ -21,4 +59,27 @@ describe('watcher configuration', () => {
2159    } ) 
2260    expect ( server . watcher . getWatched . toString ( ) ) . not . toMatch ( stubGetWatchedCode ) 
2361  } ) 
62+ 
63+   it ( 'should watch the root directory, config file dependencies, dotenv files, and the public directory' ,  async  ( )  =>  { 
64+     await  createServer ( { 
65+       server : { 
66+         watch : { } , 
67+       } , 
68+       publicDir : '__test_public__' , 
69+     } ) 
70+     expect ( watchSpy ) . toHaveBeenLastCalledWith ( 
71+       expect . arrayContaining ( 
72+         [ 
73+           process . cwd ( ) , 
74+           resolve ( 'fake/config/dependency.js' ) , 
75+           resolve ( '.env' ) , 
76+           resolve ( '.env.local' ) , 
77+           resolve ( '.env.development' ) , 
78+           resolve ( '.env.development.local' ) , 
79+           resolve ( '__test_public__' ) , 
80+         ] . map ( ( file )  =>  file . replace ( / \\ / g,  '/' ) ) , 
81+       ) , 
82+       expect . anything ( ) , 
83+     ) 
84+   } ) 
2485} ) 
0 commit comments