@@ -87,24 +87,60 @@ function verifyStatObject(stat) {
87
87
stats = await stat ( dest ) ;
88
88
verifyStatObject ( stats ) ;
89
89
90
+ stats = await handle . stat ( ) ;
91
+ verifyStatObject ( stats ) ;
92
+
90
93
await fdatasync ( handle ) ;
94
+ await handle . datasync ( ) ;
91
95
await fsync ( handle ) ;
96
+ await handle . sync ( ) ;
92
97
93
- const buf = Buffer . from ( 'hello world ' ) ;
94
-
98
+ const buf = Buffer . from ( 'hello fsPromises ' ) ;
99
+ const bufLen = buf . length ;
95
100
await write ( handle , buf ) ;
96
-
97
- const ret = await read ( handle , Buffer . alloc ( 11 ) , 0 , 11 , 0 ) ;
98
- assert . strictEqual ( ret . bytesRead , 11 ) ;
101
+ const ret = await read ( handle , Buffer . alloc ( bufLen ) , 0 , bufLen , 0 ) ;
102
+ assert . strictEqual ( ret . bytesRead , bufLen ) ;
99
103
assert . deepStrictEqual ( ret . buffer , buf ) ;
100
104
105
+ const buf2 = Buffer . from ( 'hello FileHandle' ) ;
106
+ const buf2Len = buf2 . length ;
107
+ await handle . write ( buf2 , 0 , buf2Len , 0 ) ;
108
+ const ret2 = await handle . read ( Buffer . alloc ( buf2Len ) , 0 , buf2Len , 0 ) ;
109
+ assert . strictEqual ( ret2 . bytesRead , buf2Len ) ;
110
+ assert . deepStrictEqual ( ret2 . buffer , buf2 ) ;
111
+
101
112
await chmod ( dest , 0o666 ) ;
102
113
await fchmod ( handle , 0o666 ) ;
114
+ await handle . chmod ( 0o666 ) ;
115
+
116
+ // `mode` can't be > 0o777
117
+ assert . rejects (
118
+ async ( ) => chmod ( handle , ( 0o777 + 1 ) ) ,
119
+ {
120
+ code : 'ERR_INVALID_ARG_TYPE' ,
121
+ name : 'TypeError [ERR_INVALID_ARG_TYPE]'
122
+ }
123
+ ) ;
124
+ assert . rejects (
125
+ async ( ) => fchmod ( handle , ( 0o777 + 1 ) ) ,
126
+ {
127
+ code : 'ERR_OUT_OF_RANGE' ,
128
+ name : 'RangeError [ERR_OUT_OF_RANGE]'
129
+ }
130
+ ) ;
131
+ assert . rejects (
132
+ async ( ) => handle . chmod ( handle , ( 0o777 + 1 ) ) ,
133
+ {
134
+ code : 'ERR_INVALID_ARG_TYPE' ,
135
+ name : 'TypeError [ERR_INVALID_ARG_TYPE]'
136
+ }
137
+ ) ;
103
138
104
139
await utimes ( dest , new Date ( ) , new Date ( ) ) ;
105
140
106
141
try {
107
142
await futimes ( handle , new Date ( ) , new Date ( ) ) ;
143
+ await handle . utimes ( new Date ( ) , new Date ( ) ) ;
108
144
} catch ( err ) {
109
145
// Some systems do not have futimes. If there is an error,
110
146
// expect it to be ENOSYS
@@ -152,6 +188,15 @@ function verifyStatObject(stat) {
152
188
await rmdir ( newdir ) ;
153
189
154
190
await mkdtemp ( path . resolve ( tmpDir , 'FOO' ) ) ;
191
+ assert . rejects (
192
+ // mkdtemp() expects to get a string prefix.
193
+ async ( ) => mkdtemp ( 1 ) ,
194
+ {
195
+ code : 'ERR_INVALID_ARG_TYPE' ,
196
+ name : 'TypeError [ERR_INVALID_ARG_TYPE]'
197
+ }
198
+ ) ;
199
+
155
200
}
156
201
157
202
doTest ( ) . then ( common . mustCall ( ) ) ;
0 commit comments