@@ -21,7 +21,13 @@ const context = {
21
21
logs : { output : '' , stdout : '' , stderr : '' } ,
22
22
api : new File ( join ( __dirname , '../pages/api/route.js' ) ) ,
23
23
middleware : new File ( join ( __dirname , '../middleware.js' ) ) ,
24
- lib : new File ( join ( __dirname , '../lib/index.js' ) ) ,
24
+ lib : new File (
25
+ join (
26
+ __dirname ,
27
+ // Simulated .pnpm node_modules path:
28
+ '../node_modules/.pnpm/test/node_modules/lib/index.js'
29
+ )
30
+ ) ,
25
31
}
26
32
const appOption = {
27
33
env : { __NEXT_TEST_WITH_DEVTOOL : 1 } ,
@@ -74,7 +80,7 @@ describe('Edge runtime configurable guards', () => {
74
80
}
75
81
export const config = {
76
82
runtime: 'edge',
77
- unstable_allowDynamic: '/lib/**'
83
+ unstable_allowDynamic: '**/node_modules /lib/**'
78
84
}
79
85
` )
80
86
await waitFor ( 500 )
@@ -162,14 +168,14 @@ describe('Edge runtime configurable guards', () => {
162
168
url : routeUrl ,
163
169
init ( ) {
164
170
context . api . write ( `
165
- import { hasDynamic } from '../../ lib'
171
+ import { hasDynamic } from 'lib'
166
172
export default async function handler(request) {
167
173
await hasDynamic()
168
174
return Response.json({ result: true })
169
175
}
170
176
export const config = {
171
177
runtime: 'edge',
172
- unstable_allowDynamic: '/lib/**'
178
+ unstable_allowDynamic: '**/node_modules /lib/**'
173
179
}
174
180
` )
175
181
context . lib . write ( `
@@ -178,22 +184,25 @@ describe('Edge runtime configurable guards', () => {
178
184
}
179
185
` )
180
186
} ,
187
+ // TODO: Re-enable when Turbopack applies the middleware dynamic code
188
+ // evaluation transforms also to code in node_modules.
189
+ skip : Boolean ( process . env . TURBOPACK ) ,
181
190
} ,
182
191
{
183
192
title : 'Middleware using lib' ,
184
193
url : middlewareUrl ,
185
194
init ( ) {
186
195
context . middleware . write ( `
187
196
import { NextResponse } from 'next/server'
188
- import { hasDynamic } from './ lib'
197
+ import { hasDynamic } from 'lib'
189
198
190
199
// populated with tests
191
200
export default async function () {
192
201
await hasDynamic()
193
202
return NextResponse.next()
194
203
}
195
204
export const config = {
196
- unstable_allowDynamic: '/lib/**'
205
+ unstable_allowDynamic: '**/node_modules /lib/**'
197
206
}
198
207
` )
199
208
context . lib . write ( `
@@ -202,15 +211,19 @@ describe('Edge runtime configurable guards', () => {
202
211
}
203
212
` )
204
213
} ,
214
+ // TODO: Re-enable when Turbopack applies the middleware dynamic code
215
+ // evaluation transforms also to code in node_modules.
216
+ skip : Boolean ( process . env . TURBOPACK ) ,
205
217
} ,
206
- ] ) ( '$title with allowed, used dynamic code' , ( { init, url } ) => {
218
+ ] ) ( '$title with allowed, used dynamic code' , ( { init, url, skip } ) => {
207
219
beforeEach ( ( ) => init ( ) )
208
-
209
- it ( 'still warns in dev at runtime' , async ( ) => {
220
+ ; ( skip ? it . skip : it ) ( 'still warns in dev at runtime' , async ( ) => {
210
221
context . app = await launchApp ( context . appDir , context . appPort , appOption )
211
222
const res = await fetchViaHTTP ( context . appPort , url )
212
223
await waitFor ( 500 )
224
+ // eslint-disable-next-line jest/no-standalone-expect
213
225
expect ( res . status ) . toBe ( 200 )
226
+ // eslint-disable-next-line jest/no-standalone-expect
214
227
expect ( context . logs . output ) . toContain (
215
228
`Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime`
216
229
)
@@ -260,14 +273,14 @@ describe('Edge runtime configurable guards', () => {
260
273
url : routeUrl ,
261
274
init ( ) {
262
275
context . api . write ( `
263
- import { hasUnusedDynamic } from '../../ lib'
276
+ import { hasUnusedDynamic } from 'lib'
264
277
export default async function handler(request) {
265
278
await hasUnusedDynamic()
266
279
return Response.json({ result: true })
267
280
}
268
281
export const config = {
269
282
runtime: 'edge',
270
- unstable_allowDynamic: '/lib/**'
283
+ unstable_allowDynamic: '**/node_modules /lib/**'
271
284
}
272
285
` )
273
286
context . lib . write ( `
@@ -285,14 +298,14 @@ describe('Edge runtime configurable guards', () => {
285
298
init ( ) {
286
299
context . middleware . write ( `
287
300
import { NextResponse } from 'next/server'
288
- import { hasUnusedDynamic } from './ lib'
301
+ import { hasUnusedDynamic } from 'lib'
289
302
// populated with tests
290
303
export default async function () {
291
304
await hasUnusedDynamic()
292
305
return NextResponse.next()
293
306
}
294
307
export const config = {
295
- unstable_allowDynamic: '/lib/**'
308
+ unstable_allowDynamic: '**/node_modules /lib/**'
296
309
}
297
310
` )
298
311
context . lib . write ( `
@@ -340,7 +353,7 @@ describe('Edge runtime configurable guards', () => {
340
353
url : routeUrl ,
341
354
init ( ) {
342
355
context . api . write ( `
343
- import { hasDynamic } from '../../ lib'
356
+ import { hasDynamic } from 'lib'
344
357
export default async function handler(request) {
345
358
await hasDynamic()
346
359
return Response.json({ result: true })
@@ -356,14 +369,17 @@ describe('Edge runtime configurable guards', () => {
356
369
}
357
370
` )
358
371
} ,
372
+ // TODO: Re-enable when Turbopack applies the edge runtime transforms also
373
+ // to code in node_modules.
374
+ skip : Boolean ( process . env . TURBOPACK ) ,
359
375
} ,
360
376
{
361
377
title : 'Middleware using lib' ,
362
378
url : middlewareUrl ,
363
379
init ( ) {
364
380
context . middleware . write ( `
365
381
import { NextResponse } from 'next/server'
366
- import { hasDynamic } from './ lib'
382
+ import { hasDynamic } from 'lib'
367
383
export default async function () {
368
384
await hasDynamic()
369
385
return NextResponse.next()
@@ -378,20 +394,24 @@ describe('Edge runtime configurable guards', () => {
378
394
}
379
395
` )
380
396
} ,
397
+ // TODO: Re-enable when Turbopack applies the middleware dynamic code
398
+ // evaluation transforms also to code in node_modules.
399
+ skip : Boolean ( process . env . TURBOPACK ) ,
381
400
} ,
382
- ] ) ( '$title with unallowed, used dynamic code' , ( { init, url } ) => {
401
+ ] ) ( '$title with unallowed, used dynamic code' , ( { init, url, skip } ) => {
383
402
beforeEach ( ( ) => init ( ) )
384
-
385
- it ( 'warns in dev at runtime' , async ( ) => {
403
+ ; ( skip ? it . skip : it ) ( 'warns in dev at runtime' , async ( ) => {
386
404
context . app = await launchApp ( context . appDir , context . appPort , appOption )
387
405
const res = await fetchViaHTTP ( context . appPort , url )
388
406
await waitFor ( 500 )
407
+ // eslint-disable-next-line jest/no-standalone-expect
389
408
expect ( res . status ) . toBe ( 200 )
409
+ // eslint-disable-next-line jest/no-standalone-expect
390
410
expect ( context . logs . output ) . toContain (
391
411
`Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime`
392
412
)
393
413
} )
394
- ; ( process . env . TURBOPACK_DEV ? describe . skip : describe ) (
414
+ ; ( skip || process . env . TURBOPACK_DEV ? describe . skip : describe ) (
395
415
'production mode' ,
396
416
( ) => {
397
417
it ( 'fails to build because of dynamic code evaluation' , async ( ) => {
@@ -429,7 +449,7 @@ describe('Edge runtime configurable guards', () => {
429
449
init ( ) {
430
450
context . middleware . write ( `
431
451
import { NextResponse } from 'next/server'
432
- import { returnTrue } from './ lib'
452
+ import { returnTrue } from 'lib'
433
453
export default async function () {
434
454
(() => {}) instanceof Function
435
455
return NextResponse.next()
0 commit comments