Skip to content

Commit 7194df0

Browse files
committed
Fix flaky E2E test cases - swap every self-import in that module to relative ./… paths so the only alias use that remains is from the spec files themselves, extend BasePage.waitForPageLoad() with a requireNext option so callers can specifically wait for the next astro:page-load event
1 parent 119a684 commit 7194df0

5 files changed

Lines changed: 28 additions & 19 deletions

File tree

‎_TODO.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# TODO
22

3+
Next, I'd like to add a "pause" and "play" icon to src/components/Animations/Computers
4+
There are icons with those names already configured for the Icon component.
5+
There are hooks for pause and play already setup in the component.
6+
The icon should be displayed in the low right hand corner of the animation, with 4px of padding from the bottom and right side. It should overlay the animation, not expand the bounding box of the animation.
7+
38
## Performance
49

510
Implement mitigations in test/e2e/specs/07-performance/PERFORMANCE.md

‎test/e2e/helpers/index.ts‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ export {
22
test,
33
describe,
44
expect,
5-
} from '@test/e2e/helpers/baseTest'
5+
} from './baseTest'
66
export {
77
setupConsoleErrorChecker,
88
logConsoleErrors,
9-
} from '@test/e2e/helpers/consoleErrors'
9+
} from './consoleErrors'
1010
export {
1111
setupConsoleCapture,
1212
printCapturedMessages,
13-
} from '@test/e2e/helpers/consoleCapture'
14-
export { clearConsentCookies } from '@test/e2e/helpers/browserState'
15-
export { BasePage } from '@test/e2e/helpers/pageObjectModels/BasePage'
16-
export { ComponentPersistencePage } from '@test/e2e/helpers/pageObjectModels/ComponentPersistencePage'
17-
export { HeadPage } from '@test/e2e/helpers/pageObjectModels/HeadPage'
18-
export { BreadCrumbPage } from '@test/e2e/helpers/pageObjectModels/BreadCrumbPage'
13+
} from './consoleCapture'
14+
export { clearConsentCookies } from './browserState'
15+
export { BasePage } from './pageObjectModels/BasePage'
16+
export { ComponentPersistencePage } from './pageObjectModels/ComponentPersistencePage'
17+
export { HeadPage } from './pageObjectModels/HeadPage'
18+
export { BreadCrumbPage } from './pageObjectModels/BreadCrumbPage'
1919
export {
2020
spyOnFetchEndpoint,
2121
mockFetchEndpointResponse,
2222
injectHeadersIntoFetch,
2323
delayFetchForEndpoint,
24-
} from '@test/e2e/helpers/fetchOverride'
25-
export type { FetchOverrideHandle } from '@test/e2e/helpers/fetchOverride'
24+
} from './fetchOverride'
25+
export type { FetchOverrideHandle } from './fetchOverride'
2626
export {
2727
setupCleanTestPage,
2828
setupTestPage,
2929
selectTheme,
3030
getThemePickerToggle,
31-
} from '@test/e2e/helpers/cookieHelper'
32-
export { wiremock, mocksEnabled } from '@test/e2e/helpers/mockServices'
31+
} from './cookieHelper'
32+
export { wiremock, mocksEnabled } from './mockServices'

‎test/e2e/helpers/pageObjectModels/BasePage.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,18 +435,22 @@ export class BasePage {
435435
* await page.waitForPageLoad()
436436
* ```
437437
*/
438-
async waitForPageLoad(): Promise<void> {
438+
async waitForPageLoad(options?: { requireNext?: boolean; timeout?: number }): Promise<void> {
439+
const requireNext = options?.requireNext ?? false
440+
const timeout = options?.timeout ?? DEFAULT_NAVIGATION_TIMEOUT
439441
const currentCount = await this._page.evaluate(() => window.__astroPageLoadCounter ?? 0)
440442

441-
if (currentCount > this.lastAstroPageLoadCount) {
443+
if (!requireNext && currentCount > this.lastAstroPageLoadCount) {
442444
this.lastAstroPageLoadCount = currentCount
443445
return
444446
}
445447

448+
const baseline = requireNext ? currentCount : this.lastAstroPageLoadCount
449+
446450
await this._page.waitForFunction(
447451
previousCount => (window.__astroPageLoadCounter ?? 0) > previousCount,
448-
currentCount,
449-
{ timeout: DEFAULT_NAVIGATION_TIMEOUT }
452+
baseline,
453+
{ timeout }
450454
)
451455

452456
this.lastAstroPageLoadCount = await this._page.evaluate(() => window.__astroPageLoadCounter ?? 0)

‎test/e2e/helpers/pageObjectModels/BreadCrumbPage.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class BreadCrumbPage extends BasePage {
5555
return
5656
}
5757

58-
const waitForLoad = this.waitForPageLoad()
58+
const waitForLoad = this.waitForPageLoad({ requireNext: true })
5959
await this.click(`a[href="${targetHref}"]`)
6060
await waitForLoad
6161
}

‎test/e2e/specs/01-smoke/critical-paths.spec.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ test.describe('Critical Paths @smoke', () => {
2424
const page = await BasePage.init(playwrightPage)
2525
for (const { url: path } of page.navigationItems) {
2626
await page.goto('/')
27-
const navigationComplete = page.waitForPageLoad()
27+
const navigationComplete = page.waitForPageLoad({ requireNext: true })
2828
await page.navigateToPage(path)
2929
await navigationComplete
3030
await playwrightPage.waitForFunction(() => {
@@ -56,7 +56,7 @@ test.describe('Critical Paths @smoke', () => {
5656
await playwrightPage.waitForSelector('.menu-visible', { state: 'visible' })
5757

5858
// Click navigation link
59-
const navigationComplete = page.waitForPageLoad()
59+
const navigationComplete = page.waitForPageLoad({ requireNext: true })
6060
await page.click(`a[href="${path}"]`)
6161
await navigationComplete
6262
await playwrightPage.waitForFunction(() => {

0 commit comments

Comments
 (0)