10000 test: ensure dynamic imports are not instrumented in edge · vercel/next.js@44dfe9e · GitHub
[go: up one dir, main page]

Skip to content

Commit 44dfe9e

Browse files
committed
test: ensure dynamic imports are not instrumented in edge
1 parent 406ccfd commit 44dfe9e

File tree

6 files changed

+43
-0
lines changed

6 files changed

+43
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { title: 'hello' }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export const runtime = 'edge'
2+
3+
export async function GET(_request: Request) {
4+
// This import should not be instrumented, because edge routes are never prerendered.
5+
// `trackDynamicImport` will throw if it's used in the edge runtime,
6+
// so it's enough to just do an import() here and see if it succeeds.
7+
const messages = (await import('./messages')).default
8+
return new Response(messages.title)
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This page is only used as a matcher target for the middleware.
2+
3+
export default function Page() {
4+
return 'hello'
5+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default { title: 'hello' }
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { MiddlewareConfig } from 'next/server'
2+
3+
export default async function middleware() {
4+
// This import should not be instrumented.
5+
// `trackDynamicImport` will throw if it's used in the edge runtime,
6+
// so it's enough to just do an import() here and see if it succeeds.
7+
await import('./messages')
8+
}
9+
10+
export const config: MiddlewareConfig = {
11+
matcher: ['/not-instrumented/middleware'],
12+
}

test/e2e/app-dir/dynamic-io-dynamic-imports/dynamic-io-dynamic-imports.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('async imports in dynamicIO', () => {
5050
"/inside-render/server/from-node-modules/esm/async-module",
5151
"/inside-render/server/from-node-modules/esm/sync-module",
5252
"/inside-render/server/sync-module",
53+
"/not-instrumented/middleware",
5354
"/outside-of-render/client/async-module",
5455
"/outside-of-render/client/sync-module",
5556
"/outside-of-render/server/async-module",
@@ -154,6 +155,20 @@ describe('async imports in dynamicIO', () => {
154155
})
155156
})
156157
})
158+
159+
describe('are not instrumented in edge', () => {
160+
it('middleware', async () => {
161+
// indirectly tests the behavior of middleware by rendering a page which the middleware matches
162+
await testPage('/not-instrumented/middleware')
163+
})
164+
165+
it('edge route handler', async () => {
166+
const result = await next
167+
.fetch('/not-instrumented/edge-route-handler')
168+
.then((res) => res.text())
169+
expect(result).toBe('hello')
170+
})
171+
})
157172
})
158173

159174
describe('async imports in dynamicIO - external packages', () => {

0 commit comments

Comments
 (0)
0