File size: 5,007 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
import { nextTestSetup } from 'e2e-utils'
import stripAnsi from 'strip-ansi'
import { outdent } from 'outdent'
describe('production - app dir - build output', () => {
const { next } = nextTestSetup({
files: __dirname,
})
let output = ''
beforeAll(() => {
output = stripAnsi(next.cliOutput)
})
it('should only log app routes', async () => {
expect(output).toContain('Route (app)')
expect(output).not.toContain('Route (pages)')
expect(output).not.toContain('/favicon.ico')
})
it('should always log version first then the rest jobs', async () => {
const indexOfVersion = output.indexOf('▲ Next.js')
const indexOfStartCompiling = output.indexOf(
'Creating an optimized production build'
)
const indexOfLinting = output.indexOf(
'Linting and checking validity of types'
)
expect(indexOfVersion).toBeLessThan(indexOfLinting)
expect(indexOfStartCompiling).toBeLessThan(indexOfLinting)
})
it('should match the expected output format', async () => {
expect(output).toContain('Size')
expect(output).toContain('First Load JS')
expect(output).toContain('+ First Load JS shared by all')
expect(output).toContain('└ other shared chunks (total)')
// output type
expect(output).toContain('○ (Static) prerendered as static content')
})
it('should log errors not caught by the worker without terminating the process', async () => {
expect(output).toContain('Error: Boom')
expect(output).not.toContain('Next.js build worker exited with code: 78')
const $ = await next.render$('/uncaught-error')
expect($('#sentinel').text()).toEqual('at buildtime')
})
it('should fail the build if you use a dynamic API outside of a render context - cookies', async () => {
await next.stop()
await next.patchFile(
'app/out-of-band-dynamic-api/page.tsx',
outdent`
import { cookies } from 'next/headers'
export default async function Page() {
setTimeout(() => {
cookies();
}, 0)
return <div>Hello World</div>
}
`
)
const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx')
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
})
it('should fail the build if you use a dynamic API outside of a render context - headers', async () => {
await next.stop()
await next.patchFile(
'app/out-of-band-dynamic-api/page.tsx',
outdent`
import { headers } from 'next/headers'
export default async function Page({ searchParams }) {
setTimeout(() => {
headers()
}, 0)
return <div>Hello World</div>
}
`
)
const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx')
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
})
it('should fail the build if you use a dynamic API outside of a render context - searchParams', async () => {
await next.stop()
await next.patchFile(
'app/out-of-band-dynamic-api/page.tsx',
outdent`
export default async function Page({ searchParams }) {
setTimeout(() => {
searchParams.foo
}, 0)
return <div>Hello World</div>
}
`
)
const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx')
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
})
it('should fail the build if you use a dynamic API outside of a render context - redirect', async () => {
await next.stop()
await next.patchFile(
'app/out-of-band-dynamic-api/page.tsx',
outdent`
import { redirect } from 'next/navigation'
export default async function Page({ searchParams }) {
setTimeout(() => {
redirect('/whatever')
}, 0)
return <div>Hello World</div>
}
`
)
const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx')
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
})
it('should fail the build if you use a dynamic API outside of a render context - notFound', async () => {
await next.stop()
await next.patchFile(
'app/out-of-band-dynamic-api/page.tsx',
outdent`
import { notFound } from 'next/navigation'
export default async function Page({ searchParams }) {
setTimeout(() => {
notFound()
}, 0)
return <div>Hello World</div>
}
`
)
const { cliOutput } = await next.build()
await next.deleteFile('app/out-of-band-dynamic-api/page.tsx')
expect(cliOutput).toContain('Next.js build worker exited with code: 78')
})
})
|