@@ -312,49 +312,52 @@ describe('set', () => {
312
312
await blobs . set ( key , value , { ttl } )
313
313
} )
314
314
315
- test ( 'Accepts a file' , async ( ) => {
316
- expect . assertions ( 5 )
315
+ // We need `Readable.fromWeb` to be available, which needs Node 16+.
316
+ if ( semver . gte ( nodeVersion , '16.0.0' ) ) {
317
+ test ( 'Accepts a file' , async ( ) => {
318
+ expect . assertions ( 5 )
317
319
318
- const fileContents = 'Hello from a file'
319
- const fetcher = async ( ...args : Parameters < typeof globalThis . fetch > ) => {
320
- const [ url , options ] = args
321
- const headers = options ?. headers as Record < string , string >
320
+ const fileContents = 'Hello from a file'
321
+ const fetcher = async ( ...args : Parameters < typeof globalThis . fetch > ) => {
322
+ const [ url , options ] = args
323
+ const headers = options ?. headers as Record < string , string >
322
324
323
- expect ( options ?. method ) . toBe ( 'put' )
325
+ expect ( options ?. method ) . toBe ( 'put' )
324
326
325
- if ( url === `https://api.netlify.com/api/v1/sites/${ siteID } /blobs/${ key } ?context=production` ) {
326
- const data = JSON . stringify ( { url : signedURL } )
327
+ if ( url === `https://api.netlify.com/api/v1/sites/${ siteID } /blobs/${ key } ?context=production` ) {
328
+ const data = JSON . stringify ( { url : signedURL } )
327
329
328
- expect ( headers . authorization ) . toBe ( `Bearer ${ apiToken } ` )
330
+ expect ( headers . authorization ) . toBe ( `Bearer ${ apiToken } ` )
329
331
330
- return new Response ( data )
331
- }
332
+ return new Response ( data )
333
+ }
332
334
333
- if ( url === signedURL ) {
334
- expect ( await streamToString ( options ?. body as unknown as NodeJS . ReadableStream ) ) . toBe ( fileContents )
335
- expect ( headers [ 'cache-control' ] ) . toBe ( 'max-age=0, stale-while-revalidate=60' )
335
+ if ( url === signedURL ) {
336
+ expect ( await streamToString ( options ?. body as unknown as NodeJS . ReadableStream ) ) . toBe ( fileContents )
337
+ expect ( headers [ 'cache-control' ] ) . toBe ( 'max-age=0, stale-while-revalidate=60' )
336
338
337
- return new Response ( value )
339
+ return new Response ( value )
340
+ }
341
+
342
+ throw new Error ( `Unexpected fetch call: ${ url } ` )
338
343
}
339
344
340
- throw new Error ( `Unexpected fetch call: ${ url } ` )
341
- }
345
+ const { cleanup, path } = await tmp . file ( )
342
346
343
- const { cleanup , path } = await tmp . file ( )
347
+ await writeFile ( path , fileContents )
344
348
345
- await writeFile ( path , fileContents )
349
+ const blobs = new Blobs ( {
350
+ authentication : {
351
+ token : apiToken ,
352
+ } ,
353
+ fetcher,
354
+ siteID,
355
+ } )
346
356
347
- const blobs = new Blobs ( {
348
- authentication : {
349
- token : apiToken ,
350
- } ,
351
- fetcher,
352
- siteID,
357
+ await blobs . setFile ( key , path )
358
+ await cleanup ( )
353
359
} )
354
-
355
- await blobs . setFile ( key , path )
356
- await cleanup ( )
357
- } )
360
+ }
358
361
359
362
test ( 'Throws when the API returns a non-200 status code' , async ( ) => {
360
363
const fetcher = async ( ...args : Parameters < typeof globalThis . fetch > ) => {
0 commit comments