Skip to content

Commit 220e17f

Browse files
authored
test(e2e): fix failures due to latest and canary releases (#2587)
* 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. * fix: fix private directive logic in tests * test: update one more no-cache test
1 parent 8a9a8d5 commit 220e17f

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

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

+10-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,15 @@ 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('^14.2.10 || >=15.0.0-canary.147')
2126
expect(headers['netlify-cdn-cache-control']).toBe(
22-
'no-cache, no-store, max-age=0, must-revalidate, durable',
27+
(shouldHavePrivateDirective ? 'private, ' : '') +
28+
'no-cache, no-store, max-age=0, must-revalidate, durable',
29+
)
30+
expect(headers['cache-control']).toBe(
31+
(shouldHavePrivateDirective ? 'private,' : '') + 'no-cache,no-store,max-age=0,must-revalidate',
2332
)
24-
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
2533
})

Diff for: tests/e2e/page-router.test.ts

+20-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,18 @@ 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('^14.2.10 || >=15.0.0-canary.147')
343348
expect(headers['netlify-cdn-cache-control']).toBe(
344-
'no-cache, no-store, max-age=0, must-revalidate, durable',
349+
(shouldHavePrivateDirective ? 'private, ' : '') +
350+
'no-cache, no-store, max-age=0, must-revalidate, durable',
351+
)
352+
expect(headers['cache-control']).toBe(
353+
(shouldHavePrivateDirective ? 'private,' : '') +
354+
'no-cache,no-store,max-age=0,must-revalidate',
345355
)
346-
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
347356
})
348357

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

10401049
expect(await page.textContent('h1')).toBe('404')
10411050

1051+
// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
1052+
// after that 404 pages would have `private` directive, before that it would not
1053+
const shouldHavePrivateDirective = nextVersionSatisfies('^14.2.10 || >=15.0.0-canary.147')
10421054
expect(headers['netlify-cdn-cache-control']).toBe(
1043-
'no-cache, no-store, max-age=0, must-revalidate, durable',
1055+
(shouldHavePrivateDirective ? 'private, ' : '') +
1056+
'no-cache, no-store, max-age=0, must-revalidate, durable',
1057+
)
1058+
expect(headers['cache-control']).toBe(
1059+
(shouldHavePrivateDirective ? 'private,' : '') +
1060+
'no-cache,no-store,max-age=0,must-revalidate',
10441061
)
1045-
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
10461062
})
10471063

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

Diff for: 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.0.0-canary.24 || ^15.0.0-canary.147',
228+
)
225229

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

Diff for: tests/integration/static.test.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
getBlobEntries,
1414
startMockBlobStore,
1515
} from '../utils/helpers.js'
16+
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'
1617

1718
// Disable the verbose logging of the lambda-local runtime
1819
getLogger().level = 'alert'
@@ -50,9 +51,16 @@ test<FixtureTestContext>('requesting a non existing page route that needs to be
5051
const call1 = await invokeFunction(ctx, { url: 'static/revalidate-not-existing' })
5152
expect(call1.statusCode).toBe(404)
5253
expect(load(call1.body)('h1').text()).toBe('404')
54+
55+
// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
56+
// after that (14.2.10 and canary.147) 404 pages would have `private` directive, before that it
57+
// would not
58+
const shouldHavePrivateDirective = nextVersionSatisfies('^14.2.10 || >=15.0.0-canary.147')
5359
expect(call1.headers, 'a cache hit on the first invocation of a prerendered page').toEqual(
5460
expect.objectContaining({
55-
'netlify-cdn-cache-control': 'no-cache, no-store, max-age=0, must-revalidate, durable',
61+
'netlify-cdn-cache-control':
62+
(shouldHavePrivateDirective ? 'private, ' : '') +
63+
'no-cache, no-store, max-age=0, must-revalidate, durable',
5664
}),
5765
)
5866
})

0 commit comments

Comments
 (0)