-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(adapters-e2e): deploy to platform instead of ntl serve #38643
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9e15c4e
test(adapters-e2e): deploy to platform instead of ntl serve
pieh de27dc7
test: clear browser cache for interception tests
pieh f67cfbc
test: delete deploy after the test
pieh 9f15265
test: how about not caching things to begin with?
pieh 7cef064
chore: update comment, only disable caching for webpack asset, restor…
pieh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}` | ||
) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is only real change in test - rest of it is just autoformatting (yikes). Apperently with
ntl serve
permanent caching wasn't really happing and test setup is kind of meh when that happens ( https://docs.cypress.io/api/commands/intercept#cyintercept-and-request-caching ), so this is just workaround to get test working (and probably note to actually add proper caching behavior tests in the future PR)