Unverified Commit 544d98b9 authored by Sebastian Markbåge's avatar Sebastian Markbåge Committed by GitHub

Test cached form action with revalidate (#71591)

parent b3d7335d
import { revalidateTag, unstable_cacheTag as cacheTag } from 'next/cache'
async function refresh() {
'use server'
revalidateTag('home')
}
export default async function Page() {
'use cache'
cacheTag('home')
return (
<form action={refresh}>
<button id="refresh">Refresh</button>
<p id="t">{Date.now()}</p>
</form>
)
}
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils' import { retry, waitFor } from 'next-test-utils'
const GENERIC_RSC_ERROR = const GENERIC_RSC_ERROR =
'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.' 'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.'
...@@ -241,4 +241,29 @@ describe('use-cache', () => { ...@@ -241,4 +241,29 @@ describe('use-cache', () => {
expect(await browser.elementByCss('p').text()).toBe('result') expect(await browser.elementByCss('p').text()).toBe('result')
}) })
}) })
it('should be able to revalidate a page using', async () => {
const browser = await next.browser(`/form`)
const time1 = await browser.waitForElementByCss('#t').text()
await browser.loadPage(new URL(`/form`, next.url).toString())
const time2 = await browser.waitForElementByCss('#t').text()
expect(time1).toBe(time2)
await browser.elementByCss('#refresh').click()
await waitFor(500)
const time3 = await browser.waitForElementByCss('#t').text()
expect(time3).not.toBe(time2)
// Reloading again should ideally be the same value but because the Action seeds
// the cache with real params as the argument it has a different cache key.
// await browser.loadPage(new URL(`/form?c`, next.url).toString())
// const time4 = await browser.waitForElementByCss('#t').text()
// expect(time4).toBe(time3);
})
}) })
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