Commit f30b5ccc authored by Jimmy Lai's avatar Jimmy Lai

test: verify HTML cache hit with render timestamp

Add render-timestamp outside of 'use cache' function to verify that
User B actually gets cached HTML (not a re-render). If the page
re-rendered, render-timestamp would differ between User A and User B.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: 's avatarClaude Opus 4.5 <noreply@anthropic.com>
parent b423e776
...@@ -9,9 +9,13 @@ async function getCachedTimestamp() { ...@@ -9,9 +9,13 @@ async function getCachedTimestamp() {
export default async function Page() { export default async function Page() {
const timestamp = await getCachedTimestamp() const timestamp = await getCachedTimestamp()
// This timestamp is NOT cached - it changes on every render.
// Used to verify HTML cache hits vs re-renders.
const renderTimestamp = Date.now().toString()
return ( return (
<div> <div>
<p id="timestamp">{timestamp}</p> <p id="timestamp">{timestamp}</p>
<p id="render-timestamp">{renderTimestamp}</p>
<form> <form>
<button <button
id="update-tag" id="update-tag"
......
...@@ -731,25 +731,35 @@ describe('use-cache', () => { ...@@ -731,25 +731,35 @@ describe('use-cache', () => {
// Wait for action response // Wait for action response
let userAValue: string let userAValue: string
let userARenderTimestamp: string
await retry(async () => { await retry(async () => {
const afterAction = await browser.elementByCss('#timestamp').text() const afterAction = await browser.elementByCss('#timestamp').text()
// KEY ASSERTION: User A sees fresh content immediately (read-your-own-writes) // KEY ASSERTION: User A sees fresh content immediately (read-your-own-writes)
expect(afterAction).not.toBe(initial) expect(afterAction).not.toBe(initial)
userAValue = afterAction userAValue = afterAction
userARenderTimestamp = await browser
.elementByCss('#render-timestamp')
.text()
}) })
// 3. Wait for async HTML cache regeneration // 3. Fresh cold visitor (User B) should get same cached HTML
await new Promise((r) => setTimeout(r, 2000)) // The render-timestamp is NOT cached (changes on each render), so if User B
// sees the same render-timestamp as User A, it proves HTML cache hit (not re-render).
// 4. Fresh cold visitor (User B) should get same cached HTML
const res = await next.fetch('/eager-revalidation') const res = await next.fetch('/eager-revalidation')
const html = await res.text() const html = await res.text()
const userBValue = html.match(/id="timestamp">(\d+)</)?.[1] const userBValue = html.match(/id="timestamp">(\d+)</)?.[1]
const userBRenderTimestamp = html.match(
/id="render-timestamp">(\d+)</
)?.[1]
// KEY ASSERTION: User B gets the same fresh value as User A (HTML cache was pre-warmed) // KEY ASSERTION: User B gets the same fresh value as User A (HTML cache was pre-warmed)
expect(userBValue).toBe(userAValue!) expect(userBValue).toBe(userAValue!)
// 5. Verify it's actually cached (second fetch returns same value) // KEY ASSERTION: Same render timestamp proves HTML cache hit, not re-render
// If the page re-rendered, render-timestamp would be different
expect(userBRenderTimestamp).toBe(userARenderTimestamp!)
// 4. Verify it's actually cached (second fetch returns same value)
const res2 = await next.fetch('/eager-revalidation') const res2 = await next.fetch('/eager-revalidation')
const html2 = await res2.text() const html2 = await res2.text()
const secondFetch = html2.match(/id="timestamp">(\d+)</)?.[1] const secondFetch = html2.match(/id="timestamp">(\d+)</)?.[1]
......
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