Unverified Commit ae9f00bb authored by vercel-fleet-prod[bot]'s avatar vercel-fleet-prod[bot] Committed by GitHub

Restore deploy expected-failure for expire-time revalidation

Co-authored-by: 's avatarWill Binns-Smith <755844+wbinnssmith@users.noreply.github.com>
parent 4790b5c4
...@@ -3,43 +3,62 @@ import { nextTestSetup } from 'e2e-utils' ...@@ -3,43 +3,62 @@ import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry } from 'next-test-utils'
describe('expire-time', () => { describe('expire-time', () => {
const { next } = nextTestSetup({ const { next, isNextDeploy } = nextTestSetup({
files: __dirname, files: __dirname,
}) })
it('should do a blocking revalidation when the cache entry has expired', async () => { // On Vercel, ISR cache decisions happen at the Proxy layer. The Vercel
const $first = await next.render$('/') // builder reads the route's `expire` value (Next.js's `initialExpireSeconds`
const v1 = $first('#value').text() // in the prerender manifest, which the build derives from `expireTime` when
expect(v1).toBeDateString() // no explicit `cacheLife` expire is set) and passes it to the Proxy as
// `staleExpiration`. The Proxy is also expected, once implemented, to read
// updated values from Next.js's `stale-while-revalidate` response header on
// subsequent revalidations. Today the Proxy ignores the expire value entirely
// and treats it as one year. Past `expireTime` it serves stale with a
// background revalidation instead of a blocking prerender. When Proxy is
// updated to honor the expire value, this test will start passing in deploy
// mode and `it.failing` will itself fail. That's the signal to flip it back
// to `it`.
const itFailsWhenDeployed = isNextDeploy ? it.failing : it
// The first request might trigger a background revalidation if the /* eslint-disable jest/no-standalone-expect */
// prerender document is already older than the configured revalidate itFailsWhenDeployed(
// time. So we refetch until we get a different value than the first one. 'should do a blocking revalidation when the cache entry has expired',
let v2: string async () => {
await retry( const $first = await next.render$('/')
async () => { const v1 = $first('#value').text()
const $second = await next.render$('/') expect(v1).toBeDateString()
v2 = $second('#value').text()
expect(v2).toBeDateString()
expect(v2).not.toBe(v1)
},
4_000,
200
)
// Wait past the `expireTime` (10 s). The next request must trigger a // The first request might trigger a background revalidation if the
// blocking prerender, not stale-while-revalidate — so the response // prerender document is already older than the configured revalidate
// returned right here carries a freshly-computed value. // time. So we refetch until we get a different value than the first one.
await wait(10_000) let v2: string
await retry(
async () => {
const $second = await next.render$('/')
v2 = $second('#value').text()
expect(v2).toBeDateString()
expect(v2).not.toBe(v1)
},
4_000,
200
)
const $third = await next.render$('/') // Wait past the `expireTime` (10 s). The next request must trigger a
const v3 = $third('#value').text() // blocking prerender, not stale-while-revalidate — so the response
expect(v3).toBeDateString() // returned right here carries a freshly-computed value.
await wait(10_000)
// This should be a new value, not the expired previous one, and const $third = await next.render$('/')
// especially not the expired prerendered one. const v3 = $third('#value').text()
expect(v3).not.toBe(v2) expect(v3).toBeDateString()
expect(v3).not.toBe(v1)
console.log({ v1, v2, v3 }) // This should be a new value, not the expired previous one, and
}) // especially not the expired prerendered one.
expect(v3).not.toBe(v2)
expect(v3).not.toBe(v1)
console.log({ v1, v2, v3 })
}
)
/* eslint-enable jest/no-standalone-expect */
}) })
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