@@ -162,13 +162,19 @@ test('Reading after modified should fail', async t => {
162162 await new Promise ( resolve => {
163163 setTimeout ( resolve , 100 ) ;
164164 } ) ;
165- const now = new Date ( ) ;
166- // Change modified time
167- fs . utimesSync ( './LICENSE' , now , now ) ;
165+ fs . closeSync ( fs . openSync ( './LICENSE' , 'a' ) ) ;
168166 const error = await t . throwsAsync ( blob . text ( ) ) ;
169167 t . is ( error . constructor . name , 'DOMException' ) ;
170168 t . is ( error instanceof Error , true ) ;
171169 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
172178} ) ;
173179
174180test ( 'Reading file after modified should fail' , async t => {
@@ -297,13 +303,29 @@ test('fileFrom(path, type) sets the type', async t => {
297303 t . is ( file . type , 'text/plain' ) ;
298304} ) ;
299305
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
307329} ) ;
308330
309331test ( 'blobFrom(path, type) sets the type' , async t => {
0 commit comments