Skip to content

Commit

Permalink
Add a Node.js dep test
Browse files Browse the repository at this point in the history
  • Loading branch information
Schniz committed Jul 17, 2022
1 parent 9be0db2 commit 372196d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ const handlers = new Map([
return fetch(url)
},
],
[
'from-node-module',
async () => {
const url = new URL('my-pkg/hello/world.json', import.meta.url)
return fetch(url)
},
],
])

const defaultHandler = async () =>
Expand Down
26 changes: 23 additions & 3 deletions test/e2e/edge-compiler-can-import-blob-assets/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import path from 'path'
import { promises as fs } from 'fs'
import { readJson } from 'fs-extra'
import type { MiddlewareManifest } from 'next/build/webpack/plugins/middleware-plugin'

describe('Edge Compiler can import asset assets', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: new FileRef(path.join(__dirname, './app')),
dependencies: {},
})
})
afterAll(() => next.destroy())
Expand All @@ -34,13 +34,29 @@ describe('Edge Compiler can import asset assets', () => {
expect(buffer.equals(image)).toBeTrue()
})

it('allows to assets from node_modules', async () => {
const response = await fetchViaHTTP(next.url, '/api/edge', {
handler: 'from-node-module',
})
const json = await response.json()
expect(json).toEqual({
'i am': 'a node dependency',
})
})

it('extracts all the assets from the bundle', async () => {
const manifestPath = path.join(
next.testDir,
'.next/server/middleware-manifest.json'
)
const manifest = await readJson(manifestPath)
expect(manifest.functions['/api/edge'].assets).toMatchObject([
const manifest: MiddlewareManifest = await readJson(manifestPath)
const orderedAssets = manifest.functions['/api/edge'].assets.sort(
(a, z) => {
return String(a.name).localeCompare(z.name)
}
)

expect(orderedAssets).toMatchObject([
{
name: expect.stringMatching(/^text-file\.[0-9a-f]{16}\.txt$/),
filePath: expect.stringMatching(
Expand All @@ -51,6 +67,10 @@ describe('Edge Compiler can import asset assets', () => {
name: expect.stringMatching(/^vercel\.[0-9a-f]{16}\.png$/),
filePath: expect.stringMatching(/^server\/edge-chunks\/asset_vercel/),
},
{
name: expect.stringMatching(/^world\.[0-9a-f]{16}\.json/),
filePath: expect.stringMatching(/^server\/edge-chunks\/asset_world/),
},
])
})
})

0 comments on commit 372196d

Please sign in to comment.