Skip to content

Commit

Permalink
chore(e2e-dev-runtime): bump @testing-library/cypress and adjust curr…
Browse files Browse the repository at this point in the history
…ent data updates testing setup (#26500)

* chore(e2e-dev-runtime): bump @testing-library/cypress

* chore(e2e-dev-runtime): scope fake-data source plugin data refreshes

* force single cypress version

ref: testing-library/cypress-testing-library#98
  • Loading branch information
pieh committed Aug 21, 2020
1 parent 9456b98 commit ebf08ee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
Expand Up @@ -15,17 +15,17 @@ describe(`Gatsby Preview (Updating)`, () => {
it(`displays initial data`, () => {
cy.get(`li:eq(0) a`).click().waitForRouteChange()

cy.queryByText(`Hello World (1)`).should(`exist`)
cy.findByText(`Hello World (1)`).should(`exist`)

cy.queryByText(`0`).should(`exist`)
cy.findByText(`0`).should(`exist`)
})

it(`updates and hot-reloads changes to content`, () => {
cy.get(`li:eq(0) a`).click().waitForRouteChange()

update()

cy.queryByText(`1`).should(`exist`)
cy.findByText(`1`).should(`exist`)
})

it(`updates and hot-reloads new content`, () => {
Expand All @@ -45,13 +45,9 @@ describe(`Gatsby Preview (Updating)`, () => {
cy.get(`li`).its(`length`).should(`be`, 1)
})

/*
* TODO: get this test passing in CI
* https://github.com/testing-library/cypress-testing-library/issues/23
*/
it.skip(`can be triggered with webhook data`, () => {
it(`can be triggered with webhook data`, () => {
cy.exec(`npm run update:webhook`)

cy.queryByText(`Hello World from a Webhook (999)`).should(`exist`)
cy.findByText(`Hello World from a Webhook (999)`).should(`exist`)
})
})
Expand Up @@ -51,11 +51,11 @@ describe(`redirect`, () => {
// this is sanity check for this group
it(`make sure 404 is present`, () => {
cy.visit(`/______not_existing_page`).waitForRouteChange()
cy.queryByText("Preview custom 404 page").click()
cy.queryByText("A custom 404 page wasn't detected", {
cy.findByText("Preview custom 404 page").click()
cy.findByText("A custom 404 page wasn't detected", {
exact: false,
}).should(`not.exist`)
cy.queryByText(
cy.findByText(
"You just hit a route that does not exist... the sadness."
).should(`exist`)
})
Expand Down Expand Up @@ -83,11 +83,11 @@ describe(`redirect`, () => {

it(`make sure 404 is NOT present`, () => {
cy.visit(`/______not_existing_page`).waitForRouteChange()
cy.queryByText("Preview custom 404 page").click()
cy.queryByText("A custom 404 page wasn't detected", {
cy.findByText("Preview custom 404 page").click()
cy.findByText("A custom 404 page wasn't detected", {
exact: false,
}).should(`exist`)
cy.queryByText(
cy.findByText(
"You just hit a route that does not exist... the sadness.",
{ exact: false }
).should(`not.exist`)
Expand Down
9 changes: 6 additions & 3 deletions e2e-tests/development-runtime/package.json
Expand Up @@ -34,16 +34,16 @@
"test": "npm run start-server-and-test || (npm run reset && exit 1)",
"posttest": "npm run reset",
"reset": "node scripts/reset.js",
"reset:preview": "node plugins/gatsby-source-fake-data/reset.js && npm run update:preview",
"reset:preview": "curl -X POST http://localhost:8000/__refresh",
"update": "node scripts/update.js",
"update:webhook": "node scripts/webhook.js",
"update:preview": "curl -X POST http://localhost:8000/__refresh",
"update:preview": "curl -X POST -d '{ \"fake-data-update\": true }' -H \"Content-Type: application/json\" http://localhost:8000/__refresh",
"start-server-and-test": "start-server-and-test develop http://localhost:8000 cy:run",
"cy:open": "cypress open",
"cy:run": "(is-ci && cypress run --browser chrome --record) || cypress run --browser chrome"
},
"devDependencies": {
"@testing-library/cypress": "^4.0.4",
"@testing-library/cypress": "^6.0.0",
"cross-env": "^5.2.0",
"cypress": "3.4.1",
"fs-extra": "^7.0.1",
Expand All @@ -56,5 +56,8 @@
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby"
},
"resolutions": {
"cypress": "3.4.1"
}
}
Expand Up @@ -29,6 +29,9 @@ exports.sourceNodes = async function sourceNodes({
reporter.info(`Webhook data detected; creating nodes`)
webhookBody.items.forEach(node => createNode(api.getNode(node, helpers)))
} else {
if (!(webhookBody && webhookBody[`fake-data-update`])) {
await api.reset()
}
const [updated, deleted = []] = await api.sync(helpers)

updated.forEach(node => createNode(node))
Expand Down

0 comments on commit ebf08ee

Please sign in to comment.