init() {
        context.middleware.write(`
          import { NextResponse } from 'next/server'
          import { hasDynamic } from 'lib'

          // populated with tests
          export default async function () {
            await hasDynamic()
            return NextResponse.next()
          }
          export const config = {
            unstable_allowDynamic: '**/node_modules/lib/**'
          }
        `)
        context.lib.write(`
          export async function hasDynamic() {
            eval('100')
          }
        `)
      }
'
        }
      `)
      await waitFor(500)
    })

    it('warns in dev for allowed code', async () => {
      context.app = await launchApp(context.appDir, context.appPort, appOption)
      const res = await fetchViaHTTP(context.appPort, middlewareUrl)
      await waitFor(500)
      expect(res.status).toBe(200)
      await retry(async () => {
        expect(context.logs.output).toContain(
          `Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime`
        )
      })
    })

    it('warns in dev for unallowed code', async () => {
      context.app = await launchApp(context.appDir, context.appPort, appOption)
      const res = await fetchViaHTTP(context.appPort, routeUrl)
      expect(res.status).toBe(200)
      await retry(async () => {
        expect(context.logs.output).toContain(
          `Dynamic Code Evaluation (e. g. 'eval', 'new Function') not allowed in Edge Runtime`
        )
      })
    })
    ;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
      'production mode',
      () => {
        it('fails to build because of unallowed code', async () => {
          const output = await nextBuild(context.appDir, undefined, {
            stdout: true,
            stderr: true,
            env: process.env.IS_TURBOPACK_TEST
              ? {}
              : { NEXT_TELEMETRY_DEBUG: 1 },
          })

          expect(output.code).toBe(1)
          if (!process.env.IS_TURBOPACK_TEST) {
            expect(output.stderr).toContain(`./pages/api/route.js`)
          }
          expect(output.stderr).toContain(
            `Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime`
          )
          if (!process.env.IS_TURBOPACK_TEST) {
            expect(output.stderr).toContain(`Used by default`)
            expect(output.stderr).toContain(TELEMETRY_EVENT_NAME)
          }
        })
      }
    )
  })

  describe.each([
    {
      title: 'Edge API',
      url: routeUrl,
      init() {
        context.api.write(`
          export default async function handler(request) {
            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'

          export default () => {
            eval('100')
            return NextResponse.next()
          }
          export const config = {
            unstable_allowDynamic: '**'
          }
        `)
      },
    },
    {
      title: 'Edge API using lib',
      url: routeUrl,
      init() {
        context.api.write(`
          import { hasDynamic } from 'lib'
          export default async function handler(request) {
            await hasDynamic()
            return Response.json({ result: true })
          }
          export const config = {
            runtime: 'edge',
            unstable_allowDynamic: '*