Skip to content

Commit 81a3fbf

Browse files
committed
test: move test to dedicated fixture
1 parent 81583b7 commit 81a3fbf

File tree

8 files changed

+87
-39
lines changed

8 files changed

+87
-39
lines changed

tests/e2e/after.test.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { expect } from '@playwright/test'
2+
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
3+
import { test } from '../utils/playwright-helpers.js'
4+
5+
test('next/after callback is executed and finishes', async ({ page, after }) => {
6+
test.skip(!nextVersionSatisfies('>=15.0.0'), 'This test is only for Next.js 15+')
7+
8+
// trigger initial request to check page which might be stale and allow regenerating in background
9+
await page.goto(`${after.url}/after/check`)
10+
11+
await new Promise((resolve) => setTimeout(resolve, 5000))
12+
13+
// after it was possibly regenerated we can start checking actual content of the page
14+
await page.goto(`${after.url}/after/check`)
15+
const pageInfoLocator1 = await page.locator('#page-info')
16+
const pageInfo1 = JSON.parse((await pageInfoLocator1.textContent()) ?? '{}')
17+
18+
expect(typeof pageInfo1?.timestamp, 'Check page should have timestamp').toBe('number')
19+
20+
await page.goto(`${after.url}/after/check`)
21+
const pageInfoLocator2 = await page.locator('#page-info')
22+
const pageInfo2 = JSON.parse((await pageInfoLocator2.textContent()) ?? '{}')
23+
24+
expect(typeof pageInfo2?.timestamp, 'Check page should have timestamp').toBe('number')
25+
26+
expect(pageInfo2.timestamp, 'Check page should be cached').toBe(pageInfo1.timestamp)
27+
28+
await page.goto(`${after.url}/after/trigger`)
29+
30+
// wait for next/after to trigger revalidation of check page
31+
await new Promise((resolve) => setTimeout(resolve, 5000))
32+
33+
await page.goto(`${after.url}/after/check`)
34+
const pageInfoLocator3 = await page.locator('#page-info')
35+
const pageInfo3 = JSON.parse((await pageInfoLocator3.textContent()) ?? '{}')
36+
37+
expect(typeof pageInfo3?.timestamp, 'Check page should have timestamp').toBe('number')
38+
expect(
39+
pageInfo3.timestamp,
40+
'Check page should be invalidated with newer timestamp',
41+
).toBeGreaterThan(pageInfo1.timestamp)
42+
})

tests/e2e/simple-app.test.ts

-39
Original file line numberDiff line numberDiff line change
@@ -272,42 +272,3 @@ test('can require CJS module that is not bundled', async ({ simple }) => {
272272
expect(parsedBody.notBundledCJSModule.isBundled).toEqual(false)
273273
expect(parsedBody.bundledCJSModule.isBundled).toEqual(true)
274274
})
275-
276-
test('next/after callback is executed and finishes', async ({ page, simple }) => {
277-
test.skip(!nextVersionSatisfies('>=15.0.0'), 'This test is only for Next.js 15+')
278-
279-
// trigger initial request to check page which might be stale and allow regenerating in background
280-
await page.goto(`${simple.url}/after/check`)
281-
282-
await new Promise((resolve) => setTimeout(resolve, 5000))
283-
284-
// after it was possibly regenerated we can start checking actual content of the page
285-
await page.goto(`${simple.url}/after/check`)
286-
const pageInfoLocator1 = await page.locator('#page-info')
287-
const pageInfo1 = JSON.parse((await pageInfoLocator1.textContent()) ?? '{}')
288-
289-
expect(typeof pageInfo1?.timestamp, 'Check page should have timestamp').toBe('number')
290-
291-
await page.goto(`${simple.url}/after/check`)
292-
const pageInfoLocator2 = await page.locator('#page-info')
293-
const pageInfo2 = JSON.parse((await pageInfoLocator2.textContent()) ?? '{}')
294-
295-
expect(typeof pageInfo2?.timestamp, 'Check page should have timestamp').toBe('number')
296-
297-
expect(pageInfo2.timestamp, 'Check page should be cached').toBe(pageInfo1.timestamp)
298-
299-
await page.goto(`${simple.url}/after/trigger`)
300-
301-
// wait for next/after to trigger revalidation of check page
302-
await new Promise((resolve) => setTimeout(resolve, 5000))
303-
304-
await page.goto(`${simple.url}/after/check`)
305-
const pageInfoLocator3 = await page.locator('#page-info')
306-
const pageInfo3 = JSON.parse((await pageInfoLocator3.textContent()) ?? '{}')
307-
308-
expect(typeof pageInfo3?.timestamp, 'Check page should have timestamp').toBe('number')
309-
expect(
310-
pageInfo3.timestamp,
311-
'Check page should be invalidated with newer timestamp',
312-
).toBeGreaterThan(pageInfo1.timestamp)
313-
})

tests/fixtures/after/app/layout.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const metadata = {
2+
title: 'Simple Next App',
3+
description: 'Description for Simple Next App',
4+
}
5+
6+
export default function RootLayout({ children }) {
7+
return (
8+
<html lang="en">
9+
<body>{children}</body>
10+
</html>
11+
)
12+
}

tests/fixtures/after/next.config.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/** @type {import('next').NextConfig} */
2+
const nextConfig = {
3+
output: 'standalone',
4+
eslint: {
5+
ignoreDuringBuilds: true,
6+
},
7+
experimental: {
8+
after: true,
9+
},
10+
}
11+
12+
module.exports = nextConfig

tests/fixtures/after/package.json

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "after",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"postinstall": "next build",
7+
"dev": "next dev",
8+
"build": "next build"
9+
},
10+
"dependencies": {
11+
"next": "latest",
12+
"react": "18.2.0",
13+
"react-dom": "18.2.0"
14+
},
15+
"test": {
16+
"dependencies": {
17+
"next": ">=15.0.0"
18+
}
19+
}
20+
}

tests/utils/create-e2e-fixture.ts

+1
Original file line numberDiff line numberDiff line change
@@ -428,4 +428,5 @@ export const fixtureFactories = {
428428
publishDirectory: 'apps/site/.next',
429429
smoke: true,
430430
}),
431+
after: () => createE2EFixture('after'),
431432
}

0 commit comments

Comments
 (0)