forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loader use page data (gatsbyjs#13409)
* page-data loader working for production-app * get new loader.getPage stuff working with gatsby develop * fix static-entry.js test * remove loadPageDataSync (will be in next PR) * use array of matchPaths * Deprecate various loader methods * remove console.log * document why fetchPageData needs to check that response is JSON * in offline, use prefetchedResources.push(...resourceUrls) * root.js remove else block * loader.js make* -> create* * loader drop else block * pass correct path/resourceUrls to onPostPrefetch * s/err => null/() => null/ * Extract loadComponent from loadPage * remove pageData from window object * update jest snapshots for static-entry (to use window.pagePath) * add loadPageOr404 * preload 404 page in background * normalize page paths * comment out resource-loading-resilience.js (will fix later)
- Loading branch information
Showing
22 changed files
with
505 additions
and
700 deletions.
There are no files selected for viewing
210 changes: 106 additions & 104 deletions
210
e2e-tests/production-runtime/cypress/integration/resource-loading-resilience.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,116 +1,118 @@ | ||
Cypress.on(`uncaught:exception`, (err, runnable) => { | ||
// returning false here prevents Cypress from | ||
// failing the test | ||
console.log(err) | ||
return false | ||
}) | ||
// TODO need to update to work with page-data.json | ||
|
||
const waitForAPIOptions = { | ||
timeout: 3000, | ||
} | ||
// Cypress.on(`uncaught:exception`, (err, runnable) => { | ||
// // returning false here prevents Cypress from | ||
// // failing the test | ||
// console.log(err) | ||
// return false | ||
// }) | ||
|
||
const runTests = () => { | ||
it(`Loads index`, () => { | ||
cy.visit(`/`).waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) | ||
cy.getTestElement(`dom-marker`).contains(`index`) | ||
}) | ||
// const waitForAPIOptions = { | ||
// timeout: 3000, | ||
// } | ||
|
||
it(`Navigates to second page`, () => { | ||
cy.getTestElement(`page2`).click() | ||
cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) | ||
.location(`pathname`) | ||
.should(`equal`, `/page-2/`) | ||
cy.getTestElement(`dom-marker`).contains(`page-2`) | ||
}) | ||
// const runTests = () => { | ||
// it(`Loads index`, () => { | ||
// cy.visit(`/`).waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) | ||
// cy.getTestElement(`dom-marker`).contains(`index`) | ||
// }) | ||
|
||
it(`Navigates to 404 page`, () => { | ||
cy.getTestElement(`404`).click() | ||
cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) | ||
.location(`pathname`) | ||
.should(`equal`, `/page-3/`) | ||
cy.getTestElement(`dom-marker`).contains(`404`) | ||
}) | ||
// it(`Navigates to second page`, () => { | ||
// cy.getTestElement(`page2`).click() | ||
// cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) | ||
// .location(`pathname`) | ||
// .should(`equal`, `/page-2/`) | ||
// cy.getTestElement(`dom-marker`).contains(`page-2`) | ||
// }) | ||
|
||
it(`Loads 404`, () => { | ||
cy.visit(`/page-3/`, { | ||
failOnStatusCode: false, | ||
}).waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) | ||
cy.getTestElement(`dom-marker`).contains(`404`) | ||
}) | ||
// it(`Navigates to 404 page`, () => { | ||
// cy.getTestElement(`404`).click() | ||
// cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) | ||
// .location(`pathname`) | ||
// .should(`equal`, `/page-3/`) | ||
// cy.getTestElement(`dom-marker`).contains(`404`) | ||
// }) | ||
|
||
it(`Can navigate from 404 to index`, () => { | ||
cy.getTestElement(`index`).click() | ||
cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) | ||
.location(`pathname`) | ||
.should(`equal`, `/`) | ||
cy.getTestElement(`dom-marker`).contains(`index`) | ||
}) | ||
} | ||
// it(`Loads 404`, () => { | ||
// cy.visit(`/page-3/`, { | ||
// failOnStatusCode: false, | ||
// }).waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) | ||
// cy.getTestElement(`dom-marker`).contains(`404`) | ||
// }) | ||
|
||
describe(`Every resources available`, () => { | ||
it(`Restore resources`, () => { | ||
cy.exec(`npm run chunks -- restore`) | ||
}) | ||
runTests() | ||
}) | ||
// it(`Can navigate from 404 to index`, () => { | ||
// cy.getTestElement(`index`).click() | ||
// cy.waitForAPIorTimeout(`onRouteUpdate`, waitForAPIOptions) | ||
// .location(`pathname`) | ||
// .should(`equal`, `/`) | ||
// cy.getTestElement(`dom-marker`).contains(`index`) | ||
// }) | ||
// } | ||
|
||
describe(`Missing top level resources`, () => { | ||
describe(`Deleted pages manifest`, () => { | ||
it(`Block resources`, () => { | ||
cy.exec(`npm run chunks -- restore`) | ||
cy.exec(`npm run chunks -- block pages-manifest`) | ||
}) | ||
runTests() | ||
}) | ||
// describe(`Every resources available`, () => { | ||
// it(`Restore resources`, () => { | ||
// cy.exec(`npm run chunks -- restore`) | ||
// }) | ||
// runTests() | ||
// }) | ||
|
||
describe(`Deleted app chunk assets`, () => { | ||
it(`Block resources`, () => { | ||
cy.exec(`npm run chunks -- restore`) | ||
cy.exec(`npm run chunks -- block app`) | ||
}) | ||
runTests() | ||
}) | ||
}) | ||
// describe(`Missing top level resources`, () => { | ||
// describe(`Deleted pages manifest`, () => { | ||
// it(`Block resources`, () => { | ||
// cy.exec(`npm run chunks -- restore`) | ||
// cy.exec(`npm run chunks -- block pages-manifest`) | ||
// }) | ||
// runTests() | ||
// }) | ||
|
||
const runSuiteForPage = (label, path) => { | ||
describe(`Missing "${label}" resources`, () => { | ||
describe(`Missing "${label}" page query results`, () => { | ||
it(`Block resources`, () => { | ||
cy.exec(`npm run chunks -- restore`) | ||
cy.exec(`npm run chunks -- block-page ${path} query-result`) | ||
}) | ||
runTests() | ||
}) | ||
describe(`Missing "${label}" page page-template asset`, () => { | ||
it(`Block resources`, () => { | ||
cy.exec(`npm run chunks -- restore`) | ||
cy.exec(`npm run chunks -- block-page ${path} page-template`) | ||
}) | ||
runTests() | ||
}) | ||
describe(`Missing "${label}" page extra assets`, () => { | ||
it(`Block resources`, () => { | ||
cy.exec(`npm run chunks -- restore`) | ||
cy.exec(`npm run chunks -- block-page ${path} extra`) | ||
}) | ||
runTests() | ||
}) | ||
describe(`Missing all "${label}" page assets`, () => { | ||
it(`Block resources`, () => { | ||
cy.exec(`npm run chunks -- restore`) | ||
cy.exec(`npm run chunks -- block-page ${path} all`) | ||
}) | ||
runTests() | ||
}) | ||
}) | ||
} | ||
// describe(`Deleted app chunk assets`, () => { | ||
// it(`Block resources`, () => { | ||
// cy.exec(`npm run chunks -- restore`) | ||
// cy.exec(`npm run chunks -- block app`) | ||
// }) | ||
// runTests() | ||
// }) | ||
// }) | ||
|
||
runSuiteForPage(`Index`, `/`) | ||
runSuiteForPage(`Page-2`, `/page-2/`) | ||
runSuiteForPage(`404`, `/404.html`) | ||
// const runSuiteForPage = (label, path) => { | ||
// describe(`Missing "${label}" resources`, () => { | ||
// describe(`Missing "${label}" page query results`, () => { | ||
// it(`Block resources`, () => { | ||
// cy.exec(`npm run chunks -- restore`) | ||
// cy.exec(`npm run chunks -- block-page ${path} query-result`) | ||
// }) | ||
// runTests() | ||
// }) | ||
// describe(`Missing "${label}" page page-template asset`, () => { | ||
// it(`Block resources`, () => { | ||
// cy.exec(`npm run chunks -- restore`) | ||
// cy.exec(`npm run chunks -- block-page ${path} page-template`) | ||
// }) | ||
// runTests() | ||
// }) | ||
// describe(`Missing "${label}" page extra assets`, () => { | ||
// it(`Block resources`, () => { | ||
// cy.exec(`npm run chunks -- restore`) | ||
// cy.exec(`npm run chunks -- block-page ${path} extra`) | ||
// }) | ||
// runTests() | ||
// }) | ||
// describe(`Missing all "${label}" page assets`, () => { | ||
// it(`Block resources`, () => { | ||
// cy.exec(`npm run chunks -- restore`) | ||
// cy.exec(`npm run chunks -- block-page ${path} all`) | ||
// }) | ||
// runTests() | ||
// }) | ||
// }) | ||
// } | ||
|
||
describe(`Cleanup`, () => { | ||
it(`Restore resources`, () => { | ||
cy.exec(`npm run chunks -- restore`) | ||
}) | ||
}) | ||
// runSuiteForPage(`Index`, `/`) | ||
// runSuiteForPage(`Page-2`, `/page-2/`) | ||
// runSuiteForPage(`404`, `/404.html`) | ||
|
||
// describe(`Cleanup`, () => { | ||
// it(`Restore resources`, () => { | ||
// cy.exec(`npm run chunks -- restore`) | ||
// }) | ||
// }) |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.