File size: 1,435 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
48
49
50
51
52
53
54
55
56
import { createNext } from 'e2e-utils'
import { NextInstance } from 'e2e-utils'
import { check, renderViaHTTP } from 'next-test-utils'

describe('ENOENT during require', () => {
  let next: NextInstance

  beforeAll(async () => {
    next = await createNext({
      files: {
        'pages/_app.js': `
          import App from 'next/app'
          
          if (typeof window === 'undefined') {
            if (process.env.NEXT_PHASE !== 'phase-production-build') {
              require('fs').readdirSync('non-existent-folder')
            }
          }
          export default App
        `,
        'pages/index.js': `
          export function getStaticProps() {
            console.log('revalidate /')
            
            return {
              props: {
                now: Date.now()
              },
              revalidate: 1
            }
          }
          
          export default function Page() { 
            return <p>hello world</p>
          } 
        `,
      },
      dependencies: {},
    })
  })
  afterAll(() => next.destroy())

  it('should show ENOENT error correctly', async () => {
    await check(async () => {
      await renderViaHTTP(next.url, '/')
      console.error(next.cliOutput)

      return next.cliOutput.includes('non-existent-folder')
        ? 'success'
        : next.cliOutput
    }, 'success')

    expect(next.cliOutput).not.toContain('Cannot destructure property')
  })
})