@@ -6,6 +6,7 @@ const fs = require('node:fs');
66const fsp = require ( 'node:fs/promises' ) ;
77const test = require ( 'node:test' ) ;
88const data = 'foo' ;
9+ const data2 = 'bar' ;
910let cnt = 0 ;
1011
1112function nextFile ( ) {
@@ -25,15 +26,27 @@ test('synchronous version', async (t) => {
2526
2627 await t . test ( 'performs flush' , ( t ) => {
2728 const spy = t . mock . method ( fs , 'fsyncSync' ) ;
29+ const checkCalls = ( expected ) => {
30+ const calls = spy . mock . calls ;
31+ assert . strictEqual ( calls . length , expected ) ;
32+ if ( expected === 0 ) return ;
33+ assert . strictEqual ( calls . at ( - 1 ) . result , undefined ) ;
34+ assert . strictEqual ( calls . at ( - 1 ) . error , undefined ) ;
35+ assert . strictEqual ( calls . at ( - 1 ) . arguments . length , 1 ) ;
36+ assert . strictEqual ( typeof calls . at ( - 1 ) . arguments [ 0 ] , 'number' ) ;
37+ } ;
38+
2839 const file = nextFile ( ) ;
40+
41+ checkCalls ( 0 ) ;
2942 fs . writeFileSync ( file , data , { flush : true } ) ;
30- const calls = spy . mock . calls ;
31- assert . strictEqual ( calls . length , 1 ) ;
32- assert . strictEqual ( calls [ 0 ] . result , undefined ) ;
33- assert . strictEqual ( calls [ 0 ] . error , undefined ) ;
34- assert . strictEqual ( calls [ 0 ] . arguments . length , 1 ) ;
35- assert . strictEqual ( typeof calls [ 0 ] . arguments [ 0 ] , 'number' ) ;
43+ checkCalls ( 1 ) ;
3644 assert . strictEqual ( fs . readFileSync ( file , 'utf8' ) , data ) ;
45+
46+ checkCalls ( 1 ) ;
47+ fs . writeFileSync ( file , data2 , { flush : true , encoding : 'utf8' } ) ;
48+ checkCalls ( 2 ) ;
49+ assert . strictEqual ( fs . readFileSync ( file , 'utf8' ) , data2 ) ;
3750 } ) ;
3851
3952 await t . test ( 'does not perform flush' , ( t ) => {
0 commit comments