mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
e0966df114
## Summary - migrate Cache Components, PPR, prefetching, prerendering, revalidation, and SSG deployment exclusions to `@force-gate` - remove the corresponding `skipDeployment` options and `skipped` control flow while preserving each suite's rationale This keeps caching-related exclusions together so their deployed semantics can be reviewed by the same owners. ## Verification - verified on the combined top-of-stack tree with `pnpm typescript` - compared ordinary-mode collection before and after: all 4,670 existing test names matched - collected all 510 affected files in deploy mode: 4,578 skipped tests, zero failures <!-- NEXT_JS_LLM -->
173 lines
6.5 KiB
TypeScript
173 lines
6.5 KiB
TypeScript
import { isNextDev, nextTestSetup } from 'e2e-utils'
|
|
|
|
describe('Cache Components Errors', () => {
|
|
const { next } = nextTestSetup({
|
|
files: __dirname + '/fixtures/dev-cache-bypass',
|
|
})
|
|
|
|
describe('Warning for Bypassing Caches in Dev', () => {
|
|
async function enableDraftMode() {
|
|
const draftRes = await next.fetch('/api/draft/enable', {
|
|
redirect: 'manual',
|
|
})
|
|
const setCookie = draftRes.headers.get('set-cookie')
|
|
const cookie = setCookie?.split(';', 1)[0]
|
|
|
|
expect(cookie).toBeTruthy()
|
|
return cookie!
|
|
}
|
|
|
|
if (isNextDev) {
|
|
it('warns if you render with cache-control: no-cache in dev on initial page load', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/', {
|
|
headers: { 'cache-control': 'no-cache' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from)))
|
|
.toMatchInlineSnapshot(`
|
|
"Route / is rendering with server caches disabled. For this navigation, Component Metadata in React DevTools will not accurately reflect what is statically prerenderable and runtime prefetchable. See more info here: https://nextjs.org/docs/messages/cache-bypass-in-dev
|
|
"
|
|
`)
|
|
})
|
|
|
|
it('warns if you render with cache-control: no-cache in dev on client navigation', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/other', {
|
|
headers: { 'cache-control': 'no-cache', RSC: '1' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from)))
|
|
.toMatchInlineSnapshot(`
|
|
"Route /other is rendering with server caches disabled. For this navigation, Component Metadata in React DevTools will not accurately reflect what is statically prerenderable and runtime prefetchable. See more info here: https://nextjs.org/docs/messages/cache-bypass-in-dev
|
|
"
|
|
`)
|
|
})
|
|
|
|
it('does not warn if you render without cache-control: no-cache in dev on initial page load', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/')
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
|
|
it('does not warn if you render without cache-control: no-cache in dev on client navigation', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/', {
|
|
headers: { RSC: '1' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
|
|
it('warns if draftMode is enabled in dev', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
const cookie = await enableDraftMode()
|
|
|
|
await next.fetch('/draft', {
|
|
headers: { Cookie: cookie },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from)))
|
|
.toMatchInlineSnapshot(`
|
|
"Route /draft is rendering with server caches disabled. For this navigation, Component Metadata in React DevTools will not accurately reflect what is statically prerenderable and runtime prefetchable. See more info here: https://nextjs.org/docs/messages/cache-bypass-in-dev
|
|
"
|
|
`)
|
|
})
|
|
} else {
|
|
it('does not warn if you render with cache-control: no-cache in dev on initial page load', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/', {
|
|
headers: { 'cache-control': 'no-cache' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
|
|
it('does not warn if you render with cache-control: no-cache in dev on client navigation', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/', {
|
|
headers: { 'cache-control': 'no-cache' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
|
|
it('does not warn if you render without cache-control: no-cache in dev on initial page load in start', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/')
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
|
|
it('does not warn if you render without cache-control: no-cache in dev on client navigation in start', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
|
|
await next.fetch('/', {
|
|
headers: { RSC: '1' },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
|
|
it('does not warn if draftMode is enabled in start', async () => {
|
|
// Wait for pages to be loaded to ensure the logging for the test page is the only thing that can be logged.
|
|
await next.fetch('/404')
|
|
const from = next.cliOutput.length
|
|
const cookie = await enableDraftMode()
|
|
|
|
await next.fetch('/draft', {
|
|
headers: { Cookie: cookie },
|
|
})
|
|
|
|
expect(stripGetLines(next.cliOutput.slice(from))).toMatchInlineSnapshot(
|
|
`""`
|
|
)
|
|
})
|
|
}
|
|
})
|
|
})
|
|
|
|
function stripGetLines(input: string): string {
|
|
return input
|
|
.replace(/^\s*GET.*(?:\r?\n|$)/gm, '')
|
|
.replace(/^\s*[○✓].*(?:\r?\n|$)/gm, '')
|
|
}
|