From 32ddc9aacb10aa7b9fa1a94861a3fd76c0ea4e82 Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Fri, 8 Sep 2023 17:22:56 +0200 Subject: [PATCH] test: add netlify-vary assertions --- cypress/e2e/default/dynamic-routes.cy.ts | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/cypress/e2e/default/dynamic-routes.cy.ts b/cypress/e2e/default/dynamic-routes.cy.ts index c84509884a..22530cc915 100644 --- a/cypress/e2e/default/dynamic-routes.cy.ts +++ b/cypress/e2e/default/dynamic-routes.cy.ts @@ -16,11 +16,32 @@ describe('Static Routing', () => { expect(res.body).to.contain('Dancing with the Stars') }) }) + it('renders correct page via ODB on a static route (root)', () => { + cy.request({ url: '/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => { + console.log(res.headers) + expect(res.status).to.eq(200) + if (CDNCacheControlEnabled) { + expect(res.headers).to.have.property('netlify-cdn-cache-control', 's-maxage=60, stale-while-revalidate') + expect(res.headers).to.have.property( + 'netlify-vary', + 'header=Accept-Encoding,language=en|es|fr,cookie=__prerender_bypass|__next_preview_data|NEXT_LOCALE', + ) + } else { + expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60') + } + expect(res.body).to.contain('NextJS on Netlify') + }) + }) + it('renders correct page via ODB on a static route', () => { cy.request({ url: '/getStaticProps/with-revalidate/', headers: { 'x-nf-debug-logging': '1' } }).then((res) => { expect(res.status).to.eq(200) if (CDNCacheControlEnabled) { expect(res.headers).to.have.property('netlify-cdn-cache-control', 's-maxage=1, stale-while-revalidate') + expect(res.headers).to.have.property( + 'netlify-vary', + 'header=Accept-Encoding,cookie=__prerender_bypass|__next_preview_data', + ) } else { expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60') } @@ -72,6 +93,10 @@ describe('Dynamic Routing', () => { expect(res.status).to.eq(200) if (CDNCacheControlEnabled) { expect(res.headers).to.have.property('netlify-cdn-cache-control', 's-maxage=31536000, stale-while-revalidate') + expect(res.headers).to.have.property( + 'netlify-vary', + 'header=Accept-Encoding,cookie=__prerender_bypass|__next_preview_data', + ) } else { // expect 'odb' until https://github.com/netlify/pillar-runtime/issues/438 is fixed expect(res.headers).to.have.property('x-nf-render-mode', 'odb') @@ -95,6 +120,10 @@ describe('Dynamic Routing', () => { expect(res.status).to.eq(200) if (CDNCacheControlEnabled) { expect(res.headers).to.have.property('netlify-cdn-cache-control', 's-maxage=31536000, stale-while-revalidate') + expect(res.headers).to.have.property( + 'netlify-vary', + 'header=Accept-Encoding,cookie=__prerender_bypass|__next_preview_data', + ) } else { expect(res.headers).to.have.property('x-nf-render-mode', 'odb') } @@ -107,6 +136,10 @@ describe('Dynamic Routing', () => { expect(res.status).to.eq(200) if (CDNCacheControlEnabled) { expect(res.headers).to.have.property('netlify-cdn-cache-control', 's-maxage=60, stale-while-revalidate') + expect(res.headers).to.have.property( + 'netlify-vary', + 'header=Accept-Encoding,cookie=__prerender_bypass|__next_preview_data', + ) } else { expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60') } @@ -130,6 +163,10 @@ describe('Dynamic Routing', () => { expect(res.status).to.eq(200) if (CDNCacheControlEnabled) { expect(res.headers).to.have.property('netlify-cdn-cache-control', 's-maxage=60, stale-while-revalidate') + expect(res.headers).to.have.property( + 'netlify-vary', + 'header=Accept-Encoding,cookie=__prerender_bypass|__next_preview_data', + ) } else { expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60') } @@ -143,6 +180,10 @@ describe('Dynamic Routing', () => { expect(res.status).to.eq(200) if (CDNCacheControlEnabled) { expect(res.headers).to.have.property('netlify-cdn-cache-control', 's-maxage=60, stale-while-revalidate') + expect(res.headers).to.have.property( + 'netlify-vary', + 'header=Accept-Encoding,cookie=__prerender_bypass|__next_preview_data', + ) } else { expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60') } @@ -159,6 +200,10 @@ describe('Dynamic Routing', () => { expect(res.status).to.eq(200) if (CDNCacheControlEnabled) { expect(res.headers).to.have.property('netlify-cdn-cache-control', 's-maxage=60, stale-while-revalidate') + expect(res.headers).to.have.property( + 'netlify-vary', + 'header=Accept-Encoding,cookie=__prerender_bypass|__next_preview_data', + ) } else { expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60') } @@ -173,6 +218,10 @@ describe('Dynamic Routing', () => { expect(res.status).to.eq(200) if (CDNCacheControlEnabled) { expect(res.headers).to.have.property('netlify-cdn-cache-control', 's-maxage=60, stale-while-revalidate') + expect(res.headers).to.have.property( + 'netlify-vary', + 'header=Accept-Encoding,cookie=__prerender_bypass|__next_preview_data', + ) } else { expect(res.headers).to.have.property('x-nf-render-mode', 'odb ttl=60') }