@@ -132,29 +132,51 @@ const throwNextTick = (e) => { process.nextTick(() => { throw e; }); };
132
132
. catch ( throwNextTick ) ;
133
133
}
134
134
135
- // test that appendFile accepts numbers.
136
- const filename4 = join ( tmpdir . path , 'append4.txt' ) ;
137
- fs . writeFileSync ( filename4 , currentFileData ) ;
135
+ // test that appendFile accepts numbers (callback API)
136
+ {
137
+ const filename = join ( tmpdir . path , 'append-numbers.txt' ) ;
138
+ fs . writeFileSync ( filename , currentFileData ) ;
138
139
139
- const m = 0o600 ;
140
- fs . appendFile ( filename4 , n , { mode : m } , function ( e ) {
141
- assert . ifError ( e ) ;
140
+ const m = 0o600 ;
141
+ fs . appendFile ( filename , n , { mode : m } , common . mustCall ( ( e ) => {
142
+ assert . ifError ( e ) ;
142
143
143
- ncallbacks ++ ;
144
+ // windows permissions aren't unix
145
+ if ( ! common . isWindows ) {
146
+ const st = fs . statSync ( filename ) ;
147
+ assert . strictEqual ( st . mode & 0o700 , m ) ;
148
+ }
144
149
145
- // windows permissions aren't unix
146
- if ( ! common . isWindows ) {
147
- const st = fs . statSync ( filename4 ) ;
148
- assert . strictEqual ( st . mode & 0o700 , m ) ;
149
- }
150
+ fs . readFile ( filename , common . mustCall ( ( e , buffer ) => {
151
+ assert . ifError ( e ) ;
152
+ assert . strictEqual ( Buffer . byteLength ( String ( n ) ) + currentFileData . length ,
153
+ buffer . length ) ;
154
+ } ) ) ;
155
+ } ) ) ;
156
+ }
150
157
151
- fs . readFile ( filename4 , function ( e , buffer ) {
152
- assert . ifError ( e ) ;
153
- ncallbacks ++ ;
154
- assert . strictEqual ( Buffer . byteLength ( String ( n ) ) + currentFileData . length ,
155
- buffer . length ) ;
156
- } ) ;
157
- } ) ;
158
+ // test that appendFile accepts numbers (promises API)
159
+ {
160
+ const filename = join ( tmpdir . path , 'append-numbers-promises.txt' ) ;
161
+ fs . writeFileSync ( filename , currentFileData ) ;
162
+
163
+ const m = 0o600 ;
164
+ fs . promises . appendFile ( filename , n , { mode : m } )
165
+ . then ( common . mustCall ( ( ) => {
166
+ // windows permissions aren't unix
167
+ if ( ! common . isWindows ) {
168
+ const st = fs . statSync ( filename ) ;
169
+ assert . strictEqual ( st . mode & 0o700 , m ) ;
170
+ }
171
+
172
+ return fs . promises . readFile ( filename ) ;
173
+ } ) )
174
+ . then ( ( buffer ) => {
175
+ assert . strictEqual ( Buffer . byteLength ( String ( n ) ) + currentFileData . length ,
176
+ buffer . length ) ;
177
+ } )
178
+ . catch ( throwNextTick ) ;
179
+ }
158
180
159
181
// test that appendFile accepts file descriptors
160
182
const filename5 = join ( tmpdir . path , 'append5.txt' ) ;
@@ -191,8 +213,7 @@ assert.throws(
191
213
{ code : 'ERR_INVALID_CALLBACK' } ) ;
192
214
193
215
process . on ( 'exit' , function ( ) {
194
- assert . strictEqual ( ncallbacks , 6 ) ;
216
+ assert . strictEqual ( ncallbacks , 4 ) ;
195
217
196
- fs . unlinkSync ( filename4 ) ;
197
218
fs . unlinkSync ( filename5 ) ;
198
219
} ) ;
0 commit comments