mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
Extracted from https://github.com/vercel/next.js/pull/95468. We did not have error handling around async module initialization. As a result, in `output: 'export'` mode, an error during async initialization were reported as unhandled rejections. Now it properly fails the build.
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { join } from 'path'
|
|
import { nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('output-export-async-route-module', () => {
|
|
describe('invalid route', () => {
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'fixtures', 'invalid'),
|
|
skipStart: true,
|
|
})
|
|
|
|
// The route module uses top-level await, so its `output: 'export'`
|
|
// validation runs after the module settles instead of throwing during
|
|
// require(). The resulting error must still fail the build.
|
|
it('fails the build when an async route module is not statically exportable', async () => {
|
|
const { exitCode, cliOutput } = await next.build()
|
|
expect(cliOutput).toContain(
|
|
'not configured on route "/api/data" with "output: export"'
|
|
)
|
|
expect(exitCode).toBe(1)
|
|
})
|
|
})
|
|
|
|
describe('valid route', () => {
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'fixtures', 'valid'),
|
|
skipStart: true,
|
|
})
|
|
|
|
it('exports an async route module that is statically exportable', async () => {
|
|
const { exitCode } = await next.build()
|
|
expect(exitCode).toBe(0)
|
|
expect(await next.readFile('out/api/data')).toBe('{"ok":true}')
|
|
})
|
|
})
|
|
})
|