@@ -3,12 +3,10 @@ import { skipIfNoWatch } from '../common/watch.js';
33
44skipIfNoWatch ( ) ;
55
6- // if (common.isSunOS)
7- // common.skip('`fs.watch()` is not reliable on SunOS.');
8-
96const assert = await import ( 'node:assert' ) ;
107const path = await import ( 'node:path' ) ;
118const tmpdir = await import ( '../common/tmpdir.js' ) ;
9+ const { setTimeout } = await import ( 'node:timers/promises' ) ;
1210const { watch } = await import ( 'node:fs/promises' ) ;
1311const { writeFileSync } = await import ( 'node:fs' ) ;
1412
@@ -20,21 +18,29 @@ const ignoreFile = '.hidden';
2018const keepFilePath = path . join ( testDir , keepFile ) ;
2119const ignoreFilePath = path . join ( testDir , ignoreFile ) ;
2220
23- const watcher = watch ( testDir , {
24- ignore : ( filename ) => filename . startsWith ( '.' ) ,
25- } ) ;
21+ async function watchDir ( ) {
22+ const watcher = watch ( testDir , {
23+ ignore : ( filename ) => filename . startsWith ( '.' ) ,
24+ } ) ;
2625
27- // Do the write with a delay to ensure that the OS is ready to notify us. See
28- // https://github.com/nodejs/node/issues/52601.
29- setTimeout ( ( ) => {
30- writeFileSync ( ignoreFilePath , 'ignored' ) ;
31- writeFileSync ( keepFilePath , 'content' ) ;
32- } , common . platformTimeout ( 100 ) ) ;
26+ for await ( const { filename } of watcher ) {
27+ assert . notStrictEqual ( filename , ignoreFile ) ;
3328
34- for await ( const { filename } of watcher ) {
35- assert . notStrictEqual ( filename , ignoreFile ) ;
29+ if ( filename === keepFile ) {
30+ break ;
31+ }
32+ }
33+ }
3634
37- if ( filename === keepFile ) {
38- break ;
35+ async function writeFiles ( ) {
36+ if ( common . isMacOS ) {
37+ // Do the write with a delay to ensure that the OS is ready to notify us.
38+ // See https://github.com/nodejs/node/issues/52601.
39+ await setTimeout ( common . platformTimeout ( 100 ) ) ;
3940 }
41+
42+ writeFileSync ( ignoreFilePath , 'ignored' ) ;
43+ writeFileSync ( keepFilePath , 'content' ) ;
4044}
45+
46+ await Promise . all ( [ watchDir ( ) , writeFiles ( ) ] ) ;
0 commit comments