Skip to content

Commit

Permalink
test: update assertions for fully rolled out durable cache
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Aug 21, 2024
1 parent c993184 commit 7c15344
Show file tree
Hide file tree
Showing 15 changed files with 60 additions and 82 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/cli-before-regional-blobs-support.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('should serve 404 page when requesting non existing page (no matching route
expect(await page.textContent('h1')).toBe('404')

expect(headers['netlify-cdn-cache-control']).toBe(
'no-cache, no-store, max-age=0, must-revalidate',
'no-cache, no-store, max-age=0, must-revalidate, durable',
)
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
})
19 changes: 0 additions & 19 deletions tests/e2e/durable-cache.test.ts

This file was deleted.

8 changes: 4 additions & 4 deletions tests/e2e/on-demand-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1 = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -104,7 +104,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -134,7 +134,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page has now an updated date
Expand All @@ -161,7 +161,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

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

const date1 = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -139,7 +139,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
expect(headers1Json['x-nextjs-cache']).toBeUndefined()
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_${pagePath}`)
expect(headers1Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
const data1 = (await response1Json?.json()) || {}
expect(data1?.pageProps?.time).toBe(date1)
Expand All @@ -164,7 +164,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -195,7 +195,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data2 = (await response2Json?.json()) || {}
Expand Down Expand Up @@ -250,7 +250,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

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

expect(headers['netlify-cdn-cache-control']).toBe(
'no-cache, no-store, max-age=0, must-revalidate',
'no-cache, no-store, max-age=0, must-revalidate, durable',
)
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
})
Expand All @@ -357,7 +357,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
expect(headers['cache-control']).toBe('public,max-age=0,must-revalidate')
})
Expand Down Expand Up @@ -401,7 +401,7 @@ test.describe('Simple Page Router (no basePath, no i18n)', () => {
const response = await page.goto(new URL('static/fully-static', pageRouter.url).href)
const headers = response?.headers() || {}

expect(headers['netlify-cdn-cache-control']).toBe('max-age=31536000')
expect(headers['netlify-cdn-cache-control']).toBe('max-age=31536000, durable')
expect(headers['cache-control']).toBe('public,max-age=0,must-revalidate')
})

Expand Down Expand Up @@ -487,7 +487,7 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers1ImplicitLocale['x-nextjs-cache']).toBeUndefined()
expect(headers1ImplicitLocale['netlify-cache-tag']).toBe(`_n_t_/en${pagePath}`)
expect(headers1ImplicitLocale['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1ImplicitLocale = await page.textContent('[data-testid="date-now"]')
Expand All @@ -513,7 +513,7 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers1ExplicitLocale['x-nextjs-cache']).toBeUndefined()
expect(headers1ExplicitLocale['netlify-cache-tag']).toBe(`_n_t_/en${pagePath}`)
expect(headers1ExplicitLocale['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1ExplicitLocale = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -545,7 +545,7 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers1Json['x-nextjs-cache']).toBeUndefined()
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_/en${pagePath}`)
expect(headers1Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
const data1 = (await response1Json?.json()) || {}
expect(data1?.pageProps?.time).toBe(date1ImplicitLocale)
Expand Down Expand Up @@ -573,7 +573,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -603,7 +603,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -634,7 +634,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data2 = (await response2Json?.json()) || {}
Expand Down Expand Up @@ -728,7 +728,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data3 = (await response3Json?.json()) || {}
Expand Down Expand Up @@ -817,7 +817,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

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

const date1 = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -892,7 +892,7 @@ test.describe('Page Router with basePath and i18n', () => {
expect(headers1Json['x-nextjs-cache']).toBeUndefined()
expect(headers1Json['netlify-cache-tag']).toBe(`_n_t_/de${pagePath}`)
expect(headers1Json['netlify-cdn-cache-control']).toBe(
's-maxage=31536000, stale-while-revalidate=31536000',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
const data1 = (await response1Json?.json()) || {}
expect(data1?.pageProps?.time).toBe(date1)
Expand Down Expand Up @@ -920,7 +920,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -952,7 +952,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const data2 = (await response2Json?.json()) || {}
Expand Down Expand Up @@ -1019,7 +1019,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

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

expect(headers['netlify-cdn-cache-control']).toBe(
'no-cache, no-store, max-age=0, must-revalidate',
'no-cache, no-store, max-age=0, must-revalidate, durable',
)
expect(headers['cache-control']).toBe('no-cache,no-store,max-age=0,must-revalidate')
})
Expand All @@ -1056,7 +1056,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
expect(headers['cache-control']).toBe('public,max-age=0,must-revalidate')
})
Expand Down
13 changes: 8 additions & 5 deletions tests/e2e/simple-app.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ test('Renders the Home page correctly', async ({ page, simple }) => {

await expect(page).toHaveTitle('Simple Next App')

expect(headers['cache-status']).toBe(
'"Next.js"; hit\n"Netlify Durable"; fwd=miss\n"Netlify Edge"; fwd=miss',
)
expect(headers['cache-status']).toMatch(/^"Next.js"; hit$/m)
expect(headers['cache-status']).toMatch(/^"Netlify Edge"; fwd=miss$/m)
// "Netlify Durable" assertion is skipped because we are asserting index page and there are possible that something else is making similar request to it
// and as a result we can see many possible statuses for it: `fwd=miss`, `fwd=miss; stored`, `hit; ttl=<ttl>` so there is no point in asserting on that
// "Netlify Edge" status suffers from similar issue, but is less likely to manifest (only if those requests would be handled by same CDN node) and retries
// usually allow to pass the test

const h1 = page.locator('h1')
await expect(h1).toHaveText('Home')
Expand Down Expand Up @@ -222,7 +225,7 @@ test('requesting a non existing page route that needs to be fetched from the blo

expect(headers['netlify-cdn-cache-control']).toBe(
(shouldHavePrivateDirective ? 'private, ' : '') +
'no-cache, no-store, max-age=0, must-revalidate',
'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',
Expand All @@ -240,7 +243,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)
expect(headers['cache-control']).toBe('public,max-age=0,must-revalidate')
})
Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/turborepo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1 = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -65,7 +65,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down Expand Up @@ -139,7 +139,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

const date1 = await page.textContent('[data-testid="date-now"]')
Expand Down Expand Up @@ -169,7 +169,7 @@ 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',
's-maxage=31536000, stale-while-revalidate=31536000, durable',
)

