Skip to content

Commit 4eccea7

Browse files
authored
test: don't install v16 when testing older next versions (#3207)
1 parent 6361e31 commit 4eccea7

File tree

3 files changed

+41
-40
lines changed

3 files changed

+41
-40
lines changed

tests/e2e/after.test.ts

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,44 @@ import { expect } from '@playwright/test'
22
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
33
import { test } from '../utils/playwright-helpers.js'
44

5-
test('next/after callback is executed and finishes', async ({ page, after }) => {
6-
test.skip(
7-
!nextVersionSatisfies('>=15.1.0'),
8-
'This test is only for Next.js >=15.1.0 that has stable after() support',
9-
)
5+
// This test is only for Next.js >=15.1.0 that has stable after() support
6+
if (nextVersionSatisfies('>=15.1.0')) {
7+
test('next/after callback is executed and finishes', async ({ page, after }) => {
8+
// trigger initial request to check page which might be stale and allow regenerating in background
9+
await page.goto(`${after.url}/after/check`)
1010

11-
// trigger initial request to check page which might be stale and allow regenerating in background
12-
await page.goto(`${after.url}/after/check`)
11+
await new Promise((resolve) => setTimeout(resolve, 5000))
1312

14-
await new Promise((resolve) => setTimeout(resolve, 5000))
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()) ?? '{}')
1517

16-
// after it was possibly regenerated we can start checking actual content of the page
17-
await page.goto(`${after.url}/after/check`)
18-
const pageInfoLocator1 = await page.locator('#page-info')
19-
const pageInfo1 = JSON.parse((await pageInfoLocator1.textContent()) ?? '{}')
18+
expect(typeof pageInfo1?.timestamp, 'Check page should have timestamp').toBe('number')
2019

21-
expect(typeof pageInfo1?.timestamp, 'Check page should have timestamp').toBe('number')
20+
await page.goto(`${after.url}/after/check`)
21+
const pageInfoLocator2 = await page.locator('#page-info')
22+
const pageInfo2 = JSON.parse((await pageInfoLocator2.textContent()) ?? '{}')
2223

23-
await page.goto(`${after.url}/after/check`)
24-
const pageInfoLocator2 = await page.locator('#page-info')
25-
const pageInfo2 = JSON.parse((await pageInfoLocator2.textContent()) ?? '{}')
24+
expect(typeof pageInfo2?.timestamp, 'Check page should have timestamp').toBe('number')
2625

27-
expect(typeof pageInfo2?.timestamp, 'Check page should have timestamp').toBe('number')
26+
expect(pageInfo2.timestamp, 'Check page should be cached').toBe(pageInfo1.timestamp)
2827

29-
expect(pageInfo2.timestamp, 'Check page should be cached').toBe(pageInfo1.timestamp)
28+
const response = await page.goto(`${after.url}/after/trigger`)
3029

31-
const response = await page.goto(`${after.url}/after/trigger`)
30+
expect(response?.status(), 'Trigger should return 200').toBe(200)
3231

33-
expect(response?.status(), 'Trigger should return 200').toBe(200)
32+
// wait for next/after to trigger revalidation of check page
33+
await new Promise((resolve) => setTimeout(resolve, 5000))
3434

35-
// wait for next/after to trigger revalidation of check page
36-
await new Promise((resolve) => setTimeout(resolve, 5000))
35+
await page.goto(`${after.url}/after/check`)
36+
const pageInfoLocator3 = await page.locator('#page-info')
37+
const pageInfo3 = JSON.parse((await pageInfoLocator3.textContent()) ?? '{}')
3738

38-
await page.goto(`${after.url}/after/check`)
39-
const pageInfoLocator3 = await page.locator('#page-info')
40-
const pageInfo3 = JSON.parse((await pageInfoLocator3.textContent()) ?? '{}')
41-
42-
expect(typeof pageInfo3?.timestamp, 'Check page should have timestamp').toBe('number')
43-
expect(
44-
pageInfo3.timestamp,
45-
'Check page should be invalidated with newer timestamp',
46-
).toBeGreaterThan(pageInfo1.timestamp)
47-
})
39+
expect(typeof pageInfo3?.timestamp, 'Check page should have timestamp').toBe('number')
40+
expect(
41+
pageInfo3.timestamp,
42+
'Check page should be invalidated with newer timestamp',
43+
).toBeGreaterThan(pageInfo1.timestamp)
44+
})
45+
}

tests/e2e/middleware.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,12 @@ for (const { expectedRuntime, isNodeMiddleware, label, testWithSwitchableMiddlew
165165
expect(await res?.headerValue('x-runtime')).toEqual(expectedRuntime)
166166
})
167167

168-
if (expectedRuntime !== 'node') {
168+
if (expectedRuntime !== 'node' && nextVersionSatisfies('>=14.0.0')) {
169169
// adaptation of https://github.com/vercel/next.js/blob/8aa9a52c36f338320d55bd2ec292ffb0b8c7cb35/test/e2e/app-dir/metadata-edge/index.test.ts#L24C5-L31C7
170170
test('it should render OpenGraph image meta tag correctly', async ({
171171
page,
172172
middlewareOg,
173173
}) => {
174-
test.skip(!nextVersionSatisfies('>=14.0.0'), 'This test is only for Next.js 14+')
175174
await page.goto(`${middlewareOg.url}/`)
176175
const ogURL = await page.locator('meta[property="og:image"]').getAttribute('content')
177176
expect(ogURL).toBeTruthy()

tests/utils/next-version-helpers.mjs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export async function setNextVersionInFixture(
110110

111111
const isSemverVersion = valid(resolvedVersion)
112112

113-
const areNextVersionConstraintsSatisfied = await Promise.all(
113+
const packageJsonsNeedUpdates = await Promise.all(
114114
packageJsons.map(async (packageJsonPath) => {
115115
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'))
116116
if (packageJson.dependencies?.next) {
@@ -130,15 +130,19 @@ export async function setNextVersionInFixture(
130130
`${logPrefix}⏩ Skipping '${packageJson.name}' because it requires next@${versionConstraint}`,
131131
)
132132
}
133-
return false
133+
return { packageJsonPath, needUpdate: false }
134134
}
135135
}
136-
return true
136+
return { packageJsonPath, needUpdate: true }
137137
}),
138138
)
139139

140-
if (areNextVersionConstraintsSatisfied.some((isSatisfied) => !isSatisfied)) {
141-
// at least one next version constraint is not satisfied so we skip this fixture
140+
const packageJsonsToUpdate = packageJsonsNeedUpdates
141+
.filter(({ needUpdate }) => needUpdate)
142+
.map(({ packageJsonPath }) => packageJsonPath)
143+
144+
if (packageJsonsToUpdate.length === 0) {
145+
// all next version constraints are not satisfied so we skip this fixture
142146
return false
143147
}
144148

@@ -154,7 +158,7 @@ export async function setNextVersionInFixture(
154158
}
155159

156160
await Promise.all(
157-
packageJsons.map(async (packageJsonPath) => {
161+
packageJsonsToUpdate.map(async (packageJsonPath) => {
158162
const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf8'))
159163
if (packageJson.dependencies?.next) {
160164
packageJson.dependencies.next = version

0 commit comments

Comments
 (0)