cd66e765e0
As discussed in https://vercel.slack.com/archives/C03ENM5HB4K/p1687999628589119 and #51910, it makes sense to have a known list for packages (mostly polyfills) that we know are having dynamic code (`eval`, `new Function`) but are safe to run in the Edge Runtime because that dynamic code will never be executed.
41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { createNext } from 'e2e-utils'
|
|
import { NextInstance } from 'test/lib/next-modes/base'
|
|
|
|
// This test is basically for https://github.com/vercel/next.js/discussions/51910
|
|
// to make sure that some libs that we know are using `eval` but don't break
|
|
// because it will never run into that condition, but still can't to be DCE'd.
|
|
|
|
describe('Edge safe dynamic code', () => {
|
|
let next: NextInstance
|
|
|
|
afterAll(() => next.destroy())
|
|
|
|
it('should not fail when "function-bind" package is used', async () => {
|
|
next = await createNext({
|
|
skipStart: true,
|
|
dependencies: {
|
|
'function-bind': 'latest',
|
|
},
|
|
files: {
|
|
'pages/index.js': `
|
|
export default function Page() {
|
|
return <p>hello world</p>
|
|
}
|
|
`,
|
|
'middleware.js': `
|
|
import { NextResponse } from 'next/server'
|
|
import * as bind from 'function-bind'
|
|
console.log(bind)
|
|
export default async function middleware(request) {
|
|
return NextResponse.next()
|
|
}
|
|
`,
|
|
},
|
|
})
|
|
await next.start()
|
|
|
|
expect(next.cliOutput).not.toContain(
|
|
`Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime`
|
|
)
|
|
})
|
|
})
|