|
1 |
| -import { createNext, FileRef } from 'e2e-utils' |
2 |
| -import { NextInstance } from 'e2e-utils' |
| 1 | +import { nextTestSetup } from 'e2e-utils' |
3 | 2 | import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
|
4 | 3 | import path from 'path'
|
5 | 4 | import { promises as fs } from 'fs'
|
6 | 5 | import { readJson } from 'fs-extra'
|
7 | 6 |
|
8 |
| -// TODO: `node-fetch` hangs on some of these tests in Node.js. |
9 |
| -// Re-enable when `node-fetch` is dropped. |
10 |
| -// See: https://github.com/vercel/next.js/pull/55112 |
11 |
| -describe.skip('Edge Compiler can import asset assets', () => { |
12 |
| - let next: NextInstance |
13 |
| - |
14 |
| - // TODO: remove after this is supported for deploy |
15 |
| - if ((global as any).isNextDeploy) { |
16 |
| - it('should skip for deploy for now', () => {}) |
17 |
| - return |
18 |
| - } |
19 |
| - |
20 |
| - beforeAll(async () => { |
21 |
| - next = await createNext({ |
22 |
| - files: new FileRef(path.join(__dirname, './app')), |
23 |
| - }) |
| 7 | +describe('Edge Compiler can import asset assets', () => { |
| 8 | + const { next, isTurbopack, isNextDeploy } = nextTestSetup({ |
| 9 | + files: path.join(__dirname, './app'), |
24 | 10 | })
|
25 |
| - afterAll(() => next.destroy()) |
26 | 11 |
|
27 | 12 | it('allows to fetch a remote URL', async () => {
|
28 | 13 | const response = await fetchViaHTTP(next.url, '/api/edge', {
|
@@ -66,33 +51,63 @@ describe.skip('Edge Compiler can import asset assets', () => {
|
66 | 51 | })
|
67 | 52 | })
|
68 | 53 |
|
69 |
| - it('extracts all the assets from the bundle', async () => { |
70 |
| - const manifestPath = path.join( |
71 |
| - next.testDir, |
72 |
| - '.next/server/middleware-manifest.json' |
73 |
| - ) |
74 |
| - const manifest = await readJson(manifestPath) |
75 |
| - const orderedAssets = manifest.functions['/api/edge'].assets.sort( |
76 |
| - (a, z) => { |
77 |
| - return String(a.name).localeCompare(z.name) |
78 |
| - } |
79 |
| - ) |
| 54 | + // Cannot read the file on deployment |
| 55 | + if (!isNextDeploy) { |
| 56 | + it('extracts all the assets from the bundle', async () => { |
| 57 | + const manifestPath = path.join( |
| 58 | + next.testDir, |
| 59 | + '.next/server/middleware-manifest.json' |
| 60 | + ) |
| 61 | + const manifest = await readJson(manifestPath) |
| 62 | + const orderedAssets = manifest.functions['/api/edge'].assets.sort( |
| 63 | + (a, z) => { |
| 64 | + return String(a.name).localeCompare(z.name) |
| 65 | + } |
| 66 | + ) |
80 | 67 |
|
81 |
| - expect(orderedAssets).toMatchObject([ |
82 |
| - { |
83 |
| - name: expect.stringMatching(/^text-file\.[0-9a-f]{16}\.txt$/), |
84 |
| - filePath: expect.stringMatching( |
85 |
| - /^server\/edge-chunks\/asset_text-file/ |
86 |
| - ), |
87 |
| - }, |
88 |
| - { |
89 |
| - name: expect.stringMatching(/^vercel\.[0-9a-f]{16}\.png$/), |
90 |
| - filePath: expect.stringMatching(/^server\/edge-chunks\/asset_vercel/), |
91 |
| - }, |
92 |
| - { |
93 |
| - name: expect.stringMatching(/^world\.[0-9a-f]{16}\.json/), |
94 |
| - filePath: expect.stringMatching(/^server\/edge-chunks\/asset_world/), |
95 |
| - }, |
96 |
| - ]) |
97 |
| - }) |
| 68 | + if (isTurbopack) { |
| 69 | + expect(orderedAssets).toMatchObject([ |
| 70 | + { |
| 71 | + name: expect.stringMatching( |
| 72 | + /server\/edge\/assets\/text-file\.[0-9a-f]{8}\.txt$/ |
| 73 | + ), |
| 74 | + filePath: expect.stringMatching(/^server\/edge\/assets\/text-file/), |
| 75 | + }, |
| 76 | + { |
| 77 | + name: expect.stringMatching( |
| 78 | + /^server\/edge\/assets\/vercel\.[0-9a-f]{8}\.png$/ |
| 79 | + ), |
| 80 | + filePath: expect.stringMatching(/^server\/edge\/assets\/vercel/), |
| 81 | + }, |
| 82 | + { |
| 83 | + name: expect.stringMatching( |
| 84 | + /^server\/edge\/assets\/world\.[0-9a-f]{8}\.json/ |
| 85 | + ), |
| 86 | + filePath: expect.stringMatching(/^server\/edge\/assets\/world/), |
| 87 | + }, |
| 88 | + ]) |
| 89 | + } else { |
| 90 | + expect(orderedAssets).toMatchObject([ |
| 91 | + { |
| 92 | + name: expect.stringMatching(/^text-file\.[0-9a-f]{16}\.txt$/), |
| 93 | + filePath: expect.stringMatching( |
| 94 | + /^server\/edge-chunks\/asset_text-file/ |
| 95 | + ), |
| 96 | + }, |
| 97 | + { |
| 98 | + name: expect.stringMatching(/^vercel\.[0-9a-f]{16}\.png$/), |
| 99 | + filePath: expect.stringMatching( |
| 100 | + /^server\/edge-chunks\/asset_vercel/ |
| 101 | + ), |
| 102 | + }, |
| 103 | + { |
| 104 | + name: expect.stringMatching(/^world\.[0-9a-f]{16}\.json/), |
| 105 | + filePath: expect.stringMatching( |
| 106 | + /^server\/edge-chunks\/asset_world/ |
| 107 | + ), |
| 108 | + }, |
| 109 | + ]) |
| 110 | + } |
| 111 | + }) |
| 112 | + } |
98 | 113 | })
|
0 commit comments