diff --git a/tests/e2e/simple-app.test.ts b/tests/e2e/simple-app.test.ts index 15f1f585fe..d71a18111d 100644 --- a/tests/e2e/simple-app.test.ts +++ b/tests/e2e/simple-app.test.ts @@ -272,3 +272,36 @@ test('can require CJS module that is not bundled', async ({ simple }) => { expect(parsedBody.notBundledCJSModule.isBundled).toEqual(false) expect(parsedBody.bundledCJSModule.isBundled).toEqual(true) }) + +test('next/after callback is executed and finishes', async ({ page, simple }) => { + test.skip(!nextVersionSatisfies('>=15.0.0'), 'This test is only for Next.js 15+') + + await page.goto(`${simple.url}/after/check`) + const pageInfoLocator1 = await page.locator('#page-info') + const pageInfo1 = JSON.parse((await pageInfoLocator1.textContent()) ?? '{}') + + expect(typeof pageInfo1?.timestamp, 'Check page should have timestamp').toBe('number') + + await new Promise((resolve) => setTimeout(resolve, 2000)) + + await page.goto(`${simple.url}/after/check`) + const pageInfoLocator2 = await page.locator('#page-info') + const pageInfo2 = JSON.parse((await pageInfoLocator2.textContent()) ?? '{}') + + expect(typeof pageInfo2?.timestamp, 'Check page should have timestamp').toBe('number') + + expect(pageInfo2.timestamp, 'Check page should be cached').toBe(pageInfo1.timestamp) + + + await page.goto(`${simple.url}/after/trigger`) + + // wait for next/after to trigger revalidation of check page + await new Promise((resolve) => setTimeout(resolve, 5000)) + + await page.goto(`${simple.url}/after/check`) + const pageInfoLocator3 = await page.locator('#page-info') + const pageInfo3 = JSON.parse((await pageInfoLocator3.textContent()) ?? '{}') + + expect(typeof pageInfo3?.timestamp, 'Check page should have timestamp').toBe('number') + expect(pageInfo3.timestamp, 'Check page should be invalidated with newer timestamp').toBeGreaterThan(pageInfo1.timestamp) +}) diff --git a/tests/fixtures/simple/app/after/check/page.js b/tests/fixtures/simple/app/after/check/page.js new file mode 100644 index 0000000000..8139df1390 --- /dev/null +++ b/tests/fixtures/simple/app/after/check/page.js @@ -0,0 +1,13 @@ +export const revalidate = 3600 // arbitrarily long, just so that it doesn't happen during a test run + + +export default async function Page() { + const data = { + timestamp: Date.now(), + } + console.log('/timestamp/key/[key] rendered', data) + + return ( +