From b217a0e3159544f3a3f71e85677107873e86765b Mon Sep 17 00:00:00 2001 From: Michal Piechowiak Date: Wed, 22 May 2024 18:29:01 +0200 Subject: [PATCH] test: add ssg specific headers --- e2e-tests/adapters/cypress/e2e/headers.cy.ts | 20 ++++++++ .../adapters/cypress/e2e/remote-file.cy.ts | 4 +- .../adapters/cypress/e2e/trailing-slash.cy.ts | 46 ++++++++++++++----- e2e-tests/adapters/gatsby-config.ts | 9 ++++ e2e-tests/adapters/gatsby-node.ts | 2 +- e2e-tests/adapters/src/pages/index.jsx | 8 ++-- .../pages/routes/{ => ssg}/remote-file.jsx | 2 +- .../src/pages/routes/{ => ssg}/static.jsx | 4 +- 8 files changed, 74 insertions(+), 21 deletions(-) rename e2e-tests/adapters/src/pages/routes/{ => ssg}/remote-file.jsx (98%) rename e2e-tests/adapters/src/pages/routes/{ => ssg}/static.jsx (61%) diff --git a/e2e-tests/adapters/cypress/e2e/headers.cy.ts b/e2e-tests/adapters/cypress/e2e/headers.cy.ts index a2cd58cdecbb8..e6f0d4d3708c8 100644 --- a/e2e-tests/adapters/cypress/e2e/headers.cy.ts +++ b/e2e-tests/adapters/cypress/e2e/headers.cy.ts @@ -76,6 +76,10 @@ describe("Headers", () => { beforeEach(() => { cy.intercept(PATH_PREFIX + "/", WorkaroundCachedResponse).as("index") + cy.intercept( + PATH_PREFIX + "/routes/ssg/static", + WorkaroundCachedResponse + ).as("ssg") cy.intercept( PATH_PREFIX + "/routes/ssr/static", WorkaroundCachedResponse @@ -128,6 +132,22 @@ describe("Headers", () => { checkHeaders("@js") }) + it("should contain correct headers for ssg page", () => { + cy.visit("routes/ssg/static").waitForRouteChange() + + checkHeaders("@ssg", { + ...defaultHeaders, + "x-custom-header": "my custom header value", + "x-dsg-header": "my custom header value", + "cache-control": "public,max-age=0,must-revalidate", + }) + + checkHeaders("@app-data") + checkHeaders("@page-data") + checkHeaders("@slice-data") + checkHeaders("@static-query-result") + }) + it("should contain correct headers for ssr page", () => { cy.visit("routes/ssr/static").waitForRouteChange() diff --git a/e2e-tests/adapters/cypress/e2e/remote-file.cy.ts b/e2e-tests/adapters/cypress/e2e/remote-file.cy.ts index 56adae8cec9b1..7d2a4599203aa 100644 --- a/e2e-tests/adapters/cypress/e2e/remote-file.cy.ts +++ b/e2e-tests/adapters/cypress/e2e/remote-file.cy.ts @@ -18,12 +18,12 @@ const PATH_PREFIX = Cypress.env(`PATH_PREFIX`) || `` const configs = [ { title: `remote-file (SSG, Page Query)`, - pagePath: `/routes/remote-file/`, + pagePath: `/routes/ssg/remote-file/`, placeholders: true, }, { title: `remote-file (SSG, Page Context)`, - pagePath: `/routes/remote-file-data-from-context/`, + pagePath: `/routes/ssg/remote-file-data-from-context/`, placeholders: true, }, { diff --git a/e2e-tests/adapters/cypress/e2e/trailing-slash.cy.ts b/e2e-tests/adapters/cypress/e2e/trailing-slash.cy.ts index c595f655907ce..0a4b1ce2de670 100644 --- a/e2e-tests/adapters/cypress/e2e/trailing-slash.cy.ts +++ b/e2e-tests/adapters/cypress/e2e/trailing-slash.cy.ts @@ -1,7 +1,7 @@ import { assertPageVisits } from "../utils/assert-page-visits" import { applyTrailingSlashOption } from "../../utils" -Cypress.on("uncaught:exception", (err) => { +Cypress.on("uncaught:exception", err => { if (err.message.includes("Minified React error")) { return false } @@ -12,38 +12,62 @@ const TRAILING_SLASH = Cypress.env(`TRAILING_SLASH`) || `never` describe("trailingSlash", () => { describe(TRAILING_SLASH, () => { it("should work when using Gatsby Link (without slash)", () => { - cy.visit('/').waitForRouteChange() + cy.visit("/").waitForRouteChange() - cy.get(`[data-testid="static-without-slash"]`).click().waitForRouteChange().assertRoute(applyTrailingSlashOption(`/routes/static`, TRAILING_SLASH)) + cy.get(`[data-testid="static-without-slash"]`) + .click() + .waitForRouteChange() + .assertRoute( + applyTrailingSlashOption(`/routes/ssg/static`, TRAILING_SLASH) + ) }) it("should work when using Gatsby Link (with slash)", () => { - cy.visit('/').waitForRouteChange() + cy.visit("/").waitForRouteChange() - cy.get(`[data-testid="static-with-slash"]`).click().waitForRouteChange().assertRoute(applyTrailingSlashOption(`/routes/static`, TRAILING_SLASH)) + cy.get(`[data-testid="static-with-slash"]`) + .click() + .waitForRouteChange() + .assertRoute( + applyTrailingSlashOption(`/routes/ssg/static`, TRAILING_SLASH) + ) }) it("should work on direct visit (with other setting)", () => { - const destination = applyTrailingSlashOption("/routes/static", TRAILING_SLASH) - const inverse = TRAILING_SLASH === `always` ? "/routes/static" : "/routes/static/" + const destination = applyTrailingSlashOption( + "/routes/ssg/static", + TRAILING_SLASH + ) + const inverse = + TRAILING_SLASH === `always` + ? "/routes/ssg/static" + : "/routes/ssg/static/" assertPageVisits([ { path: destination, status: 200, }, - { path: inverse, status: 301, destinationPath: destination } + { path: inverse, status: 301, destinationPath: destination }, ]) - cy.visit(inverse).waitForRouteChange().assertRoute(applyTrailingSlashOption(`/routes/static`, TRAILING_SLASH)) + cy.visit(inverse) + .waitForRouteChange() + .assertRoute( + applyTrailingSlashOption(`/routes/ssg/static`, TRAILING_SLASH) + ) }) it("should work on direct visit (with current setting)", () => { assertPageVisits([ { - path: applyTrailingSlashOption("/routes/static", TRAILING_SLASH), + path: applyTrailingSlashOption("/routes/ssg/static", TRAILING_SLASH), status: 200, }, ]) - cy.visit(applyTrailingSlashOption("/routes/static", TRAILING_SLASH)).waitForRouteChange().assertRoute(applyTrailingSlashOption(`/routes/static`, TRAILING_SLASH)) + cy.visit(applyTrailingSlashOption("/routes/ssg/static", TRAILING_SLASH)) + .waitForRouteChange() + .assertRoute( + applyTrailingSlashOption(`/routes/ssg/static`, TRAILING_SLASH) + ) }) }) }) diff --git a/e2e-tests/adapters/gatsby-config.ts b/e2e-tests/adapters/gatsby-config.ts index 78c0361981ae9..803de68814634 100644 --- a/e2e-tests/adapters/gatsby-config.ts +++ b/e2e-tests/adapters/gatsby-config.ts @@ -77,6 +77,15 @@ const config: GatsbyConfig = { }, ], }, + { + source: `routes/ssg/*`, + headers: [ + { + key: "x-ssg-header", + value: "my custom header value", + }, + ], + }, ], ...configOverrides, } diff --git a/e2e-tests/adapters/gatsby-node.ts b/e2e-tests/adapters/gatsby-node.ts index 9342bb30fa191..f0c6697d1f932 100644 --- a/e2e-tests/adapters/gatsby-node.ts +++ b/e2e-tests/adapters/gatsby-node.ts @@ -55,7 +55,7 @@ export const createPages: GatsbyNode["createPages"] = async ({ createPage({ path: applyTrailingSlashOption( - `/routes/remote-file-data-from-context/`, + `/routes/ssg/remote-file-data-from-context/`, TRAILING_SLASH ), component: path.resolve(`./src/templates/remote-file-from-context.jsx`), diff --git a/e2e-tests/adapters/src/pages/index.jsx b/e2e-tests/adapters/src/pages/index.jsx index 0032374b21b5f..e847fbd2adab7 100644 --- a/e2e-tests/adapters/src/pages/index.jsx +++ b/e2e-tests/adapters/src/pages/index.jsx @@ -7,12 +7,12 @@ import "./index.css" const routes = [ { text: "Static", - url: "/routes/static", + url: "/routes/ssg/static", id: "static-without-slash", }, { text: "Static (With Slash)", - url: "/routes/static/", + url: "/routes/ssg/static/", id: "static-with-slash", }, { @@ -41,11 +41,11 @@ const routes = [ }, { text: "RemoteFile (ImageCDN and FileCDN) (SSG, Page Query)", - url: "/routes/remote-file", + url: "/routes/ssg/remote-file", }, { text: "RemoteFile (ImageCDN and FileCDN) (SSG, Page Context)", - url: "/routes/remote-file-data-from-context", + url: "/routes/ssg/remote-file-data-from-context", }, { text: "RemoteFile (ImageCDN and FileCDN) (SSR, Page Query)", diff --git a/e2e-tests/adapters/src/pages/routes/remote-file.jsx b/e2e-tests/adapters/src/pages/routes/ssg/remote-file.jsx similarity index 98% rename from e2e-tests/adapters/src/pages/routes/remote-file.jsx rename to e2e-tests/adapters/src/pages/routes/ssg/remote-file.jsx index 8f2ceba8a1756..8401dd5e948a1 100644 --- a/e2e-tests/adapters/src/pages/routes/remote-file.jsx +++ b/e2e-tests/adapters/src/pages/routes/ssg/remote-file.jsx @@ -2,7 +2,7 @@ import { graphql } from "gatsby" import React from "react" import { GatsbyImage } from "gatsby-plugin-image" -import Layout from "../../components/layout" +import Layout from "../../../components/layout" const RemoteFile = ({ data }) => { return ( diff --git a/e2e-tests/adapters/src/pages/routes/static.jsx b/e2e-tests/adapters/src/pages/routes/ssg/static.jsx similarity index 61% rename from e2e-tests/adapters/src/pages/routes/static.jsx rename to e2e-tests/adapters/src/pages/routes/ssg/static.jsx index 709b5b24559f1..e8d43fe501717 100644 --- a/e2e-tests/adapters/src/pages/routes/static.jsx +++ b/e2e-tests/adapters/src/pages/routes/ssg/static.jsx @@ -1,5 +1,5 @@ import * as React from "react" -import Layout from "../../components/layout" +import Layout from "../../../components/layout" const StaticPage = () => { return ( @@ -11,4 +11,4 @@ const StaticPage = () => { export default StaticPage -export const Head = () => Static \ No newline at end of file +export const Head = () => Static