init() {
        context.middleware.write(`
          import { NextResponse } from 'next/server'
          import { hasUnusedDynamic } from 'lib'
          // populated with tests
          export default async function () {
            await hasUnusedDynamic()
            return NextResponse.next()
          }
          export const config = {
            unstable_allowDynamic: '**/node_modules/lib/**'
          }
        `)
        context.lib.write(`
          export async function hasUnusedDynamic() {
            if ((() => false)()) {
              eval('100')
            }
          }
        `)
      }
'
          }
        `)
        context.lib.write(`
          export async function hasDynamic() {
            eval('100')
          }
        `)
      },
      // TODO: Re-enable when Turbopack applies the middleware dynamic code
      // evaluation transforms also to code in node_modules.
      skip: Boolean(process.env.IS_TURBOPACK_TEST),
    },
  ])('$title with allowed, used dynamic code', ({ init, url, skip }) => {
    beforeEach(() => init())
    ;(skip ? it.skip : it)('still warns in dev at runtime', async () => {
      context.app = await launchApp(context.appDir, context.appPort, appOption)
      const res = await fetchViaHTTP(context.appPort, url)
      await waitFor(500)
      // eslint-disable-next-line jest/no-standalone-expect
      expect(res.status).toBe(200)
      // eslint-disable-next-line jest/no-standalone-expect
      expect(context.logs.output).toContain(
        `Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime`
      )
    })
  })

  describe.each([
    {
      title: 'Edge API',
      url: routeUrl,
      init() {
        context.api.write(`
          export default async function handler(request) {
            if ((() => false)()) {
              eval('100')
            }
            return Response.json({ result: true })
          }
          export const config = {
            runtime: 'edge',
            unstable_allowDynamic: '**'
          }
        `)
      },
    },
    {
      title: 'Middleware',
      url: middlewareUrl,
      init() {
        context.middleware.write(`
          import { NextResponse } from 'next/server'
          // populated with tests
          export default () => {
            if ((() => false)()) {
              eval('100')
            }
            return NextResponse.next()
          }
          export const config = {
            unstable_allowDynamic: '**'
          }
        `)
      },
    },
    {
      title: 'Edge API using lib',
      url: routeUrl,
      init() {
        context.api.write(`
          import { hasUnusedDynamic } from 'lib'
          export default async function handler(request) {
            await hasUnusedDynamic()
            return Response.json({ result: true })
          }
          export const config = {
            runtime: 'edge',
            unstable_allowDynamic: '*