File size: 1,629 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { nextTestSetup } from 'e2e-utils'

describe('Dynamic Code Evaluation (DCE)', () => {
  const { next } = nextTestSetup({
    skipStart: true,
    dependencies: { 'function-bind': 'latest' },
    files: __dirname,
  })

  // 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.
  it('should not fail when "function-bind" package is used', async () => {
    const { exitCode, cliOutput } = await next.build()
    expect(exitCode).toBe(0)
    expect(cliOutput).not.toContain(
      `Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime`
    )
  })
  ;(process.env.IS_TURBOPACK_TEST ? it.skip : it)(
    "should show the user's import trace",
    async () => {
      await next.patchFile(
        'middleware.js',
        `
      import { foo } from './lib/foo'
      export function middleware() {
        foo()
      }`
      )
      const { exitCode, cliOutput } = await next.build()
      // eslint-disable-next-line jest/no-standalone-expect
      expect(exitCode).toBe(1)

      // eslint-disable-next-line jest/no-standalone-expect
      expect(cliOutput).toContain(`./lib/foo.js
Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime 
Used by bar`)

      // eslint-disable-next-line jest/no-standalone-expect
      expect(cliOutput).toContain(`Import trace for requested module:
  ./lib/foo.js
  ./middleware.js`)
    }
  )
})