Skip to content

Commit

Permalink
test: adjust tests for [email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Oct 14, 2024
1 parent 4f5f563 commit 2973a63
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 41 deletions.
17 changes: 13 additions & 4 deletions tests/e2e/on-demand-app.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.describe('app router on-demand revalidation', () => {
for (const { label, prerendered, pagePath, revalidateApiPath, expectedH1Content } of [
Expand Down Expand Up @@ -90,7 +91,9 @@ test.describe('app router on-demand revalidation', () => {
expect(response1?.status()).toBe(200)
expect(headers1['x-nextjs-cache']).toBeUndefined()
expect(headers1['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1 = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -118,7 +121,9 @@ test.describe('app router on-demand revalidation', () => {
expect(headers2['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers2['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -148,7 +153,9 @@ test.describe('app router on-demand revalidation', () => {
expect(response3?.status()).toBe(200)
expect(headers3?.['x-nextjs-cache']).toBeUndefined()
expect(headers3['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page has now an updated date
Expand All @@ -175,7 +182,9 @@ test.describe('app router on-demand revalidation', () => {
expect(headers4['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers4['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down
80 changes: 60 additions & 20 deletions tests/e2e/page-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
expect(headers1['x-nextjs-cache']).toBeUndefined()
expect(headers1['netlify-cache-tag']).toBe(`_n_t_${encodeURI(pagePath).toLowerCase()}`)
expect(headers1['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1 = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -156,7 +158,9 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
expect(headers1Json['x-nextjs-cache']).toBeUndefined()
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_${encodeURI(pagePath).toLowerCase()}`)
expect(headers1Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
const data1 = (await response1Json?.json()) || {}
expect(data1?.pageProps?.time).toBe(date1)
Expand All @@ -181,7 +185,9 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
expect(headers2['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers2['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -212,7 +218,9 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
expect(headers2Json['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers2Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data2 = (await response2Json?.json()) || {}
Expand Down Expand Up @@ -267,7 +275,9 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
expect(response3Json?.status()).toBe(200)
expect(headers3Json['x-nextjs-cache']).toBeUndefined()
expect(headers3Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data3 = (await response3Json?.json()) || {}
Expand Down Expand Up @@ -382,7 +392,9 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
expect(await page.textContent('h1')).toBe('404')

expect(headers['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
expect(headers['cache-control']).toBe('public,max-age=0,must-revalidate')
})
Expand Down Expand Up @@ -532,7 +544,9 @@ test.describe('Page Router with basePath and i18n', () => {
`_n_t_/en${encodeURI(pagePath).toLowerCase()}`,
)
expect(headers1ImplicitLocale['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1ImplicitLocale = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -560,7 +574,9 @@ test.describe('Page Router with basePath and i18n', () => {
`_n_t_/en${encodeURI(pagePath).toLowerCase()}`,
)
expect(headers1ExplicitLocale['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1ExplicitLocale = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -594,7 +610,9 @@ test.describe('Page Router with basePath and i18n', () => {
`_n_t_/en${encodeURI(pagePath).toLowerCase()}`,
)
expect(headers1Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
const data1 = (await response1Json?.json()) || {}
expect(data1?.pageProps?.time).toBe(date1ImplicitLocale)
Expand Down Expand Up @@ -622,7 +640,9 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers2ImplicitLocale['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers2ImplicitLocale['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -652,7 +672,9 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers2ExplicitLocale['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers2ExplicitLocale['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -683,7 +705,9 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers2Json['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers2Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data2 = (await response2Json?.json()) || {}
Expand Down Expand Up @@ -777,7 +801,9 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers3Json['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers3Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data3 = (await response3Json?.json()) || {}
Expand Down Expand Up @@ -866,7 +892,9 @@ test.describe('Page Router with basePath and i18n', () => {
expect(response4Json?.status()).toBe(200)
expect(headers4Json['x-nextjs-cache']).toBeUndefined()
expect(headers4Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data4 = (await response4Json?.json()) || {}
Expand Down Expand Up @@ -912,7 +940,9 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers1['x-nextjs-cache']).toBeUndefined()
expect(headers1['netlify-cache-tag']).toBe(`_n_t_/de${encodeURI(pagePath).toLowerCase()}`)
expect(headers1['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1 = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -943,7 +973,9 @@ test.describe('Page Router with basePath and i18n', () => {
`_n_t_/de${encodeURI(pagePath).toLowerCase()}`,
)
expect(headers1Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
const data1 = (await response1Json?.json()) || {}
expect(data1?.pageProps?.time).toBe(date1)
Expand Down Expand Up @@ -971,7 +1003,9 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers2['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers2['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -1003,7 +1037,9 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers2Json['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers2Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data2 = (await response2Json?.json()) || {}
Expand Down Expand Up @@ -1070,7 +1106,9 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers3Json['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers3Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data3 = (await response3Json?.json()) || {}
Expand Down Expand Up @@ -1114,7 +1152,9 @@ test.describe('Page Router with basePath and i18n', () => {
expect(await page.textContent('h1')).toBe('404')

expect(headers['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
expect(headers['cache-control']).toBe('public,max-age=0,must-revalidate')
})
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e/simple-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ test('requesting a non existing page route that needs to be fetched from the blo
expect(await page.textContent('h1')).toBe('404 Not Found')

expect(headers['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
expect(headers['cache-control']).toBe('public,max-age=0,must-revalidate')
})
Expand Down
17 changes: 13 additions & 4 deletions tests/e2e/turborepo.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'

// those tests have different fixtures and can run in parallel
test.describe.configure({ mode: 'parallel' })
Expand Down Expand Up @@ -35,7 +36,9 @@ test.describe('[PNPM] Package manager', () => {
expect(response1?.status()).toBe(200)
expect(headers1['x-nextjs-cache']).toBeUndefined()
expect(headers1['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1 = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -65,7 +68,9 @@ test.describe('[PNPM] Package manager', () => {
expect(headers2['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers2['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -139,7 +144,9 @@ test.describe('[NPM] Package manager', () => {
expect(response1?.status()).toBe(200)
expect(headers1['x-nextjs-cache']).toBeUndefined()
expect(headers1['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1 = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -169,7 +176,9 @@ test.describe('[NPM] Package manager', () => {
expect(headers2['cache-status']).toMatch(/"Next.js"; hit/m)
}
expect(headers2['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000, durable',
nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down
9 changes: 7 additions & 2 deletions tests/integration/cache-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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 @@ -89,7 +90,9 @@ describe('page router', () => {
).toEqual(
expect.objectContaining({
'cache-status': '"Next.js"; hit',
'netlify-cdn-cache-control': 's-maxage=5, stale-while-revalidate=31536000, durable',
'netlify-cdn-cache-control': nextVersionSatisfies('>=15.0.0-canary.187')
? `s-maxage=5, stale-while-revalidate=${31536000 - 5}, durable`
: 's-maxage=5, stale-while-revalidate=31536000, durable',
}),
)
expect(
Expand Down Expand Up @@ -240,7 +243,9 @@ describe('app router', () => {
// It will be hit instead of stale
expect.objectContaining({
'cache-status': '"Next.js"; hit',
'netlify-cdn-cache-control': 's-maxage=31536000, stale-while-revalidate=31536000, durable',
'netlify-cdn-cache-control': nextVersionSatisfies('>=15.0.0-canary.187')
? 's-maxage=31536000, durable'
: 's-maxage=31536000, stale-while-revalidate=31536000, durable',
}),
)
expect(
Expand Down
9 changes: 7 additions & 2 deletions tests/integration/fetch-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { afterAll, beforeAll, beforeEach, expect, test, vi } from 'vitest'
import { type FixtureTestContext } from '../utils/contexts.js'
import { createFixture, invokeFunction, runPlugin, runPluginStep } from '../utils/fixture.js'
import { generateRandomObjectID, 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 @@ -229,7 +230,9 @@ test<FixtureTestContext>('if the fetch call is cached correctly (cached page res
).toEqual(
expect.objectContaining({
'cache-status': '"Next.js"; hit',
'netlify-cdn-cache-control': 's-maxage=5, stale-while-revalidate=31536000, durable',
'netlify-cdn-cache-control': nextVersionSatisfies('>=15.0.0-canary.187')
? `s-maxage=5, stale-while-revalidate=${31536000 - 5}, durable`
: 's-maxage=5, stale-while-revalidate=31536000, durable',
}),
)

Expand Down Expand Up @@ -295,7 +298,9 @@ test<FixtureTestContext>('if the fetch call is cached correctly (cached page res
).toEqual(
expect.objectContaining({
'cache-status': '"Next.js"; hit',
'netlify-cdn-cache-control': 's-maxage=5, stale-while-revalidate=31536000, durable',
'netlify-cdn-cache-control': nextVersionSatisfies('>=15.0.0-canary.187')
? `s-maxage=5, stale-while-revalidate=${31536000 - 5}, durable`
: 's-maxage=5, stale-while-revalidate=31536000, durable',
}),
)
})
Loading

0 comments on commit 2973a63

Please sign in to comment.