forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(refresh-endpoint): Show restarting page while refreshing, auto p…
…age reload included, switch by env variable
- Loading branch information
Daniel Aparicio
committed
Jun 23, 2020
1 parent
de7ad40
commit a560f8a
Showing
9 changed files
with
98 additions
and
16 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
77 changes: 62 additions & 15 deletions
77
e2e-tests/development-refresh-endpoint/cypress/integration/functionality/refresh-endpoint.js
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,22 +1,69 @@ | ||
describe(`When the refresh endpoint is hit multiple times`, () => { | ||
|
||
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`) | ||
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>`) | ||
}) | ||
}) | ||
cy.request(`POST`, `/__refresh`).then(response => { | ||
expect(response.body).to.include(`already queued`) | ||
|
||
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>`) | ||
}) | ||
}) | ||
cy.request(`POST`, `/__refresh`, `otherBody`).then(response => { | ||
expect(response.body).to.include(`queued`) | ||
}) | ||
|
||
describe(`and it was not already refreshing`, () => { | ||
it(`should return empty body`, () => { | ||
cy.request(`POST`, `/__refresh`).then(response => { | ||
expect(response.body).to.be.equal(``) | ||
}) | ||
}) | ||
cy.request(`POST`, `/__refresh`, `otherBody`).then(response => { | ||
expect(response.body).to.include(`already queued`) | ||
}) | ||
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, | ||
} | ||
) | ||
} |
1 change: 1 addition & 0 deletions
1
e2e-tests/development-refresh-endpoint/cypress/support/commands.js
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 +1,2 @@ | ||
import "@testing-library/cypress/add-commands" | ||
import "cypress-wait-until" |
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
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
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