Skip to content

Commit 1166509

Browse files
vtenfysGatsbyJS Bot
authored and
GatsbyJS Bot
committed
fix(tests): Remove unreliable timeout logic from development-runtime (#16454)
* Remove timeout logic from development-runtime * Reduce timeout and add logging to waitForAPI * Fix package.json scripts and remove timeout from static-query.js * Remove timeout from compilation-hash.js
1 parent 7ce5cd0 commit 1166509

File tree

5 files changed

+14
-9
lines changed

5 files changed

+14
-9
lines changed

e2e-tests/development-runtime/cypress/integration/hot-reloading/static-queries.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const author = `@gatsbyjs`
22

33
beforeEach(() => {
4-
cy.visit(`/static-query/`).waitForAPIorTimeout(`onRouteUpdate`)
4+
cy.visit(`/static-query/`).waitForRouteChange()
55
})
66

77
describe(`hot-reloading static queries`, () => {

e2e-tests/production-runtime/cypress/integration/compilation-hash.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ describe(`Webpack Compilation Hash tests`, () => {
4444
// Simulate a new webpack build
4545
cy.task(`overwriteWebpackCompilationHash`, mockHash).then(() => {
4646
cy.getTestElement(`compilation-hash`).click()
47-
cy.waitForAPIorTimeout(`onRouteUpdate`, { timeout: 3000 })
47+
cy.waitForRouteChange()
4848

4949
// Navigate into a non-prefetched page
5050
cy.getTestElement(`deep-link-page`).click()
51-
cy.waitForAPIorTimeout(`onRouteUpdate`, { timeout: 3000 })
51+
cy.waitForRouteChange()
5252

5353
// If the window compilation hash has changed, we know the
5454
// page was refreshed

e2e-tests/production-runtime/cypress/integration/static-query.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
beforeEach(() => {
2-
cy.visit(`/static-query/`).waitForAPIorTimeout(`onRouteUpdate`)
2+
cy.visit(`/static-query/`).waitForRouteChange()
33
})
44

55
describe(`StaticQuery behavior`, () => {

e2e-tests/production-runtime/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
"license": "MIT",
2222
"scripts": {
2323
"build": "CYPRESS_SUPPORT=y gatsby build",
24-
"build:offline": "TEST_PLUGIN_OFFLINE=y gatsby build",
24+
"build:offline": "TEST_PLUGIN_OFFLINE=y CYPRESS_SUPPORT=y gatsby build",
2525
"develop": "gatsby develop",
2626
"format": "prettier --write '**/*.js'",
2727
"serve": "gatsby serve",
2828
"start": "npm run develop",
29-
"test": "CYPRESS_SUPPORT=y npm run build && npm run start-server-and-test && npm run test-env-vars",
30-
"test:offline": "CYPRESS_SUPPORT=y npm run build:offline && yarn start-server-and-test:offline && npm run test-env-vars",
29+
"test": "npm run build && npm run start-server-and-test && npm run test-env-vars",
30+
"test:offline": "npm run build:offline && yarn start-server-and-test:offline && npm run test-env-vars",
3131
"test-env-vars": " node __tests__/env-vars.js",
3232
"start-server-and-test": "start-server-and-test serve http://localhost:9000 cy:run",
3333
"start-server-and-test:offline": "start-server-and-test serve http://localhost:9000 cy:run:offline",

packages/gatsby-cypress/src/commands.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,18 @@ Cypress.Commands.add(`getTestElement`, (selector, options = {}) =>
66
cy.get(`[data-testid="${selector}"]`, options)
77
)
88

9-
const TIMEOUT = 9999
9+
const TIMEOUT = 5000
1010

1111
Cypress.Commands.add(
1212
`waitForAPI`,
1313
{ prevSubject: `optional` },
1414
(subject, api, { timeout = TIMEOUT } = {}) => {
15-
cy.window().then({ timeout: timeout }, win => {
15+
Cypress.log({
16+
name: `waitForAPI`,
17+
message: api,
18+
})
19+
20+
cy.window({ log: false }).then({ timeout: timeout }, win => {
1621
if (!win.___apiHandler) {
1722
win.___apiHandler = apiHandler.bind(win)
1823
}

0 commit comments

Comments
 (0)