From 1430626ea70b32768b3a18acc569effa169cc401 Mon Sep 17 00:00:00 2001 From: tyhopp Date: Mon, 14 Nov 2022 15:16:28 +0800 Subject: [PATCH] chore(e2e-tests): Wait for route change on back/forward --- .../gatsby-script-inline-scripts.js | 8 ++++---- .../gatsby-script-scripts-with-sources.js | 8 ++++---- .../integration/gatsby-script-inline-scripts.js | 17 +++++++++++------ .../gatsby-script-scripts-with-sources.js | 17 +++++++++++------ 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/e2e-tests/development-runtime/cypress/integration/gatsby-script/gatsby-script-inline-scripts.js b/e2e-tests/development-runtime/cypress/integration/gatsby-script/gatsby-script-inline-scripts.js index 54cedb9d2ff7c..a43abdb6037bf 100644 --- a/e2e-tests/development-runtime/cypress/integration/gatsby-script/gatsby-script-inline-scripts.js +++ b/e2e-tests/development-runtime/cypress/integration/gatsby-script/gatsby-script-inline-scripts.js @@ -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() @@ -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() diff --git a/e2e-tests/development-runtime/cypress/integration/gatsby-script/gatsby-script-scripts-with-sources.js b/e2e-tests/development-runtime/cypress/integration/gatsby-script/gatsby-script-scripts-with-sources.js index 71414162a02ae..523ac95bc16d0 100644 --- a/e2e-tests/development-runtime/cypress/integration/gatsby-script/gatsby-script-scripts-with-sources.js +++ b/e2e-tests/development-runtime/cypress/integration/gatsby-script/gatsby-script-scripts-with-sources.js @@ -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() @@ -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() diff --git a/e2e-tests/production-runtime/cypress/integration/gatsby-script-inline-scripts.js b/e2e-tests/production-runtime/cypress/integration/gatsby-script-inline-scripts.js index 7c0b300e6ded2..75d624494116a 100644 --- a/e2e-tests/production-runtime/cypress/integration/gatsby-script-inline-scripts.js +++ b/e2e-tests/production-runtime/cypress/integration/gatsby-script-inline-scripts.js @@ -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 } }) @@ -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() @@ -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() diff --git a/e2e-tests/production-runtime/cypress/integration/gatsby-script-scripts-with-sources.js b/e2e-tests/production-runtime/cypress/integration/gatsby-script-scripts-with-sources.js index 51bc1398ef2cf..f8893cc4d1c89 100644 --- a/e2e-tests/production-runtime/cypress/integration/gatsby-script-scripts-with-sources.js +++ b/e2e-tests/production-runtime/cypress/integration/gatsby-script-scripts-with-sources.js @@ -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 } }) @@ -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() @@ -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()