-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gatsby): refresh browser when receiving update and runtime errored (
#27467) * fix(gatsby): refresh browser when receiving update and runtime errored * add query validation error test * add test cases for changing content causing and fixing runtime errors * adjust test names
- Loading branch information
Showing
19 changed files
with
449 additions
and
5 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
e2e-tests/development-runtime/content/error-recovery/page-query.json
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"selector": "page-query", | ||
"hasError": false | ||
} |
4 changes: 4 additions & 0 deletions
4
e2e-tests/development-runtime/content/error-recovery/static-query.json
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"selector": "static-query", | ||
"hasError": false | ||
} |
41 changes: 41 additions & 0 deletions
41
...sts/development-runtime/cypress/integration/hot-reloading/error-handling/compile-error.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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
before(() => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/compile-error.js --restore` | ||
) | ||
}) | ||
|
||
after(() => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/compile-error.js --restore` | ||
) | ||
}) | ||
|
||
const errorPlaceholder = `// compile-error` | ||
const errorReplacement = `a b` | ||
|
||
describe(`testing error overlay and ability to automatically recover from webpack compile errors`, () => { | ||
it(`displays content initially (no errors yet)`, () => { | ||
cy.visit(`/error-handling/compile-error/`).waitForRouteChange() | ||
cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Working`) | ||
}) | ||
|
||
it(`displays error with overlay on compilation errors`, () => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/compile-error.js --replacements "${errorPlaceholder}:${errorReplacement}" --exact` | ||
) | ||
|
||
cy.getOverlayIframe().contains(`Failed to compile`) | ||
cy.getOverlayIframe().contains(`Parsing error: Unexpected token`) | ||
cy.screenshot() | ||
}) | ||
|
||
it(`can recover without need to refresh manually`, () => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/compile-error.js --replacements "Working:Updated" --replacements "${errorReplacement}:${errorPlaceholder}" --exact` | ||
) | ||
|
||
cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Updated`) | ||
cy.assertNoOverlayIframe() | ||
cy.screenshot() | ||
}) | ||
}) |
69 changes: 69 additions & 0 deletions
69
...ntime/cypress/integration/hot-reloading/error-handling/page-query-result-runtime-error.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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Cypress.on("uncaught:exception", (err, runnable) => { | ||
// returning false here prevents Cypress from | ||
// failing the test | ||
return false | ||
}) | ||
|
||
before(() => { | ||
cy.exec( | ||
`npm run update -- --file content/error-recovery/page-query.json --restore` | ||
) | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/page-query-result-runtime-error.js --restore` | ||
) | ||
}) | ||
|
||
after(() => { | ||
cy.exec( | ||
`npm run update -- --file content/error-recovery/page-query.json --restore` | ||
) | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/page-query-result-runtime-error.js --restore` | ||
) | ||
}) | ||
|
||
const errorPlaceholder = `false` | ||
const errorReplacement = `true` | ||
|
||
describe(`testing error overlay and ability to automatically recover runtime errors cause by content changes (page queries variant)`, () => { | ||
it(`displays content initially (no errors yet)`, () => { | ||
cy.visit( | ||
`/error-handling/page-query-result-runtime-error/` | ||
).waitForRouteChange() | ||
cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Working`) | ||
cy.getTestElement(`results`) | ||
.invoke(`text`) | ||
.should(`contain`, `"hasError": false`) | ||
}) | ||
|
||
it(`displays error with overlay on runtime errors`, () => { | ||
cy.exec( | ||
`npm run update -- --file content/error-recovery/page-query.json --replacements "${errorPlaceholder}:${errorReplacement}" --exact` | ||
) | ||
|
||
// that's the exact error we throw and we expect to see that | ||
cy.getOverlayIframe().contains(`Page query results caused runtime error`) | ||
// contains details | ||
cy.getOverlayIframe().contains( | ||
`src/pages/error-handling/page-query-result-runtime-error.js` | ||
) | ||
cy.screenshot() | ||
}) | ||
|
||
it(`can recover without need to refresh manually`, () => { | ||
cy.exec( | ||
`npm run update -- --file content/error-recovery/page-query.json --replacements "${errorReplacement}:${errorPlaceholder}" --exact` | ||
) | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/page-query-result-runtime-error.js --replacements "Working:Updated" --exact` | ||
) | ||
|
||
cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Updated`) | ||
cy.getTestElement(`results`) | ||
.invoke(`text`) | ||
.should(`contain`, `"hasError": false`) | ||
|
||
cy.assertNoOverlayIframe() | ||
cy.screenshot() | ||
}) | ||
}) |
45 changes: 45 additions & 0 deletions
45
...opment-runtime/cypress/integration/hot-reloading/error-handling/query-validation-error.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
before(() => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/query-validation-error.js --restore` | ||
) | ||
}) | ||
|
||
after(() => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/query-validation-error.js --restore` | ||
) | ||
}) | ||
|
||
const errorPlaceholder = `# query-validation-error` | ||
const errorReplacement = `fieldThatDoesNotExistOnSiteMapType` | ||
|
||
describe(`testing error overlay and ability to automatically recover from query extraction validation errors`, () => { | ||
it(`displays content initially (no errors yet)`, () => { | ||
cy.visit(`/error-handling/query-validation-error/`).waitForRouteChange() | ||
cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Working`) | ||
}) | ||
|
||
it(`displays error with overlay on compilation errors`, () => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/query-validation-error.js --replacements "${errorPlaceholder}:${errorReplacement}" --exact` | ||
) | ||
|
||
cy.getOverlayIframe().contains(`Failed to compile`) | ||
cy.getOverlayIframe().contains(`There was an error in your GraphQL query`) | ||
// make sure we mark location | ||
cy.getOverlayIframe().contains( | ||
`src/pages/error-handling/query-validation-error.js` | ||
) | ||
cy.screenshot() | ||
}) | ||
|
||
it(`can recover without need to refresh manually`, () => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/query-validation-error.js --replacements "Working:Updated" --replacements "${errorReplacement}:${errorPlaceholder}" --exact` | ||
) | ||
|
||
cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Updated`) | ||
cy.assertNoOverlayIframe() | ||
cy.screenshot() | ||
}) | ||
}) |
48 changes: 48 additions & 0 deletions
48
...sts/development-runtime/cypress/integration/hot-reloading/error-handling/runtime-error.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Cypress.on("uncaught:exception", (err, runnable) => { | ||
// returning false here prevents Cypress from | ||
// failing the test | ||
return false | ||
}) | ||
|
||
before(() => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/runtime-error.js --restore` | ||
) | ||
}) | ||
|
||
after(() => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/runtime-error.js --restore` | ||
) | ||
}) | ||
|
||
const errorPlaceholder = `// runtime-error` | ||
const errorReplacement = `window.a.b.c.d.e.f.g()` | ||
|
||
describe(`testing error overlay and ability to automatically recover from runtime errors`, () => { | ||
it(`displays content initially (no errors yet)`, () => { | ||
cy.visit(`/error-handling/runtime-error/`).waitForRouteChange() | ||
cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Working`) | ||
}) | ||
|
||
it(`displays error with overlay on runtime errors`, () => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/runtime-error.js --replacements "${errorPlaceholder}:${errorReplacement}" --exact` | ||
) | ||
|
||
cy.getOverlayIframe().contains(`Cannot read property`) | ||
// contains details | ||
cy.getOverlayIframe().contains(`src/pages/error-handling/runtime-error.js`) | ||
cy.screenshot() | ||
}) | ||
|
||
it(`can recover without need to refresh manually`, () => { | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/runtime-error.js --replacements "Working:Updated" --replacements "${errorReplacement}:${errorPlaceholder}" --exact` | ||
) | ||
|
||
cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Updated`) | ||
cy.assertNoOverlayIframe() | ||
cy.screenshot() | ||
}) | ||
}) |
69 changes: 69 additions & 0 deletions
69
...ime/cypress/integration/hot-reloading/error-handling/static-query-result-runtime-error.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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Cypress.on("uncaught:exception", (err, runnable) => { | ||
// returning false here prevents Cypress from | ||
// failing the test | ||
return false | ||
}) | ||
|
||
before(() => { | ||
cy.exec( | ||
`npm run update -- --file content/error-recovery/static-query.json --restore` | ||
) | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/static-query-result-runtime-error.js --restore` | ||
) | ||
}) | ||
|
||
after(() => { | ||
cy.exec( | ||
`npm run update -- --file content/error-recovery/static-query.json --restore` | ||
) | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/static-query-result-runtime-error.js --restore` | ||
) | ||
}) | ||
|
||
const errorPlaceholder = `false` | ||
const errorReplacement = `true` | ||
|
||
describe(`testing error overlay and ability to automatically recover from runtime errors (static queries variant)`, () => { | ||
it(`displays content initially (no errors yet)`, () => { | ||
cy.visit( | ||
`/error-handling/static-query-result-runtime-error/` | ||
).waitForRouteChange() | ||
cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Working`) | ||
cy.getTestElement(`results`) | ||
.invoke(`text`) | ||
.should(`contain`, `"hasError": false`) | ||
}) | ||
|
||
it(`displays error with overlay on runtime errors`, () => { | ||
cy.exec( | ||
`npm run update -- --file content/error-recovery/static-query.json --replacements "${errorPlaceholder}:${errorReplacement}" --exact` | ||
) | ||
|
||
// that's the exact error we throw and we expect to see that | ||
cy.getOverlayIframe().contains(`Static query results caused runtime error`) | ||
// contains details | ||
cy.getOverlayIframe().contains( | ||
`src/pages/error-handling/static-query-result-runtime-error.js` | ||
) | ||
cy.screenshot() | ||
}) | ||
|
||
it(`can recover without need to refresh manually`, () => { | ||
cy.exec( | ||
`npm run update -- --file content/error-recovery/static-query.json --replacements "${errorReplacement}:${errorPlaceholder}" --exact` | ||
) | ||
cy.exec( | ||
`npm run update -- --file src/pages/error-handling/static-query-result-runtime-error.js --replacements "Working:Updated" --exact` | ||
) | ||
|
||
cy.getTestElement(`hot`).invoke(`text`).should(`contain`, `Updated`) | ||
cy.getTestElement(`results`) | ||
.invoke(`text`) | ||
.should(`contain`, `"hasError": false`) | ||
|
||
cy.assertNoOverlayIframe() | ||
cy.screenshot() | ||
}) | ||
}) |
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
8 changes: 8 additions & 0 deletions
8
e2e-tests/development-runtime/src/pages/error-handling/compile-error.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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import React from "react" | ||
|
||
function CompileError() { | ||
// compile-error | ||
return <p data-testid="hot">Working</p> | ||
} | ||
|
||
export default CompileError |
Oops, something went wrong.