mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
- rename `unstable_after` -> `after` - remove `experimental.after` flag (and warn if it's present) i separated the big find-and-replace into a separate commit so that it's easier to see what else changed apart from that. does not touch docs, that's in #73038
88 lines
2.3 KiB
TypeScript
88 lines
2.3 KiB
TypeScript
/* eslint-env jest */
|
|
import { isNextDev, nextTestSetup } from 'e2e-utils'
|
|
import * as Log from './utils/log'
|
|
import { setTimeout } from 'timers/promises'
|
|
|
|
// This test relies on next.build() so it can't work in dev mode.
|
|
const _describe = isNextDev ? describe.skip : describe
|
|
|
|
_describe('after() in static pages', () => {
|
|
const { next, skipped } = nextTestSetup({
|
|
files: __dirname,
|
|
skipDeployment: true, // reading CLI logs to observe after
|
|
skipStart: true,
|
|
})
|
|
|
|
if (skipped) return
|
|
|
|
let currentCliOutputIndex = 0
|
|
beforeEach(() => {
|
|
currentCliOutputIndex = next.cliOutput.length
|
|
})
|
|
|
|
const getLogs = () => {
|
|
if (next.cliOutput.length < currentCliOutputIndex) {
|
|
// cliOutput shrank since we started the test, so something (like a `sandbox`) reset the logs
|
|
currentCliOutputIndex = 0
|
|
}
|
|
return next.cliOutput.slice(currentCliOutputIndex)
|
|
}
|
|
|
|
const resetLogs = () => {
|
|
currentCliOutputIndex = next.cliOutput.length
|
|
}
|
|
|
|
it('runs after during build', async () => {
|
|
const buildResult = await next.build()
|
|
expect(buildResult?.exitCode).toBe(0)
|
|
|
|
{
|
|
// after should run at build time
|
|
const logsFromAfter = Log.readCliLogs(getLogs())
|
|
expect(logsFromAfter).toContainEqual({
|
|
source: '[page] /static/dynamic-error',
|
|
})
|
|
expect(logsFromAfter).toContainEqual({
|
|
source: '[page] /static/dynamic-force-static',
|
|
})
|
|
expect(logsFromAfter).toContainEqual({
|
|
source: '[route] /static/route',
|
|
})
|
|
}
|
|
|
|
resetLogs()
|
|
await next.start()
|
|
|
|
{
|
|
const res = await next.fetch('/static/dynamic-error')
|
|
expect(res.status).toBe(200)
|
|
}
|
|
|
|
{
|
|
const res = await next.fetch('/static/dynamic-force-static')
|
|
expect(res.status).toBe(200)
|
|
}
|
|
|
|
{
|
|
const res = await next.fetch('/static/route')
|
|
expect(res.status).toBe(200)
|
|
}
|
|
|
|
await setTimeout(1000) // no other good way to make sure any possible afters ran
|
|
|
|
{
|
|
// after should not run at runtime
|
|
const logsFromAfter = Log.readCliLogs(getLogs())
|
|
expect(logsFromAfter).not.toContainEqual({
|
|
source: '[page] /static/dynamic-error',
|
|
})
|
|
expect(logsFromAfter).not.toContainEqual({
|
|
source: '[page] /static/dynamic-force-static',
|
|
})
|
|
expect(logsFromAfter).not.toContainEqual({
|
|
source: '[page] /static/route',
|
|
})
|
|
}
|
|
})
|
|
})
|