Skip to content

Commit 5a318ab

Browse files
committed
test(e2e): fix failures due to latest and canary releases
[v14.2.10](https://github.com/vercel/next.js/releases/tag/v14.2.10) and [v15.0.0-canary.147](https://github.com/vercel/next.js/releases/tag/v15.0.0-canary.147) included vercel/next.js#69802 which added `private` back into `no-cache,no-store` `cache-control` headers in some cases.
1 parent 8a9a8d5 commit 5a318ab

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

tests/e2e/cli-before-regional-blobs-support.test.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from '@playwright/test'
22
import { test } from '../utils/playwright-helpers.js'
3+
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
34

45
test('should serve 404 page when requesting non existing page (no matching route) if site is deployed with CLI not supporting regional blobs', async ({
56
page,
@@ -18,8 +19,17 @@ test('should serve 404 page when requesting non existing page (no matching route
1819

1920
expect(await page.textContent('h1')).toBe('404')
2021

22+
// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
23+
// after that (14.2.10 and canary.147) 404 pages would have `private` directive, before that it
24+
// would not
25+
const shouldHavePrivateDirective = nextVersionSatisfies(
26+
'>=14.2.10 <15.0.0 || >=15.0.0-canary.147',
27+
)
2128
expect(headers['netlify-cdn-cache-control']).toBe(
22-
'no-cache, no-store, max-age=0, must-revalidate, durable',
29+
(shouldHavePrivateDirective ? 'private, ' : '') +
30+
'private, no-cache, no-store, max-age=0, must-revalidate, durable',
31+
)
32+
expect(headers['cache-control']).toBe(
33+
(shouldHavePrivateDirective ? 'private,' : '') + 'no-cache,no-store,max-age=0,must-revalidate',
2334
)
24-
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
2535
})

tests/e2e/page-router.test.ts

+24-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect } from '@playwright/test'
22
import { test } from '../utils/playwright-helpers.js'
3+
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
34

45
export function waitFor(millis: number) {
56
return new Promise((resolve) => setTimeout(resolve, millis))
@@ -340,10 +341,20 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
340341

341342
expect(await page.textContent('h1')).toBe('404')
342343

344+
// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
345+
// after that (14.2.10 and canary.147) 404 pages would have `private` directive, before that
346+
// it would not
347+
const shouldHavePrivateDirective = nextVersionSatisfies(
348+
'>=14.2.10 <15.0.0 || >=15.0.0-canary.147',
349+
)
343350
expect(headers['netlify-cdn-cache-control']).toBe(
344-
'no-cache, no-store, max-age=0, must-revalidate, durable',
351+
(shouldHavePrivateDirective ? 'private, ' : '') +
352+
'no-cache, no-store, max-age=0, must-revalidate, durable',
353+
)
354+
expect(headers['cache-control']).toBe(
355+
(shouldHavePrivateDirective ? 'private,' : '') +
356+
'no-cache,no-store,max-age=0,must-revalidate',
345357
)
346-
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
347358
})
348359

349360
test('should serve 404 page when requesting non existing page (marked with notFound: true in getStaticProps)', async ({
@@ -1039,10 +1050,19 @@ test.describe('Page Router with basePath and i18n', () => {
10391050

10401051
expect(await page.textContent('h1')).toBe('404')
10411052

1053+
// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
1054+
// after that 404 pages would have `private` directive, before that it would not
1055+
const shouldHavePrivateDirective = nextVersionSatisfies(
1056+
'>=14.2.10 <15.0.0 || >=15.0.0-canary.147',
1057+
)
10421058
expect(headers['netlify-cdn-cache-control']).toBe(
1043-
'no-cache, no-store, max-age=0, must-revalidate, durable',
1059+
(shouldHavePrivateDirective ? 'private, ' : '') +
1060+
'no-cache, no-store, max-age=0, must-revalidate, durable',
1061+
)
1062+
expect(headers['cache-control']).toBe(
1063+
(shouldHavePrivateDirective ? 'private,' : '') +
1064+
'no-cache,no-store,max-age=0,must-revalidate',
10441065
)
1045-
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
10461066
})
10471067

10481068
test('requesting a non existing page route that needs to be fetched from the blob store like 404.html (notFound: true)', async ({

tests/e2e/simple-app.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,12 @@ test('requesting a non existing page route that needs to be fetched from the blo
220220
expect(await page.textContent('h1')).toBe('404 Not Found')
221221

222222
// https://github.com/vercel/next.js/pull/66674 made changes to returned cache-control header,
223-
// before that 404 page would have `private` directive, after that it would not
224-
const shouldHavePrivateDirective = !nextVersionSatisfies('>=14.2.4 <15.0.0 || >=15.0.0-canary.24')
223+
// before that 404 page would have `private` directive, after that (14.2.4 and canary.24) it
224+
// would not ... and then https://github.com/vercel/next.js/pull/69802 changed it back again
225+
// (14.2.10 and canary.147)
226+
const shouldHavePrivateDirective = nextVersionSatisfies(
227+
'<14.2.4 || >=14.2.10 < 15 || <15.0.0-canary.24 || >= 15.0.0-canary.147',
228+
)
225229

226230
expect(headers['netlify-cdn-cache-control']).toBe(
227231
(shouldHavePrivateDirective ? 'private, ' : '') +

0 commit comments

Comments
 (0)