/
index.test.ts
48 lines (42 loc) · 1.18 KB
/
index.test.ts
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
import { createNext } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
describe('Disable fallback polyfills', () => {
let next: NextInstance
beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
import { useEffect } from 'react'
import crypto from 'crypto'
export default function Page() {
useEffect(() => {
crypto;
}, [])
return <p>hello world</p>
}
`,
},
dependencies: {},
})
await next.stop()
})
afterAll(() => next.destroy())
it('Fallback polyfills added by default', async () => {
const firstLoadJSSize = Number(
next.cliOutput.match(/○ \/\s{38}(\d*) kB\s{10}(?<firstLoad>\d*) kB/)
.groups.firstLoad
)
expect(firstLoadJSSize).not.toBeLessThan(200)
})
it('Build should fail, when fallback polyfilling is disabled', async () => {
await next.patchFile(
'next.config.js',
`module.exports = {
experimental: {
fallbackNodePolyfills: false
}
}`
)
await expect(next.start()).rejects.toThrow(/next build failed/)
})
})