-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…38662) * test(adapters-e2e): deploy to platform instead of ntl serve * test: clear browser cache for interception tests * test: delete deploy after the test * test: how about not caching things to begin with? * chore: update comment, only disable caching for webpack asset, restore previous assertions (cherry picked from commit 5bc0992) Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
- Loading branch information
Showing
4 changed files
with
85 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,49 @@ | ||
import { title } from "../../constants" | ||
|
||
describe('Basics', () => { | ||
describe("Basics", () => { | ||
beforeEach(() => { | ||
cy.intercept("/gatsby-icon.png").as("static-folder-image") | ||
cy.intercept("/static/astro-**.png").as("img-import") | ||
cy.intercept("/static/astro-**.png", req => { | ||
req.on("before:response", res => { | ||
// this generally should be permamently cached, but that cause problems with intercepting | ||
// see https://docs.cypress.io/api/commands/intercept#cyintercept-and-request-caching | ||
// so we disable caching for this response | ||
// tests for cache-control headers should be done elsewhere | ||
|
||
cy.visit('/').waitForRouteChange() | ||
res.headers["cache-control"] = "no-store" | ||
}) | ||
}).as("img-import") | ||
|
||
cy.visit("/").waitForRouteChange() | ||
}) | ||
|
||
it('should display index page', () => { | ||
cy.get('h1').should('have.text', title) | ||
cy.title().should('eq', 'Adapters E2E') | ||
it("should display index page", () => { | ||
cy.get("h1").should("have.text", title) | ||
cy.title().should("eq", "Adapters E2E") | ||
}) | ||
// If this test fails, run "gatsby build" and retry | ||
it('should serve assets from "static" folder', () => { | ||
cy.wait("@static-folder-image").should(req => { | ||
expect(req.response.statusCode).to.be.gte(200).and.lt(400) | ||
}) | ||
|
||
cy.get('[alt="Gatsby Monogram Logo"]').should('be.visible') | ||
cy.get('[alt="Gatsby Monogram Logo"]').should("be.visible") | ||
}) | ||
it('should serve assets imported through webpack', () => { | ||
it("should serve assets imported through webpack", () => { | ||
cy.wait("@img-import").should(req => { | ||
expect(req.response.statusCode).to.be.gte(200).and.lt(400) | ||
}) | ||
|
||
cy.get('[alt="Gatsby Astronaut"]').should('be.visible') | ||
cy.get('[alt="Gatsby Astronaut"]').should("be.visible") | ||
}) | ||
it(`should show custom 404 page on invalid URL`, () => { | ||
cy.visit(`/non-existent-page`, { | ||
failOnStatusCode: false, | ||
}) | ||
|
||
cy.get('h1').should('have.text', 'Page not found') | ||
cy.get("h1").should("have.text", "Page not found") | ||
}) | ||
it('should apply CSS', () => { | ||
cy.get(`h1`).should( | ||
`have.css`, | ||
`color`, | ||
`rgb(21, 21, 22)` | ||
) | ||
it("should apply CSS", () => { | ||
cy.get(`h1`).should(`have.css`, `color`, `rgb(21, 21, 22)`) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// @ts-check | ||
|
||
import { execa } from "execa" | ||
|
||
process.env.NETLIFY_SITE_ID = process.env.E2E_ADAPTERS_NETLIFY_SITE_ID | ||
process.env.ADAPTER = "netlify" | ||
|
||
const deployTitle = process.env.CIRCLE_SHA1 || "N/A" | ||
|
||
const npmScriptToRun = process.argv[2] || "test:netlify" | ||
|
||
const deployResults = await execa( | ||
"ntl", | ||
["deploy", "--build", "--json", "--message", deployTitle], | ||
{ | ||
reject: false, | ||
} | ||
) | ||
|
||
if (deployResults.exitCode !== 0) { | ||
if (deployResults.stdout) { | ||
console.log(deployResults.stdout) | ||
} | ||
if (deployResults.stderr) { | ||
console.error(deployResults.stderr) | ||
} | ||
|
||
process.exit(deployResults.exitCode) | ||
} | ||
|
||
const deployInfo = JSON.parse(deployResults.stdout) | ||
|
||
process.env.DEPLOY_URL = deployInfo.deploy_url | ||
|
||
try { | ||
await execa(`npm`, [`run`, npmScriptToRun], { stdio: `inherit` }) | ||
} finally { | ||
if (!process.env.GATSBY_TEST_SKIP_CLEANUP) { | ||
console.log(`Deleting project with deploy_id ${deployInfo.deploy_id}`) | ||
|
||
const deleteResponse = await execa("ntl", [ | ||
"api", | ||
"deleteDeploy", | ||
"--data", | ||
`{ "deploy_id": "${deployInfo.deploy_id}" }`, | ||
]) | ||
|
||
if (deleteResponse.exitCode !== 0) { | ||
throw new Error( | ||
`Failed to delete project ${deleteResponse.stdout} ${deleteResponse.stderr} (${deleteResponse.exitCode})` | ||
) | ||
} | ||
|
||
console.log( | ||
`Successfully deleted project with deploy_id ${deployInfo.deploy_id}` | ||
) | ||
} | ||
} |