Skip to content

Commit

Permalink
chore(e2e-tests): Wait for route change on back/forward (#37033)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyhopp committed Nov 14, 2022
1 parent 4842417 commit 1cfd9b8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
Expand Up @@ -135,8 +135,8 @@ for (const { descriptor, inlineScriptType } of typesOfInlineScripts) {
cy.visit(page.navigation).waitForRouteChange()
cy.get(`a[href="${page.target}"][id=anchor-link]`).click()
cy.get(`table[id=script-mark-records] tbody`) // Make sure history has time to change
cy.go(`back`)
cy.go(`forward`)
cy.go(`back`).waitForRouteChange()
cy.go(`forward`).waitForRouteChange()

cy.get(`table[id=script-mark-records] tbody`)
.children()
Expand Down Expand Up @@ -174,8 +174,8 @@ for (const { descriptor, inlineScriptType } of typesOfInlineScripts) {
it(`should load only once if the page is revisited via browser back/forward buttons after Gatsby link navigation`, () => {
cy.visit(page.navigation).waitForRouteChange()
cy.get(`a[href="${page.target}"][id=gatsby-link]`).click()
cy.go(`back`)
cy.go(`forward`)
cy.go(`back`).waitForRouteChange()
cy.go(`forward`).waitForRouteChange()

cy.get(`table[id=script-mark-records] tbody`)
.children()
Expand Down
Expand Up @@ -119,8 +119,8 @@ describe(`scripts with sources`, () => {
it(`should load only once if the page is revisited via browser back/forward buttons after anchor link navigation`, () => {
cy.visit(page.navigation).waitForRouteChange()
cy.get(`a[href="${page.target}"][id=anchor-link]`).click()
cy.go(`back`)
cy.go(`forward`)
cy.go(`back`).waitForRouteChange()
cy.go(`forward`).waitForRouteChange()

cy.get(`table[id=script-resource-records] tbody`)
.children()
Expand Down Expand Up @@ -150,8 +150,8 @@ describe(`scripts with sources`, () => {
it(`should load only once if the page is revisited via browser back/forward buttons after Gatsby link navigation`, () => {
cy.visit(page.navigation).waitForRouteChange()
cy.get(`a[href="${page.target}"][id=gatsby-link]`).click()
cy.go(`back`)
cy.go(`forward`)
cy.go(`back`).waitForRouteChange()
cy.go(`forward`).waitForRouteChange()

cy.get(`table[id=script-resource-records] tbody`)
.children()
Expand Down
Expand Up @@ -17,8 +17,13 @@ const typesOfInlineScripts = [
},
]

Cypress.on('uncaught:exception', (err) => {
if ((err.message.includes('Minified React error #418') || err.message.includes('Minified React error #423') || err.message.includes('Minified React error #425')) && Cypress.env(`TEST_PLUGIN_OFFLINE`)) {
Cypress.on(`uncaught:exception`, err => {
if (
(err.message.includes(`Minified React error #418`) ||
err.message.includes(`Minified React error #423`) ||
err.message.includes(`Minified React error #425`)) &&
Cypress.env(`TEST_PLUGIN_OFFLINE`)
) {
return false
}
})
Expand Down Expand Up @@ -141,8 +146,8 @@ for (const { descriptor, inlineScriptType } of typesOfInlineScripts) {
cy.visit(page.navigation).waitForRouteChange()
cy.get(`a[href="${page.target}"][id=anchor-link]`).click()
cy.get(`table[id=script-mark-records] tbody`) // Make sure history has time to change
cy.go(`back`)
cy.go(`forward`)
cy.go(`back`).waitForRouteChange()
cy.go(`forward`).waitForRouteChange()

cy.get(`table[id=script-mark-records] tbody`)
.children()
Expand Down Expand Up @@ -180,8 +185,8 @@ for (const { descriptor, inlineScriptType } of typesOfInlineScripts) {
it(`should load only once if the page is revisited via browser back/forward buttons after Gatsby link navigation`, () => {
cy.visit(page.navigation).waitForRouteChange()
cy.get(`a[href="${page.target}"][id=gatsby-link]`).click()
cy.go(`back`)
cy.go(`forward`)
cy.go(`back`).waitForRouteChange()
cy.go(`forward`).waitForRouteChange()

cy.get(`table[id=script-mark-records] tbody`)
.children()
Expand Down
Expand Up @@ -8,8 +8,13 @@ const page = {
navigation: `/gatsby-script-navigation/`,
}

Cypress.on('uncaught:exception', (err) => {
if ((err.message.includes('Minified React error #418') || err.message.includes('Minified React error #423') || err.message.includes('Minified React error #425')) && Cypress.env(`TEST_PLUGIN_OFFLINE`)) {
Cypress.on(`uncaught:exception`, err => {
if (
(err.message.includes(`Minified React error #418`) ||
err.message.includes(`Minified React error #423`) ||
err.message.includes(`Minified React error #425`)) &&
Cypress.env(`TEST_PLUGIN_OFFLINE`)
) {
return false
}
})
Expand Down Expand Up @@ -131,8 +136,8 @@ describe(`scripts with sources`, () => {
it(`should load only once if the page is revisited via browser back/forward buttons after anchor link navigation`, () => {
cy.visit(page.navigation).waitForRouteChange()
cy.get(`a[href="${page.target}"][id=anchor-link]`).click()
cy.go(`back`)
cy.go(`forward`)
cy.go(`back`).waitForRouteChange()
cy.go(`forward`).waitForRouteChange()

cy.get(`table[id=script-resource-records] tbody`)
.children()
Expand Down Expand Up @@ -162,8 +167,8 @@ describe(`scripts with sources`, () => {
it(`should load only once if the page is revisited via browser back/forward buttons after Gatsby link navigation`, () => {
cy.visit(page.navigation).waitForRouteChange()
cy.get(`a[href="${page.target}"][id=gatsby-link]`).click()
cy.go(`back`)
cy.go(`forward`)
cy.go(`back`).waitForRouteChange()
cy.go(`forward`).waitForRouteChange()

cy.get(`table[id=script-resource-records] tbody`)
.children()
Expand Down

0 comments on commit 1cfd9b8

Please sign in to comment.