Skip to content

Commit 732c499

Browse files
committed
chore: skip test on Node <16
1 parent cd1cf8d commit 732c499

File tree

1 file changed

+33
-30
lines changed

1 file changed

+33
-30
lines changed

src/main.test.ts

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -312,49 +312,52 @@ describe('set', () => {
312312
await blobs.set(key, value, { ttl })
313313
})
314314

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)
317319

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>
322324

323-
expect(options?.method).toBe('put')
325+
expect(options?.method).toBe('put')
324326

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 })
327329

328-
expect(headers.authorization).toBe(`Bearer ${apiToken}`)
330+
expect(headers.authorization).toBe(`Bearer ${apiToken}`)
329331

330-
return new Response(data)
331-
}
332+
return new Response(data)
333+
}
332334

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')
336338

337-
return new Response(value)
339+
return new Response(value)
340+
}
341+
342+
throw new Error(`Unexpected fetch call: ${url}`)
338343
}
339344

340-
throw new Error(`Unexpected fetch call: ${url}`)
341-
}
345+
const { cleanup, path } = await tmp.file()
342346

343-
const { cleanup, path } = await tmp.file()
347+
await writeFile(path, fileContents)
344348

345-
await writeFile(path, fileContents)
349+
const blobs = new Blobs({
350+
authentication: {
351+
token: apiToken,
352+
},
353+
fetcher,
354+
siteID,
355+
})
346356

347-
const blobs = new Blobs({
348-
authentication: {
349-
token: apiToken,
350-
},
351-
fetcher,
352-
siteID,
357+
await blobs.setFile(key, path)
358+
await cleanup()
353359
})
354-
355-
await blobs.setFile(key, path)
356-
await cleanup()
357-
})
360+
}
358361

359362
test('Throws when the API returns a non-200 status code', async () => {
360363
const fetcher = async (...args: Parameters<typeof globalThis.fetch>) => {

0 commit comments

Comments
 (0)