[test] Use `@force-gate`

parent a92d806a
...@@ -6,105 +6,103 @@ import { basePath, url } from './base-path' ...@@ -6,105 +6,103 @@ import { basePath, url } from './base-path'
// Variants are supported with Turbopack only, and enabling them rejects a // Variants are supported with Turbopack only, and enabling them rejects a
// webpack build, which `variants-webpack.test.ts` covers. // webpack build, which `variants-webpack.test.ts` covers.
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)( // @force-gate turbopack
'variants with a cache lifetime per combination', describe('variants with a cache lifetime per combination', () => {
() => { const { next, skipped } = nextTestSetup({
const { next, skipped } = nextTestSetup({ files: __dirname + '/fixtures/cache-lifetime',
files: __dirname + '/fixtures/cache-lifetime', // TODO(variants): enable this for a deployment. A platform serves a
// TODO(variants): enable this for a deployment. A platform serves a // combination from the routing rules the adapter emits, and those do not
// combination from the routing rules the adapter emits, and those do not // exist yet, so every assertion here is about a self-hosted server.
// exist yet, so every assertion here is about a self-hosted server. skipDeployment: true,
skipDeployment: true, // Handed to the build rather than read from `process.env` there, so that
// Handed to the build rather than read from `process.env` there, so that // a deployed build receives it too: only what goes through here is
// a deployed build receives it too: only what goes through here is // forwarded to the remote build.
// forwarded to the remote build. env: basePath ? { BASE_PATH: basePath } : undefined,
env: basePath ? { BASE_PATH: basePath } : undefined, })
if (skipped) {
return
}
it('should resolve a variant while revalidating a stale prerender', async () => {
// A tag rather than the route's own lifetime, so the entry goes stale at
// once instead of after an hour.
const before = await next.render$(url('/lifetime/r'), undefined, {
headers: { cookie: 'theme=dark' },
}) })
if (skipped) { expect(before('#theme').text()).toBe('dark')
return
} const renderedAt = before('#rendered-at').text()
expect(renderedAt).not.toBe('')
it('should resolve a variant while revalidating a stale prerender', async () => { const revalidateRes = await next.fetch(url('/revalidate?tag=lifetime-r'))
// A tag rather than the route's own lifetime, so the entry goes stale at expect(revalidateRes.status).toBe(200)
// once instead of after an hour.
const before = await next.render$(url('/lifetime/r'), undefined, { // The stamp is what shows the entry was replaced. The variant reads
// `dark` before and after, so a response carrying the old stamp is the
// stale entry served while the revalidation runs behind it, and asserting
// on the variant alone would pass without that render happening.
await retry(async () => {
const after = await next.render$(url('/lifetime/r'), undefined, {
headers: { cookie: 'theme=dark' }, headers: { cookie: 'theme=dark' },
}) })
expect(before('#theme').text()).toBe('dark') expect(after('#rendered-at').text()).not.toBe(renderedAt)
expect(after('#theme').text()).toBe('dark')
})
})
const renderedAt = before('#rendered-at').text() it('should resolve the variant the cache lifetime is selected from', async () => {
expect(renderedAt).not.toBe('') const $ = await next.render$(url('/lifetime/a'), undefined, {
headers: { cookie: 'theme=dark' },
})
const revalidateRes = await next.fetch(url('/revalidate?tag=lifetime-r')) expect($('#theme').text()).toBe('dark')
expect(revalidateRes.status).toBe(200) })
// The stamp is what shows the entry was replaced. The variant reads if (isNextStart) {
// `dark` before and after, so a response carrying the old stamp is the it('should give each combination its own cache lifetime', async () => {
// stale entry served while the revalidation runs behind it, and asserting const darkResponse = await next.fetch(url('/lifetime/a'), {
// on the variant alone would pass without that render happening. headers: { cookie: 'theme=dark' },
await retry(async () => { })
const after = await next.render$(url('/lifetime/r'), undefined, {
headers: { cookie: 'theme=dark' },
})
expect(after('#rendered-at').text()).not.toBe(renderedAt) expect(darkResponse.headers.get('cache-control')).toContain(
's-maxage=3600'
)
expect(after('#theme').text()).toBe('dark') const darkBrowser = await next.browser(url('/lifetime/a'), {
async beforePageLoad(page: Playwright.Page) {
await page
.context()
.addCookies([{ name: 'theme', value: 'dark', url: next.url }])
},
}) })
})
it('should resolve the variant the cache lifetime is selected from', async () => { await retry(async () => {
const $ = await next.render$(url('/lifetime/a'), undefined, { expect(await darkBrowser.elementByCss('#theme').text()).toBe('dark')
headers: { cookie: 'theme=dark' },
}) })
expect($('#theme').text()).toBe('dark') const lightResponse = await next.fetch(url('/lifetime/a'), {
}) headers: { cookie: 'theme=light' },
})
if (isNextStart) { expect(lightResponse.headers.get('cache-control')).toContain(
it('should give each combination its own cache lifetime', async () => { 's-maxage=60'
const darkResponse = await next.fetch(url('/lifetime/a'), { )
headers: { cookie: 'theme=dark' },
}) const lightBrowser = await next.browser(url('/lifetime/a'), {
async beforePageLoad(page: Playwright.Page) {
expect(darkResponse.headers.get('cache-control')).toContain( await page
's-maxage=3600' .context()
) .addCookies([{ name: 'theme', value: 'light', url: next.url }])
},
const darkBrowser = await next.browser(url('/lifetime/a'), {
async beforePageLoad(page: Playwright.Page) {
await page
.context()
.addCookies([{ name: 'theme', value: 'dark', url: next.url }])
},
})
await retry(async () => {
expect(await darkBrowser.elementByCss('#theme').text()).toBe('dark')
})
const lightResponse = await next.fetch(url('/lifetime/a'), {
headers: { cookie: 'theme=light' },
})
expect(lightResponse.headers.get('cache-control')).toContain(
's-maxage=60'
)
const lightBrowser = await next.browser(url('/lifetime/a'), {
async beforePageLoad(page: Playwright.Page) {
await page
.context()
.addCookies([{ name: 'theme', value: 'light', url: next.url }])
},
})
await retry(async () => {
expect(await lightBrowser.elementByCss('#theme').text()).toBe('light')
})
}) })
}
await retry(async () => {
expect(await lightBrowser.elementByCss('#theme').text()).toBe('light')
})
})
} }
) })
...@@ -2,29 +2,28 @@ import { isNextDev, nextTestSetup } from 'e2e-utils' ...@@ -2,29 +2,28 @@ import { isNextDev, nextTestSetup } from 'e2e-utils'
// Variants are supported with Turbopack only, and enabling them rejects a // Variants are supported with Turbopack only, and enabling them rejects a
// webpack build, which `variants-webpack.test.ts` covers. // webpack build, which `variants-webpack.test.ts` covers.
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)( // @force-gate turbopack
'variants with a variant read above every boundary', describe('variants with a variant read above every boundary', () => {
() => { const { next, skipped } = nextTestSetup({
const { next, skipped } = nextTestSetup({ files: __dirname + '/fixtures/empty-shell',
files: __dirname + '/fixtures/empty-shell', // Every route of this fixture exists to fail the build, so the harness
// Every route of this fixture exists to fail the build, so the harness // must not build or start it. Both modes below drive Next.js by hand, and
// must not build or start it. Both modes below drive Next.js by hand, and // a deployment cannot run a build that fails.
// a deployment cannot run a build that fails. skipStart: true,
skipStart: true, skipDeployment: true,
skipDeployment: true, })
})
if (skipped) {
if (skipped) { return
return }
}
if (isNextDev) { if (isNextDev) {
it('should report the read above a Suspense boundary in the dev overlay', async () => { it('should report the read above a Suspense boundary in the dev overlay', async () => {
await next.start() await next.start()
const browser = await next.browser('/above-boundary') const browser = await next.browser('/above-boundary')
await expect(browser).toDisplayCollapsedRedbox(` await expect(browser).toDisplayCollapsedRedbox(`
{ {
"description": "Next.js encountered runtime data during prerendering.", "description": "Next.js encountered runtime data during prerendering.",
"environmentLabel": "Server", "environmentLabel": "Server",
...@@ -37,28 +36,27 @@ import { isNextDev, nextTestSetup } from 'e2e-utils' ...@@ -37,28 +36,27 @@ import { isNextDev, nextTestSetup } from 'e2e-utils'
], ],
} }
`) `)
}) })
return return
} }
// Each route is built on its own, because a build of both stops at // Each route is built on its own, because a build of both stops at
// whichever fails first. // whichever fails first.
it.each([['above-boundary'], ['runtime-above-boundary']])( it.each([['above-boundary'], ['runtime-above-boundary']])(
'should fail the build for %s', 'should fail the build for %s',
async (route) => { async (route) => {
const { exitCode, cliOutput } = await next.build({ const { exitCode, cliOutput } = await next.build({
args: ['--debug-build-paths', `app/${route}/page.tsx`], args: ['--debug-build-paths', `app/${route}/page.tsx`],
}) })
expect(exitCode).toBe(1) expect(exitCode).toBe(1)
expect(cliOutput).toContain( expect(cliOutput).toContain(
`Error occurred prerendering page "/${route}"` `Error occurred prerendering page "/${route}"`
) )
expect(cliOutput).toContain( expect(cliOutput).toContain(
'Next.js encountered uncached or runtime data during prerendering' 'Next.js encountered uncached or runtime data during prerendering'
) )
} }
) )
} })
)
...@@ -3,61 +3,59 @@ import { retry } from 'next-test-utils' ...@@ -3,61 +3,59 @@ import { retry } from 'next-test-utils'
// Variants are supported with Turbopack only, and enabling them rejects a // Variants are supported with Turbopack only, and enabling them rejects a
// webpack build, which `variants-webpack.test.ts` covers. // webpack build, which `variants-webpack.test.ts` covers.
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)( // @force-gate turbopack
'variants on an upgraded fallback shell', describe('variants on an upgraded fallback shell', () => {
() => { const { next, skipped } = nextTestSetup({
const { next, skipped } = nextTestSetup({ files: __dirname + '/fixtures/fallback-upgrade',
files: __dirname + '/fixtures/fallback-upgrade', // TODO(variants): enable this for a deployment. A platform serves a
// TODO(variants): enable this for a deployment. A platform serves a // combination from the routing rules the adapter emits, and those do not
// combination from the routing rules the adapter emits, and those do not // exist yet, so every assertion here is about a self-hosted server.
// exist yet, so every assertion here is about a self-hosted server. skipDeployment: true,
skipDeployment: true, })
})
if (skipped) { if (skipped) {
return return
} }
if (isNextDev) { if (isNextDev) {
// Dev prerenders nothing, so it has no fallback shell to upgrade. // Dev prerenders nothing, so it has no fallback shell to upgrade.
it.skip('upgrades the shell of each combination separately', () => {}) it.skip('upgrades the shell of each combination separately', () => {})
return return
} }
it('should upgrade the shell of each combination separately', async () => {
// `generateStaticParams` names `b` alone, so `/prefix/c` is served a
// fallback shell where the param is a hole. That request triggers an
// upgrade in the background, and a later one is served a shell built for
// `c`. Partial Prefetching is what enables the upgrade, and nothing else
// in this suite turns it on.
//
// The upgraded shell is rendered for one combination and bakes its theme,
// so each combination needs an upgraded shell of its own. That is what
// the prefix on the cache key provides. Without it the second combination
// reads the first one's shell and is answered with its theme.
for (const theme of ['dark', 'light']) {
const fallback = await next.render$('/prefix/c', undefined, {
headers: { cookie: `theme=${theme}` },
})
// `first()`, because a fallback shell emits the placeholder and the
// resume then emits the value, so both elements carry this id.
expect({
theme: fallback('#theme').first().text(),
one: fallback('#one').first().text(),
}).toEqual({ theme, one: 'pending' })
it('should upgrade the shell of each combination separately', async () => { await retry(async () => {
// `generateStaticParams` names `b` alone, so `/prefix/c` is served a const upgraded = await next.render$('/prefix/c', undefined, {
// fallback shell where the param is a hole. That request triggers an
// upgrade in the background, and a later one is served a shell built for
// `c`. Partial Prefetching is what enables the upgrade, and nothing else
// in this suite turns it on.
//
// The upgraded shell is rendered for one combination and bakes its theme,
// so each combination needs an upgraded shell of its own. That is what
// the prefix on the cache key provides. Without it the second combination
// reads the first one's shell and is answered with its theme.
for (const theme of ['dark', 'light']) {
const fallback = await next.render$('/prefix/c', undefined, {
headers: { cookie: `theme=${theme}` }, headers: { cookie: `theme=${theme}` },
}) })
// `first()`, because a fallback shell emits the placeholder and the
// resume then emits the value, so both elements carry this id.
expect({ expect({
theme: fallback('#theme').first().text(), theme: upgraded('#theme').first().text(),
one: fallback('#one').first().text(), one: upgraded('#one').first().text(),
}).toEqual({ theme, one: 'pending' }) }).toEqual({ theme, one: 'c' })
})
await retry(async () => { }
const upgraded = await next.render$('/prefix/c', undefined, { })
headers: { cookie: `theme=${theme}` }, })
})
expect({
theme: upgraded('#theme').first().text(),
one: upgraded('#one').first().text(),
}).toEqual({ theme, one: 'c' })
})
}
})
}
)
...@@ -6,44 +6,42 @@ const expectedError = ...@@ -6,44 +6,42 @@ const expectedError =
// Variants are supported with Turbopack only, so a webpack build rejects the // Variants are supported with Turbopack only, so a webpack build rejects the
// config of this fixture before it reads the middleware file. // config of this fixture before it reads the middleware file.
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)( // @force-gate turbopack
'variants in a middleware file', describe('variants in a middleware file', () => {
() => { const { next, skipped } = nextTestSetup({
const { next, skipped } = nextTestSetup({ files: __dirname + '/fixtures/middleware-file',
files: __dirname + '/fixtures/middleware-file', // The fixture exists to fail, so the harness must not build or start it.
// The fixture exists to fail, so the harness must not build or start it. // Both modes below drive Next.js by hand instead.
// Both modes below drive Next.js by hand instead. skipStart: true,
skipStart: true, skipDeployment: true,
skipDeployment: true, })
})
if (skipped) {
if (skipped) { return
return }
}
if (isNextDev) { if (isNextDev) {
beforeAll(async () => { beforeAll(async () => {
await next.start() await next.start()
}) })
it('should report the middleware file and keep the dev server up', async () => { it('should report the middleware file and keep the dev server up', async () => {
// Renaming the file has to recover without a restart, so the dev server // Renaming the file has to recover without a restart, so the dev server
// reports the error and carries on rather than failing the route. // reports the error and carries on rather than failing the route.
const response = await next.fetch('/') const response = await next.fetch('/')
expect(response.status).toBe(200) expect(response.status).toBe(200)
await retry(async () => { await retry(async () => {
expect(next.cliOutput).toContain(expectedError) expect(next.cliOutput).toContain(expectedError)
})
}) })
} else { })
it('should fail the build', async () => { } else {
const { exitCode, cliOutput } = await next.build() it('should fail the build', async () => {
const { exitCode, cliOutput } = await next.build()
expect(exitCode).toBe(1) expect(exitCode).toBe(1)
expect(cliOutput).toContain(expectedError) expect(cliOutput).toContain(expectedError)
}) })
}
} }
) })
...@@ -5,69 +5,67 @@ const DECLARED = '/declared' ...@@ -5,69 +5,67 @@ const DECLARED = '/declared'
// Variants are supported with Turbopack only, and enabling them rejects a // Variants are supported with Turbopack only, and enabling them rejects a
// webpack build, which `variants-webpack.test.ts` covers. // webpack build, which `variants-webpack.test.ts` covers.
;(process.env.IS_TURBOPACK_TEST ? describe : describe.skip)( // @force-gate turbopack
'variants with a param the build did not name', describe('variants with a param the build did not name', () => {
() => { const { next, skipped } = nextTestSetup({
const { next, skipped } = nextTestSetup({ files: __dirname + '/fixtures/on-demand-param',
files: __dirname + '/fixtures/on-demand-param', // TODO(variants): enable this for a deployment. A platform serves a
// TODO(variants): enable this for a deployment. A platform serves a // combination from the routing rules the adapter emits, and those do not
// combination from the routing rules the adapter emits, and those do not // exist yet, so every assertion here is about a self-hosted server.
// exist yet, so every assertion here is about a self-hosted server. skipDeployment: true,
skipDeployment: true, })
})
if (skipped) { if (skipped) {
return return
} }
if (isNextDev) { if (isNextDev) {
// Dev prerenders nothing, so it has no entry to keep and no shell to // Dev prerenders nothing, so it has no entry to keep and no shell to
// resume. The second test therefore cannot hold here at all. The first // resume. The second test therefore cannot hold here at all. The first
// would pass, but only because a dev render and an on-demand prerender // would pass, but only because a dev render and an on-demand prerender
// report the same sentinel, so it would prove nothing. // report the same sentinel, so it would prove nothing.
it.skip('prerenders a param the build did not name', () => {}) it.skip('prerenders a param the build did not name', () => {})
return return
} }
it('should prerender a param the build did not name for the request that asks', async () => { it('should prerender a param the build did not name for the request that asks', async () => {
// `/control/[slug]` has the same shape and declares no combinations. If // `/control/[slug]` has the same shape and declares no combinations. If
// both routes behave alike, the combinations are not the cause. // both routes behave alike, the combinations are not the cause.
// //
// The sentinel reports which render filled the entry, not which render // The sentinel reports which render filled the entry, not which render
// reads it. A request that resumes the empty shell replays what the build // reads it. A request that resumes the empty shell replays what the build
// wrote, and reports `buildtime`. The markup cannot report this, because // wrote, and reports `buildtime`. The markup cannot report this, because
// the page looks the same either way. The cache state cannot either, // the page looks the same either way. The cache state cannot either,
// because resuming a shell looks like serving a prerender. // because resuming a shell looks like serving a prerender.
// //
// Two params are asked for, because there must be one prerender per // Two params are asked for, because there must be one prerender per
// param. A single entry that ignored the param would answer for both, and // param. A single entry that ignored the param would answer for both, and
// would serve one param's page under the other's URL. So each response's // would serve one param's page under the other's URL. So each response's
// own param is asserted too. // own param is asserted too.
for (const route of [CONTROL, DECLARED]) { for (const route of [CONTROL, DECLARED]) {
for (const slug of ['unnamed-one', 'unnamed-two']) { for (const slug of ['unnamed-one', 'unnamed-two']) {
const $ = await next.render$(`${route}/${slug}`, undefined, { const $ = await next.render$(`${route}/${slug}`, undefined, {
headers: { cookie: 'theme=dark' }, headers: { cookie: 'theme=dark' },
}) })
expect({ expect({
route, route,
slug: $('#slug').text(), slug: $('#slug').text(),
cachedSentinel: $('#cached-sentinel').text(), cachedSentinel: $('#cached-sentinel').text(),
}).toEqual({ route, slug, cachedSentinel: 'runtime' }) }).toEqual({ route, slug, cachedSentinel: 'runtime' })
}
} }
}) }
})
it('should serve a param the build named from the prerender of its combination', async () => {
const $ = await next.render$(`${DECLARED}/built`, undefined, {
headers: { cookie: 'theme=dark' },
})
expect({ it('should serve a param the build named from the prerender of its combination', async () => {
slug: $('#slug').text(), const $ = await next.render$(`${DECLARED}/built`, undefined, {
theme: $('#theme').text(), headers: { cookie: 'theme=dark' },
cachedSentinel: $('#cached-sentinel').text(),
}).toEqual({ slug: 'built', theme: 'dark', cachedSentinel: 'buildtime' })
}) })
}
) expect({
slug: $('#slug').text(),
theme: $('#theme').text(),
cachedSentinel: $('#cached-sentinel').text(),
}).toEqual({ slug: 'built', theme: 'dark', cachedSentinel: 'buildtime' })
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment