Skip to content

Commit 126f69c

Browse files
committed
test: add ssg specific headers
1 parent 9584173 commit 126f69c

File tree

8 files changed

+71
-18
lines changed

8 files changed

+71
-18
lines changed

e2e-tests/adapters/cypress/e2e/headers.cy.ts

+20
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ describe("Headers", () => {
7676

7777
beforeEach(() => {
7878
cy.intercept(PATH_PREFIX + "/", WorkaroundCachedResponse).as("index")
79+
cy.intercept(
80+
PATH_PREFIX + "/routes/ssg/static",
81+
WorkaroundCachedResponse
82+
).as("ssg")
7983
cy.intercept(
8084
PATH_PREFIX + "/routes/ssr/static",
8185
WorkaroundCachedResponse
@@ -128,6 +132,22 @@ describe("Headers", () => {
128132
checkHeaders("@js")
129133
})
130134

135+
it("should contain correct headers for ssg page", () => {
136+
cy.visit("routes/ssg/static").waitForRouteChange()
137+
138+
checkHeaders("@ssg", {
139+
...defaultHeaders,
140+
"x-custom-header": "my custom header value",
141+
"x-dsg-header": "my custom header value",
142+
"cache-control": "public,max-age=0,must-revalidate",
143+
})
144+
145+
checkHeaders("@app-data")
146+
checkHeaders("@page-data")
147+
checkHeaders("@slice-data")
148+
checkHeaders("@static-query-result")
149+
})
150+
131151
it("should contain correct headers for ssr page", () => {
132152
cy.visit("routes/ssr/static").waitForRouteChange()
133153

e2e-tests/adapters/cypress/e2e/remote-file.cy.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ const PATH_PREFIX = Cypress.env(`PATH_PREFIX`) || ``
1818
const configs = [
1919
{
2020
title: `remote-file (SSG, Page Query)`,
21-
pagePath: `/routes/remote-file/`,
21+
pagePath: `/routes/ssg/remote-file/`,
2222
placeholders: true,
2323
},
2424
{
2525
title: `remote-file (SSG, Page Context)`,
26-
pagePath: `/routes/remote-file-data-from-context/`,
26+
pagePath: `/routes/ssg/remote-file-data-from-context/`,
2727
placeholders: true,
2828
},
2929
{
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { assertPageVisits } from "../utils/assert-page-visits"
22
import { applyTrailingSlashOption } from "../../utils"
33

4-
Cypress.on("uncaught:exception", (err) => {
4+
Cypress.on("uncaught:exception", err => {
55
if (err.message.includes("Minified React error")) {
66
return false
77
}
@@ -12,38 +12,62 @@ const TRAILING_SLASH = Cypress.env(`TRAILING_SLASH`) || `never`
1212
describe("trailingSlash", () => {
1313
describe(TRAILING_SLASH, () => {
1414
it("should work when using Gatsby Link (without slash)", () => {
15-
cy.visit('/').waitForRouteChange()
15+
cy.visit("/").waitForRouteChange()
1616

17-
cy.get(`[data-testid="static-without-slash"]`).click().waitForRouteChange().assertRoute(applyTrailingSlashOption(`/routes/static`, TRAILING_SLASH))
17+
cy.get(`[data-testid="static-without-slash"]`)
18+
.click()
19+
.waitForRouteChange()
20+
.assertRoute(
21+
applyTrailingSlashOption(`/routes/ssg/static`, TRAILING_SLASH)
22+
)
1823
})
1924
it("should work when using Gatsby Link (with slash)", () => {
20-
cy.visit('/').waitForRouteChange()
25+
cy.visit("/").waitForRouteChange()
2126

22-
cy.get(`[data-testid="static-with-slash"]`).click().waitForRouteChange().assertRoute(applyTrailingSlashOption(`/routes/static`, TRAILING_SLASH))
27+
cy.get(`[data-testid="static-with-slash"]`)
28+
.click()
29+
.waitForRouteChange()
30+
.assertRoute(
31+
applyTrailingSlashOption(`/routes/ssg/static`, TRAILING_SLASH)
32+
)
2333
})
2434
it("should work on direct visit (with other setting)", () => {
25-
const destination = applyTrailingSlashOption("/routes/static", TRAILING_SLASH)
26-
const inverse = TRAILING_SLASH === `always` ? "/routes/static" : "/routes/static/"
35+
const destination = applyTrailingSlashOption(
36+
"/routes/ssg/static",
37+
TRAILING_SLASH
38+
)
39+
const inverse =
40+
TRAILING_SLASH === `always`
41+
? "/routes/ssg/static"
42+
: "/routes/ssg/static/"
2743

2844
assertPageVisits([
2945
{
3046
path: destination,
3147
status: 200,
3248
},
33-
{ path: inverse, status: 301, destinationPath: destination }
49+
{ path: inverse, status: 301, destinationPath: destination },
3450
])
3551

36-
cy.visit(inverse).waitForRouteChange().assertRoute(applyTrailingSlashOption(`/routes/static`, TRAILING_SLASH))
52+
cy.visit(inverse)
53+
.waitForRouteChange()
54+
.assertRoute(
55+
applyTrailingSlashOption(`/routes/ssg/static`, TRAILING_SLASH)
56+
)
3757
})
3858
it("should work on direct visit (with current setting)", () => {
3959
assertPageVisits([
4060
{
41-
path: applyTrailingSlashOption("/routes/static", TRAILING_SLASH),
61+
path: applyTrailingSlashOption("/routes/ssg/static", TRAILING_SLASH),
4262
status: 200,
4363
},
4464
])
4565

46-
cy.visit(applyTrailingSlashOption("/routes/static", TRAILING_SLASH)).waitForRouteChange().assertRoute(applyTrailingSlashOption(`/routes/static`, TRAILING_SLASH))
66+
cy.visit(applyTrailingSlashOption("/routes/ssg/static", TRAILING_SLASH))
67+
.waitForRouteChange()
68+
.assertRoute(
69+
applyTrailingSlashOption(`/routes/ssg/static`, TRAILING_SLASH)
70+
)
4771
})
4872
})
4973
})

e2e-tests/adapters/gatsby-config.ts

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ const config: GatsbyConfig = {
7777
},
7878
],
7979
},
80+
{
81+
source: `routes/ssg/*`,
82+
headers: [
83+
{
84+
key: "x-ssg-header",
85+
value: "my custom header value",
86+
},
87+
],
88+
},
8089
],
8190
...configOverrides,
8291
}

e2e-tests/adapters/gatsby-node.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const createPages: GatsbyNode["createPages"] = async ({
5555

5656
createPage({
5757
path: applyTrailingSlashOption(
58-
`/routes/remote-file-data-from-context/`,
58+
`/routes/ssg/remote-file-data-from-context/`,
5959
TRAILING_SLASH
6060
),
6161
component: path.resolve(`./src/templates/remote-file-from-context.jsx`),

e2e-tests/adapters/src/pages/index.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import "./index.css"
77
const routes = [
88
{
99
text: "Static",
10-
url: "/routes/static",
10+
url: "/routes/ssg/static",
1111
id: "static-without-slash",
1212
},
1313
{
1414
text: "Static (With Slash)",
15-
url: "/routes/static/",
15+
url: "/routes/ssg/static/",
1616
id: "static-with-slash",
1717
},
1818
{
@@ -41,11 +41,11 @@ const routes = [
4141
},
4242
{
4343
text: "RemoteFile (ImageCDN and FileCDN) (SSG, Page Query)",
44-
url: "/routes/remote-file",
44+
url: "/routes/ssg/remote-file",
4545
},
4646
{
4747
text: "RemoteFile (ImageCDN and FileCDN) (SSG, Page Context)",
48-
url: "/routes/remote-file-data-from-context",
48+
url: "/routes/ssg/remote-file-data-from-context",
4949
},
5050
{
5151
text: "RemoteFile (ImageCDN and FileCDN) (SSR, Page Query)",

0 commit comments

Comments
 (0)