|
1 | 1 | import { Buffer } from 'node:buffer'
|
2 |
| -import { writeFile } from 'node:fs/promises' |
3 | 2 | import { env, version as nodeVersion } from 'node:process'
|
4 | 3 |
|
5 | 4 | import semver from 'semver'
|
6 |
| -import tmp from 'tmp-promise' |
7 | 5 | import { describe, test, expect, beforeAll, afterEach } from 'vitest'
|
8 | 6 |
|
9 | 7 | import { MockFetch } from '../test/mock_fetch.js'
|
@@ -415,127 +413,6 @@ describe('set', () => {
|
415 | 413 | expect(mockStore.fulfilled).toBeTruthy()
|
416 | 414 | })
|
417 | 415 |
|
418 |
| - // We need `Readable.toWeb` to be available, which needs Node 16+. |
419 |
| - if (semver.gte(nodeVersion, '16.0.0')) { |
420 |
| - test('Accepts a file', async () => { |
421 |
| - const fileContents = 'Hello from a file' |
422 |
| - const mockStore = new MockFetch() |
423 |
| - .put({ |
424 |
| - headers: { authorization: `Bearer ${apiToken}` }, |
425 |
| - response: new Response(JSON.stringify({ url: signedURL })), |
426 |
| - url: `https://api.netlify.com/api/v1/sites/${siteID}/blobs/${key}?context=production`, |
427 |
| - }) |
428 |
| - .put({ |
429 |
| - body: async (body) => { |
430 |
| - expect(await streamToString(body as unknown as NodeJS.ReadableStream)).toBe(fileContents) |
431 |
| - }, |
432 |
| - headers: { |
433 |
| - 'cache-control': 'max-age=0, stale-while-revalidate=60', |
434 |
| - }, |
435 |
| - response: new Response(null), |
436 |
| - url: signedURL, |
437 |
| - }) |
438 |
| - |
439 |
| - globalThis.fetch = mockStore.fetcher |
440 |
| - |
441 |
| - const { cleanup, path } = await tmp.file() |
442 |
| - |
443 |
| - await writeFile(path, fileContents) |
444 |
| - |
445 |
| - const blobs = getStore({ |
446 |
| - name: 'production', |
447 |
| - token: apiToken, |
448 |
| - siteID, |
449 |
| - }) |
450 |
| - |
451 |
| - await blobs.setFile(key, path) |
452 |
| - |
453 |
| - expect(mockStore.fulfilled).toBeTruthy() |
454 |
| - |
455 |
| - await cleanup() |
456 |
| - }) |
457 |
| - |
458 |
| - test('Accepts multiple files concurrently', async () => { |
459 |
| - const contents = ['Hello from key-0', 'Hello from key-1', 'Hello from key-2'] |
460 |
| - const signedURLs = ['https://signed-url.aws/0', 'https://signed-url.aws/1', 'https://signed-url.aws/2'] |
461 |
| - |
462 |
| - const mockStore = new MockFetch() |
463 |
| - .put({ |
464 |
| - headers: { authorization: `Bearer ${apiToken}` }, |
465 |
| - response: new Response(JSON.stringify({ url: signedURLs[0] })), |
466 |
| - url: `https://api.netlify.com/api/v1/sites/${siteID}/blobs/key-0?context=production`, |
467 |
| - }) |
468 |
| - .put({ |
469 |
| - body: async (body) => { |
470 |
| - expect(await streamToString(body as unknown as NodeJS.ReadableStream)).toBe(contents[0]) |
471 |
| - }, |
472 |
| - headers: { |
473 |
| - 'cache-control': 'max-age=0, stale-while-revalidate=60', |
474 |
| - }, |
475 |
| - response: new Response(null), |
476 |
| - url: signedURLs[0], |
477 |
| - }) |
478 |
| - .put({ |
479 |
| - headers: { authorization: `Bearer ${apiToken}` }, |
480 |
| - response: new Response(JSON.stringify({ url: signedURLs[1] })), |
481 |
| - url: `https://api.netlify.com/api/v1/sites/${siteID}/blobs/key-1?context=production`, |
482 |
| - }) |
483 |
| - .put({ |
484 |
| - body: async (body) => { |
485 |
| - expect(await streamToString(body as unknown as NodeJS.ReadableStream)).toBe(contents[1]) |
486 |
| - }, |
487 |
| - headers: { |
488 |
| - 'cache-control': 'max-age=0, stale-while-revalidate=60', |
489 |
| - }, |
490 |
| - response: new Response(null), |
491 |
| - url: signedURLs[1], |
492 |
| - }) |
493 |
| - .put({ |
494 |
| - headers: { authorization: `Bearer ${apiToken}` }, |
495 |
| - response: new Response(JSON.stringify({ url: signedURLs[2] })), |
496 |
| - url: `https://api.netlify.com/api/v1/sites/${siteID}/blobs/key-2?context=production`, |
497 |
| - }) |
498 |
| - .put({ |
499 |
| - body: async (body) => { |
500 |
| - expect(await streamToString(body as unknown as NodeJS.ReadableStream)).toBe(contents[2]) |
501 |
| - }, |
502 |
| - headers: { |
503 |
| - 'cache-control': 'max-age=0, stale-while-revalidate=60', |
504 |
| - }, |
505 |
| - response: new Response(null), |
506 |
| - url: signedURLs[2], |
507 |
| - }) |
508 |
| - |
509 |
| - globalThis.fetch = mockStore.fetcher |
510 |
| - |
511 |
| - const writes = await Promise.all( |
512 |
| - contents.map(async (content) => { |
513 |
| - const { cleanup, path } = await tmp.file() |
514 |
| - |
515 |
| - await writeFile(path, content) |
516 |
| - |
517 |
| - return { cleanup, path } |
518 |
| - }), |
519 |
| - ) |
520 |
| - const files = writes.map(({ path }, idx) => ({ |
521 |
| - key: `key-${idx}`, |
522 |
| - path, |
523 |
| - })) |
524 |
| - |
525 |
| - const blobs = getStore({ |
526 |
| - name: 'production', |
527 |
| - token: apiToken, |
528 |
| - siteID, |
529 |
| - }) |
530 |
| - |
531 |
| - await blobs.setFiles(files) |
532 |
| - |
533 |
| - expect(mockStore.fulfilled).toBeTruthy() |
534 |
| - |
535 |
| - await Promise.all(writes.map(({ cleanup }) => cleanup())) |
536 |
| - }) |
537 |
| - } |
538 |
| - |
539 | 416 | test('Throws when the API returns a non-200 status code', async () => {
|
540 | 417 | const mockStore = new MockFetch().put({
|
541 | 418 | headers: { authorization: `Bearer ${apiToken}` },
|
|
0 commit comments