Skip to content

Commit

Permalink
test(e2e): fix failures due to latest and canary releases (#2587)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
serhalp authored Sep 17, 2024
1 parent 8a9a8d5 commit 220e17f
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
12 changes: 10 additions & 2 deletions tests/e2e/cli-before-regional-blobs-support.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from '@playwright/test'
import { test } from '../utils/playwright-helpers.js'
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'

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

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

// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
// after that (14.2.10 and canary.147) 404 pages would have `private` directive, before that it
// would not
const shouldHavePrivateDirective = nextVersionSatisfies('^14.2.10 || >=15.0.0-canary.147')
expect(headers['netlify-cdn-cache-control']).toBe(
'no-cache, no-store, max-age=0, must-revalidate, durable',
(shouldHavePrivateDirective ? 'private, ' : '') +
'no-cache, no-store, max-age=0, must-revalidate, durable',
)
expect(headers['cache-control']).toBe(
(shouldHavePrivateDirective ? 'private,' : '') + 'no-cache,no-store,max-age=0,must-revalidate',
)
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
})
24 changes: 20 additions & 4 deletions tests/e2e/page-router.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { expect } from '@playwright/test'
import { test } from '../utils/playwright-helpers.js'
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'

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

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

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

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

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

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

test('requesting a non existing page route that needs to be fetched from the blob store like 404.html (notFound: true)', async ({
Expand Down
8 changes: 6 additions & 2 deletions tests/e2e/simple-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,12 @@ test('requesting a non existing page route that needs to be fetched from the blo
expect(await page.textContent('h1')).toBe('404 Not Found')

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

expect(headers['netlify-cdn-cache-control']).toBe(
(shouldHavePrivateDirective ? 'private, ' : '') +
Expand Down
10 changes: 9 additions & 1 deletion tests/integration/static.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getBlobEntries,
startMockBlobStore,
} from '../utils/helpers.js'
import { nextVersionSatisfies } from '../utils/next-version-helpers.mjs'

// Disable the verbose logging of the lambda-local runtime
getLogger().level = 'alert'
Expand Down Expand Up @@ -50,9 +51,16 @@ test<FixtureTestContext>('requesting a non existing page route that needs to be
const call1 = await invokeFunction(ctx, { url: 'static/revalidate-not-existing' })
expect(call1.statusCode).toBe(404)
expect(load(call1.body)('h1').text()).toBe('404')

// https://github.com/vercel/next.js/pull/69802 made changes to returned cache-control header,
// after that (14.2.10 and canary.147) 404 pages would have `private` directive, before that it
// would not
const shouldHavePrivateDirective = nextVersionSatisfies('^14.2.10 || >=15.0.0-canary.147')
expect(call1.headers, 'a cache hit on the first invocation of a prerendered page').toEqual(
expect.objectContaining({
'netlify-cdn-cache-control': 'no-cache, no-store, max-age=0, must-revalidate, durable',
'netlify-cdn-cache-control':
(shouldHavePrivateDirective ? 'private, ' : '') +
'no-cache, no-store, max-age=0, must-revalidate, durable',
}),
)
})
Expand Down

0 comments on commit 220e17f

Please sign in to comment.