11'use strict' ;
22
3- const fs = require ( 'fs' ) ;
3+ const {
4+ createReadStream,
5+ createWriteStream,
6+ } = require ( 'fs' ) ;
7+ const { readFile, unlink} = require ( 'fs/promises' ) ;
48const os = require ( 'os' ) ;
59const { join} = require ( 'path' ) ;
610
@@ -18,8 +22,8 @@ test('files: read', async (t) => {
1822 const result = await files . read ( names ) ;
1923
2024 const expected = {
21- [ `${ dir } /package.json` ] : fs . readFileSync ( `${ dir } /package.json` ) ,
22- [ `${ dir } /README.md` ] : fs . readFileSync ( `${ dir } /README.md` ) ,
25+ [ `${ dir } /package.json` ] : await readFile ( `${ dir } /package.json` ) ,
26+ [ `${ dir } /README.md` ] : await readFile ( `${ dir } /README.md` ) ,
2327 } ;
2428
2529 t . deepEqual ( result , expected , 'should equal' ) ;
@@ -33,7 +37,7 @@ test('files: pipe', async (t) => {
3337
3438 const [ e ] = await tryToCatch ( files . pipe , from , to ) ;
3539
36- fs . unlinkSync ( to ) ;
40+ await unlink ( to ) ;
3741
3842 t . notOk ( e , 'should not be error' ) ;
3943 t . end ( ) ;
@@ -48,7 +52,7 @@ test('files: pipe: gzip', async (t) => {
4852 gzip : true ,
4953 } ) ;
5054
51- fs . unlinkSync ( to ) ;
55+ await unlink ( to ) ;
5256
5357 t . notOk ( e , 'should not be error' ) ;
5458 t . end ( ) ;
@@ -80,7 +84,7 @@ test('files: pipe: range', async (t) => {
8084 } ,
8185 } ) ;
8286
83- fs . unlinkSync ( to ) ;
87+ await unlink ( to ) ;
8488
8589 t . notOk ( e , 'should not be error' ) ;
8690 t . end ( ) ;
@@ -90,12 +94,12 @@ test('files: pipe: streams', async (t) => {
9094 const tmpDir = os . tmpdir ( ) ;
9195 const from = join ( __dirname , '..' , 'README.md' ) ;
9296 const to = join ( tmpDir , 'README_COPY.gz' ) ;
93- const fromStream = fs . createReadStream ( from ) ;
94- const toStream = fs . createWriteStream ( to ) ;
97+ const fromStream = createReadStream ( from ) ;
98+ const toStream = createWriteStream ( to ) ;
9599
96100 const [ e ] = await tryToCatch ( files . pipe , fromStream , toStream ) ;
97101
98- fs . unlinkSync ( to ) ;
102+ await unlink ( to ) ;
99103
100104 t . notOk ( e , 'should not be error' ) ;
101105 t . end ( ) ;
@@ -106,11 +110,11 @@ test('files: readPipe', async (t) => {
106110 const file1 = join ( __dirname , '..' , 'README.md' ) ;
107111 const file2 = join ( __dirname , '..' , 'package.json' ) ;
108112 const to = join ( tmpDir , 'README_COPY.gz' ) ;
109- const stream = fs . createWriteStream ( to ) ;
113+ const stream = createWriteStream ( to ) ;
110114
111115 const [ e ] = await tryToCatch ( files . readPipe , [ file1 , file2 ] , stream ) ;
112116
113- fs . unlinkSync ( to ) ;
117+ await unlink ( to ) ;
114118
115119 t . notOk ( e , 'should not be error' ) ;
116120 t . end ( ) ;
0 commit comments