11const assert = require ( 'node:assert' ) ;
2- const {
3- existsSync,
4- promises : fs ,
5- readdirSync,
6- readFileSync,
7- unlinkSync,
8- writeFileSync
9- } = require ( 'node:fs' ) ;
2+ const { existsSync, readdirSync, readFileSync, rmSync, unlinkSync } = require ( 'node:fs' ) ;
3+ const { rm, unlink, writeFile } = require ( 'node:fs/promises' ) ;
104const { resolve } = require ( 'node:path' ) ;
115const { chdir, cwd, hrtime } = require ( 'node:process' ) ;
12- const { copy, removeSync } = require ( 'fs-extra' ) ;
6+ const { copy } = require ( 'fs-extra' ) ;
137const rollup = require ( '../../dist/rollup' ) ;
148const { atomicWriteFileSync, wait } = require ( '../utils' ) ;
159
@@ -18,7 +12,10 @@ describe('rollup.watch', () => {
1812
1913 beforeEach ( ( ) => {
2014 chdir ( cwd ( ) ) ;
21- return removeSync ( 'test/_tmp' ) ;
15+ return rm ( 'test/_tmp' , {
16+ force : true ,
17+ recursive : true
18+ } ) ;
2219 } ) ;
2320
2421 afterEach ( ( ) => {
@@ -240,7 +237,7 @@ describe('rollup.watch', () => {
240237 let ids ;
241238 const expectedIds = [ WATCHED_ID , resolve ( 'test/_tmp/input/main.js' ) ] ;
242239 await copy ( 'test/watch/samples/watch-files' , 'test/_tmp/input' ) ;
243- await fs . unlink ( WATCHED_ID ) ;
240+ await unlink ( WATCHED_ID ) ;
244241 await wait ( 100 ) ;
245242 watcher = rollup . watch ( {
246243 input : 'test/_tmp/input/main.js' ,
@@ -350,7 +347,7 @@ describe('rollup.watch', () => {
350347 assert . strictEqual ( lastEvent , null ) ;
351348 atomicWriteFileSync ( WATCHED_ID , 'another' ) ;
352349 await wait ( 100 ) ;
353- unlinkSync ( WATCHED_ID ) ;
350+ await unlink ( WATCHED_ID ) ;
354351 } ,
355352 'START' ,
356353 'BUNDLE_START' ,
@@ -361,7 +358,7 @@ describe('rollup.watch', () => {
361358 lastEvent = null ;
362359 atomicWriteFileSync ( WATCHED_ID , '123' ) ;
363360 await wait ( 100 ) ;
364- unlinkSync ( WATCHED_ID ) ;
361+ await unlink ( WATCHED_ID ) ;
365362 // To ensure there is always another change to trigger a rebuild
366363 atomicWriteFileSync ( MAIN_ID , 'export default 43;' ) ;
367364 } ,
@@ -1107,7 +1104,10 @@ describe('rollup.watch', () => {
11071104 'END' ,
11081105 ( ) => {
11091106 [ dynamicName , staticName , chunkName ] = readdirSync ( 'test/_tmp/output' ) . sort ( ) ;
1110- removeSync ( 'test/_tmp/output' ) ;
1107+ rmSync ( 'test/_tmp/output' , {
1108+ force : true ,
1109+ recursive : true
1110+ } ) ;
11111111
11121112 // this should only update the hash of that particular entry point
11131113 atomicWriteFileSync (
@@ -1122,7 +1122,10 @@ describe('rollup.watch', () => {
11221122 ( ) => {
11231123 const [ newDynamicName , newStaticName , newChunkName ] =
11241124 readdirSync ( 'test/_tmp/output' ) . sort ( ) ;
1125- removeSync ( 'test/_tmp/output' ) ;
1125+ rmSync ( 'test/_tmp/output' , {
1126+ force : true ,
1127+ recursive : true
1128+ } ) ;
11261129 assert . notEqual ( newStaticName , staticName ) ;
11271130 assert . strictEqual ( newDynamicName , dynamicName ) ;
11281131 assert . strictEqual ( newChunkName , chunkName ) ;
@@ -1384,7 +1387,9 @@ describe('rollup.watch', () => {
13841387 const transformFile = resolve ( 'test/_tmp/input/transform' ) ;
13851388 const watchFiles = [ buildStartFile , loadFile , resolveIdFile , transformFile ] ;
13861389 await copy ( 'test/watch/samples/basic' , 'test/_tmp/input' ) ;
1387- for ( const file of watchFiles ) writeFileSync ( file , 'initial' ) ;
1390+
1391+ await Promise . all ( watchFiles . map ( file => writeFile ( file , 'initial' ) ) ) ;
1392+
13881393 watcher = rollup . watch ( {
13891394 input : 'test/_tmp/input/main.js' ,
13901395 output : {
@@ -1415,11 +1420,12 @@ describe('rollup.watch', () => {
14151420 'BUNDLE_START' ,
14161421 'BUNDLE_END' ,
14171422 'END' ,
1418- ( ) => {
1423+ async ( ) => {
14191424 assert . strictEqual ( run ( '../_tmp/output/bundle.js' ) , 42 ) ;
14201425 // sometimes the watcher is triggered during the initial run
14211426 watchChangeIds . clear ( ) ;
1422- for ( const file_2 of watchFiles ) writeFileSync ( file_2 , 'changed' ) ;
1427+
1428+ await Promise . all ( watchFiles . map ( file => writeFile ( file , 'changed' ) ) ) ;
14231429 } ,
14241430 'START' ,
14251431 'BUNDLE_START' ,
@@ -1646,7 +1652,7 @@ describe('rollup.watch', () => {
16461652
16471653 it ( 'respects unlinked and re-added watched files' , async ( ) => {
16481654 await copy ( 'test/watch/samples/basic' , 'test/_tmp/input' ) ;
1649- writeFileSync ( 'test/_tmp/input/dep' , '' ) ;
1655+ await writeFile ( 'test/_tmp/input/dep' , '' ) ;
16501656 watcher = rollup . watch ( {
16511657 input : 'test/_tmp/input/main.js' ,
16521658 output : {
@@ -1693,7 +1699,7 @@ describe('rollup.watch', () => {
16931699 let transformRuns = 0 ;
16941700 await copy ( 'test/watch/samples/watch-files' , 'test/_tmp/input' ) ;
16951701 await wait ( 100 ) ;
1696- writeFileSync ( 'test/_tmp/input/alsoWatched' , 'initial' ) ;
1702+ await writeFile ( 'test/_tmp/input/alsoWatched' , 'initial' ) ;
16971703 watcher = rollup . watch ( {
16981704 input : 'test/_tmp/input/main.js' ,
16991705 output : {
0 commit comments