@@ -162,13 +162,19 @@ test('Reading after modified should fail', async t => {
162
162
await new Promise ( resolve => {
163
163
setTimeout ( resolve , 100 ) ;
164
164
} ) ;
165
- const now = new Date ( ) ;
166
- // Change modified time
167
- fs . utimesSync ( './LICENSE' , now , now ) ;
165
+ fs . closeSync ( fs . openSync ( './LICENSE' , 'a' ) ) ;
168
166
const error = await t . throwsAsync ( blob . text ( ) ) ;
169
167
t . is ( error . constructor . name , 'DOMException' ) ;
170
168
t . is ( error instanceof Error , true ) ;
171
169
t . is ( error . name , 'NotReadableError' ) ;
170
+
171
+ const file = fileFromSync ( './LICENSE' ) ;
172
+ // Above test updates the last modified date to now
173
+ t . is ( typeof file . lastModified , 'number' ) ;
174
+ // The lastModifiedDate is deprecated and removed from spec
175
+ t . false ( 'lastModifiedDate' in file ) ;
176
+ const mod = file . lastModified - Date . now ( ) ;
177
+ t . true ( mod <= 0 && mod >= - 100 ) ; // Close to tolerance: 0.100ms
172
178
} ) ;
173
179
174
180
test ( 'Reading file after modified should fail' , async t => {
@@ -297,13 +303,29 @@ test('fileFrom(path, type) sets the type', async t => {
297
303
t . is ( file . type , 'text/plain' ) ;
298
304
} ) ;
299
305
300
- test ( 'fileFrom(path, type) read/sets the lastModified ' , async t => {
301
- const file = await fileFrom ( './LICENSE' , 'text/plain' ) ;
302
- // Earlier test updates the last modified date to now
303
- t . is ( typeof file . lastModified , 'number' ) ;
304
- // The lastModifiedDate is deprecated and removed from spec
305
- t . false ( 'lastModifiedDate' in file ) ;
306
- t . is ( file . lastModified > Date . now ( ) - 60000 , true ) ;
306
+ test ( 'new File(,,{lastModified: 100})' , t => {
307
+ const mod = new File ( [ ] , '' , { lastModified : 100 } ) . lastModified ;
308
+ t . is ( mod , 100 ) ;
309
+ } ) ;
310
+
311
+ test ( 'new File(,,{lastModified: "200"})' , t => {
312
+ const mod = new File ( [ ] , '' , { lastModified : '200' } ) . lastModified ;
313
+ t . is ( mod , 200 ) ;
314
+ } ) ;
315
+
316
+ test ( 'new File(,,{lastModified: true})' , t => {
317
+ const mod = new File ( [ ] , '' , { lastModified : true } ) . lastModified ;
318
+ t . is ( mod , 1 ) ;
319
+ } ) ;
320
+
321
+ test ( 'new File(,,{lastModified: new Date()})' , t => {
322
+ const mod = new File ( [ ] , '' , { lastModified : new Date ( ) } ) . lastModified - Date . now ( ) ;
323
+ t . true ( mod <= 0 && mod >= - 20 ) ; // Close to tolerance: 0.020ms
324
+ } ) ;
325
+
326
+ test ( 'new File(,,{}) sets current time' , t => {
327
+ const mod = new File ( [ ] , '' ) . lastModified - Date . now ( ) ;
328
+ t . true ( mod <= 0 && mod >= - 20 ) ; // Close to tolerance: 0.020ms
307
329
} ) ;
308
330
309
331
test ( 'blobFrom(path, type) sets the type' , async t => {
0 commit comments