Skip to content

Commit f4f8dd9

Browse files
committed
Fix edge-runtime-dynamic-code test
1 parent affe796 commit f4f8dd9

File tree

4 files changed

+57
-49
lines changed

4 files changed

+57
-49
lines changed

test/integration/edge-runtime-dynamic-code/lib/utils.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
export const useCases = {
2-
eval: 'using-eval',
3-
noEval: 'not-using-eval',
4-
wasmCompile: 'using-webassembly-compile',
5-
wasmInstanciate: 'using-webassembly-instantiate',
6-
wasmBufferInstanciate: 'using-webassembly-instantiate-with-buffer',
7-
}
8-
91
export async function usingEval() {
102
// eslint-disable-next-line no-eval
113
return { value: eval('100') }
Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,39 @@
11
import { NextResponse } from 'next/server'
2-
import { useCases, notUsingEval, usingEval } from './lib/utils'
2+
import { notUsingEval, usingEval } from './lib/utils'
33
import {
44
usingWebAssemblyCompile,
55
usingWebAssemblyInstantiate,
66
usingWebAssemblyInstantiateWithBuffer,
77
} from './lib/wasm'
88

99
export async function middleware(request) {
10-
if (request.nextUrl.pathname === `/${useCases.eval}`) {
10+
if (request.nextUrl.pathname === '/using-eval') {
1111
return new Response(null, {
1212
headers: { data: JSON.stringify(await usingEval()) },
1313
})
1414
}
1515

16-
if (request.nextUrl.pathname === `/${useCases.noEval}`) {
16+
if (request.nextUrl.pathname === '/not-using-eval') {
1717
return new Response(null, {
1818
headers: { data: JSON.stringify(await notUsingEval()) },
1919
})
2020
}
2121

22-
if (request.nextUrl.pathname === `/${useCases.wasmCompile}`) {
22+
if (request.nextUrl.pathname === '/using-webassembly-compile') {
2323
return new Response(null, {
2424
headers: { data: JSON.stringify(await usingWebAssemblyCompile(9)) },
2525
})
2626
}
2727

28-
if (request.nextUrl.pathname === `/${useCases.wasmInstanciate}`) {
28+
if (request.nextUrl.pathname === '/using-webassembly-instantiate') {
2929
return new Response(null, {
3030
headers: { data: JSON.stringify(await usingWebAssemblyInstantiate(9)) },
3131
})
3232
}
3333

34-
if (request.nextUrl.pathname === `/${useCases.wasmBufferInstanciate}`) {
34+
if (
35+
request.nextUrl.pathname === '/using-webassembly-instantiate-with-buffer'
36+
) {
3537
return new Response(null, {
3638
headers: {
3739
data: JSON.stringify(await usingWebAssemblyInstantiateWithBuffer(9)),
@@ -43,5 +45,11 @@ export async function middleware(request) {
4345
}
4446

4547
export const config = {
46-
matcher: Object.values(useCases).map((route) => `/${route}`),
48+
matcher: [
49+
'/using-eval',
50+
'/not-using-eval',
51+
'/using-webassembly-compile',
52+
'/using-webassembly-instantiate',
53+
'/using-webassembly-instantiate-with-buffer',
54+
],
4755
}
Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useCases, notUsingEval, usingEval } from '../../lib/utils'
1+
import { notUsingEval, usingEval } from '../../lib/utils'
22
import {
33
usingWebAssemblyCompile,
44
usingWebAssemblyInstantiate,
@@ -8,19 +8,27 @@ import {
88
export default async function handler(request) {
99
const useCase = request.nextUrl.searchParams.get('case')
1010

11-
return Response.json(
12-
useCase === useCases.eval
13-
? await usingEval()
14-
: useCase === useCases.noEval
15-
? await notUsingEval()
16-
: useCase === useCases.wasmCompile
17-
? await usingWebAssemblyCompile(9)
18-
: useCase === useCases.wasmInstanciate
19-
? await usingWebAssemblyInstantiate(9)
20-
: useCase === useCases.wasmBufferInstanciate
21-
? await usingWebAssemblyInstantiateWithBuffer(9)
22-
: { ok: true }
23-
)
11+
if (useCase === 'using-eval') {
12+
return Response.json(await usingEval())
13+
}
14+
15+
if (useCase === 'not-using-eval') {
16+
return Response.json(await notUsingEval())
17+
}
18+
19+
if (useCase === 'using-webassembly-compile') {
20+
return Response.json(await usingWebAssemblyCompile(9))
21+
}
22+
23+
if (useCase === 'using-webassembly-instantiate') {
24+
return Response.json(await usingWebAssemblyInstantiate(9))
25+
}
26+
27+
if (useCase === 'using-webassembly-instantiate-with-buffer') {
28+
return Response.json(await usingWebAssemblyInstantiateWithBuffer(9))
29+
}
30+
31+
return Response.json({ ok: true })
2432
}
2533

2634
export const config = { runtime: 'edge' }

test/integration/edge-runtime-dynamic-code/test/index.test.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('Page using eval in development mode', () => {
4242
beforeEach(() => (output = ''))
4343
afterAll(() => killApp(context.app))
4444

45-
it('does issue dynamic code evaluation warnings', async () => {
45+
it('does not issue dynamic code evaluation warnings', async () => {
4646
const html = await renderViaHTTP(context.appPort, '/')
4747
expect(html).toMatch(/>.*?100.*?and.*?100.*?<\//)
4848
await waitFor(500)
@@ -108,10 +108,10 @@ describe.each([
108108
isTurbopack
109109
? '' +
110110
// TODO(veil): Turbopack duplicates project path
111-
'\n at usingEval (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/utils.js:11:17)' +
111+
'\n at usingEval (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/utils.js:3:17)' +
112112
'\n at middleware (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/middleware.js:12:54)' +
113-
'\n 9 | export async function usingEval() {'
114-
: '\n at usingEval (../../test/integration/edge-runtime-dynamic-code/lib/utils.js:11:19)' +
113+
'\n 1 | export async function usingEval() {'
114+
: '\n at usingEval (../../test/integration/edge-runtime-dynamic-code/lib/utils.js:3:19)' +
115115
'\n at middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:12:54)' +
116116
// Next.js internal frame. Feel free to adjust.
117117
// Not ignore-listed because we're not in an isolated app and Next.js is symlinked so it's not in node_modules
@@ -122,27 +122,27 @@ describe.each([
122122
isTurbopack
123123
? '' +
124124
// TODO(veil): Turbopack duplicates project path
125-
'\n at usingEval (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/utils.js:11:17)' +
126-
'\n at handler (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:13:24)' +
127-
'\n 9 | export async function usingEval() {'
128-
: '\n at usingEval (../../test/integration/edge-runtime-dynamic-code/lib/utils.js:11:19)' +
129-
'\n at handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:13:24)' +
130-
'\n 9 | export async function usingEval() {'
125+
'\n at usingEval (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/utils.js:3:17)' +
126+
'\n at handler (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:12:41)' +
127+
'\n 1 | export async function usingEval() {'
128+
: '\n at usingEval (../../test/integration/edge-runtime-dynamic-code/lib/utils.js:3:19)' +
129+
'\n at handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:12:41)' +
130+
'\n 1 | export async function usingEval() {'
131131
)
132132
}
133133

134134
// Turbopack produces incorrect mappings in the sourcemap.
135135
if (isTurbopack) {
136136
expect(output).toContain(
137137
'' +
138-
"\n> 11 | return { value: eval('100') }" +
139-
'\n | ^'
138+
"\n> 3 | return { value: eval('100') }" +
139+
'\n | ^'
140140
)
141141
} else {
142142
expect(output).toContain(
143143
'' +
144-
"\n> 11 | return { value: eval('100') }" +
145-
'\n | ^'
144+
"\n> 3 | return { value: eval('100') }" +
145+
'\n | ^'
146146
)
147147
}
148148
})
@@ -189,11 +189,11 @@ describe.each([
189189
? '' +
190190
// TODO(veil): Turbopack duplicates project path
191191
'\n at usingWebAssemblyCompile (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/wasm.js:22:18)' +
192-
'\n at handler (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:17:42)' +
192+
'\n at handler (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:20:55)' +
193193
'\n 20 |'
194194
: '' +
195195
'\n at usingWebAssemblyCompile (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:22:24)' +
196-
'\n at handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:17:42)' +
196+
'\n at handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:20:55)' +
197197
// Next.js internal frame. Feel free to adjust.
198198
// Not ignore-listed because we're not in an isolated app and Next.js is symlinked so it's not in node_modules
199199
'\n at'
@@ -230,11 +230,11 @@ describe.each([
230230
isTurbopack
231231
? '' +
232232
'\n at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:24)' +
233-
'\n at async middleware (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/middleware.js:37:30)' +
233+
'\n at async middleware (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/middleware.js:39:30)' +
234234
'\n 26 |\n'
235235
: '' +
236236
'\n at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:24)' +
237-
'\n at async middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:37:30)' +
237+
'\n at async middleware (../../test/integration/edge-runtime-dynamic-code/middleware.js:39:30)' +
238238
// Next.js internal frame. Feel free to adjust.
239239
// TODO(veil): https://linear.app/vercel/issue/NDX-464
240240
'\n at '
@@ -250,11 +250,11 @@ describe.each([
250250
? '' +
251251
// TODO(veil): Turbopack duplicates project path
252252
'\n at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:24)' +
253-
'\n at async handler (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:21:17)' +
253+
'\n at async handler (../../test/integration/edge-runtime-dynamic-code/test/integration/edge-runtime-dynamic-code/pages/api/route.js:28:26)' +
254254
'\n 26 |'
255255
: '' +
256256
'\n at async usingWebAssemblyInstantiateWithBuffer (../../test/integration/edge-runtime-dynamic-code/lib/wasm.js:28:24)' +
257-
'\n at async handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:21:17)' +
257+
'\n at async handler (../../test/integration/edge-runtime-dynamic-code/pages/api/route.js:28:26)' +
258258
// Next.js internal frame. Feel free to adjust.
259259
// Not ignore-listed because we're not in an isolated app and Next.js is symlinked so it's not in node_modules
260260
'\n at'

0 commit comments

Comments
 (0)