Skip to content

Commit

Permalink
feat(refresh-endpoint): Add e2e integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Aparicio committed Jun 9, 2020
1 parent f812e49 commit bb4370c
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
describe(`When the refresh endpoint is hit`, () => {
afterEach(() => {
waitUntilRefreshFinishes()
})

describe(`and accessing any page while refreshing`, () => {
it(`the page shown should be restarting page for 404 page`, () => {
cy.request(`/non-existing`).then(response => {
expect(response.body).not.to.include(`<title>Restarting...</title>`)
})
cy.request(`POST`, `/__refresh`)
cy.request(`/non-existing`).then(response => {
expect(response.body).to.include(`<title>Restarting...</title>`)
})
})

it(`the page shown should be restarting page for existing pages`, () => {
cy.request(`/page-2/`).then(response => {
expect(response.body).not.to.include(`<title>Restarting...</title>`)
})
cy.request(`POST`, `/__refresh`)
cy.request(`/page-2/`).then(response => {
expect(response.body).to.include(`<title>Restarting...</title>`)
})
})
})

describe(`and it was not already refreshing`, () => {
it(`should return empty body`, () => {
cy.request(`POST`, `/__refresh`).then(response => {
expect(response.body).to.be.equal(``)
})
})
})
describe(`and it was already refreshing`, () => {
it(`should put new requests with unique body in a queue`, () => {
cy.request(`POST`, `/__refresh`).then(response => {
expect(response.body).to.be.equal(``)
})
cy.request(`POST`, `/__refresh`).then(response => {
expect(response.body).to.include(`queued`)
})
cy.request(`POST`, `/__refresh`).then(response => {
expect(response.body).to.include(`already queued`)
})
cy.request(`POST`, `/__refresh`, `otherBody`).then(response => {
expect(response.body).to.include(`queued`)
})
cy.request(`POST`, `/__refresh`, `otherBody`).then(response => {
expect(response.body).to.include(`already queued`)
})
})
})
})

function waitUntilRefreshFinishes() {
cy.waitUntil(
() =>
cy
.request(`/`)
.then(
response => !response.body.includes(`<title>Restarting...</title>`)
),
{
timeout: 60000,
interval: 2000,
}
)

cy.request(`/`).then(response => {
expect(response.body).not.to.include(`<title>Restarting...</title>`)
})
}
1 change: 1 addition & 0 deletions e2e-tests/development-runtime/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "@testing-library/cypress/add-commands"
import "cypress-wait-until"

Cypress.Commands.add(`lifecycleCallCount`, action =>
cy
Expand Down
1 change: 1 addition & 0 deletions e2e-tests/development-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@testing-library/cypress": "^4.0.4",
"cross-env": "^5.2.0",
"cypress": "3.4.1",
"cypress-wait-until": "1.7.1",
"fs-extra": "^7.0.1",
"gatsby-cypress": "^0.1.7",
"is-ci": "^2.0.0",
Expand Down

0 comments on commit bb4370c

Please sign in to comment.