// the page is cached
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/cache-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('page router', () => {
).toEqual(
expect.objectContaining({
'cache-status': '"Next.js"; hit',
'netlify-cdn-cache-control': 's-maxage=5, stale-while-revalidate=31536000',
'netlify-cdn-cache-control': 's-maxage=5, stale-while-revalidate=31536000, durable',
}),
)
expect(
Expand Down Expand Up @@ -239,7 +239,7 @@ 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',
'netlify-cdn-cache-control': 's-maxage=31536000, stale-while-revalidate=31536000, durable',
}),
)
expect(
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/fetch-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ 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',
'netlify-cdn-cache-control': 's-maxage=5, stale-while-revalidate=31536000, durable',
}),
)

Expand Down Expand Up @@ -295,7 +295,7 @@ 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',
'netlify-cdn-cache-control': 's-maxage=5, stale-while-revalidate=31536000, durable',
}),
)
})
2 changes: 1 addition & 1 deletion tests/integration/page-router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ test.skipIf(platform === 'win32')<FixtureTestContext>(
url: '/static/fully-static',
})

expect(response.headers?.['netlify-cdn-cache-control']).toBe('max-age=31536000')
expect(response.headers?.['netlify-cdn-cache-control']).toBe('max-age=31536000, durable')
expect(response.headers?.['cache-control']).toBe('public, max-age=0, must-revalidate')
},
)
Expand Down
Loading

0 comments on commit 7c15344

Please sign in to comment.