Skip to content
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) #38662

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions e2e-tests/adapters/cypress/configs/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { defineConfig } from "cypress"

export default defineConfig({
e2e: {
baseUrl: `http://localhost:8888`,
baseUrl: process.env.DEPLOY_URL || `http://localhost:8888`,
// Netlify doesn't handle trailing slash behaviors really, so no use in testing it
excludeSpecPattern: [`cypress/e2e/trailing-slash.cy.ts`,],
excludeSpecPattern: [`cypress/e2e/trailing-slash.cy.ts`],
projectId: `4enh4m`,
videoUploadOnPasses: false,
experimentalRunAllSpecs: true,
retries: 2,
},
})
})
39 changes: 22 additions & 17 deletions e2e-tests/adapters/cypress/e2e/basics.cy.ts
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)`)
})
})
})
4 changes: 2 additions & 2 deletions e2e-tests/adapters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"test:template": "cross-env-shell CYPRESS_GROUP_NAME=$ADAPTER TRAILING_SLASH=$TRAILING_SLASH node ../../scripts/cypress-run-with-conditional-record-flag.js --browser chrome --e2e --config-file \"cypress/configs/$ADAPTER.ts\" --env TRAILING_SLASH=$TRAILING_SLASH",
"test:template:debug": "cross-env-shell CYPRESS_GROUP_NAME=$ADAPTER TRAILING_SLASH=$TRAILING_SLASH npm run cy:open -- --config-file \"cypress/configs/$ADAPTER.ts\" --env TRAILING_SLASH=$TRAILING_SLASH",
"test:debug": "npm-run-all -s build:debug ssat:debug",
"test:netlify": "start-server-and-test 'cross-env TRAILING_SLASH=always BROWSER=none ntl serve --port 8888' http://localhost:8888 'cross-env ADAPTER=netlify TRAILING_SLASH=always npm run test:template'",
"test:netlify:debug": "start-server-and-test 'cross-env TRAILING_SLASH=always BROWSER=none ntl serve --port 8888' http://localhost:8888 'cross-env ADAPTER=netlify TRAILING_SLASH=always npm run test:template:debug'",
"test:netlify": "cross-env TRAILING_SLASH=always node scripts/deploy-and-run/netlify.mjs test:template",
"test:netlify:debug": "cross-env TRAILING_SLASH=always node scripts/deploy-and-run/netlify.mjs test:template:debug",
"test": "npm-run-all -c -s test:netlify"
},
"dependencies": {
Expand Down
58 changes: 58 additions & 0 deletions e2e-tests/adapters/scripts/deploy-and-run/netlify.mjs
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}`
)
}
}