Skip to content

Commit 32eb8d8

Browse files
authored
Merge pull request #595 from dev-five-git/fix-e2e
fix e2e test
2 parents 0c0b4bd + f47038e commit 32eb8d8

File tree

2 files changed

+89
-14
lines changed

2 files changed

+89
-14
lines changed

.github/workflows/publish.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,6 @@ jobs:
147147
file_pattern: "e2e/**/*-snapshots/*.png"
148148
- name: Run E2E Tests
149149
run: bun run test:e2e
150-
- name: Upload artifact
151-
uses: actions/upload-pages-artifact@v3
152-
with:
153-
path: ./apps/landing/out
154-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
155-
- uses: actions/deploy-pages@v4
156-
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
157150
- name: Build Landing (singleCss)
158151
run: |
159152
rm -rf apps/landing/out apps/landing/.next apps/landing/df
@@ -167,6 +160,13 @@ jobs:
167160
name: playwright-report-singlecss
168161
path: playwright-report/
169162
retention-days: 30
163+
- name: Upload artifact
164+
uses: actions/upload-pages-artifact@v3
165+
with:
166+
path: ./apps/landing/out
167+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
168+
- uses: actions/deploy-pages@v4
169+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
170170
- name: Upload to codecov.io
171171
uses: codecov/codecov-action@v5
172172
with:

e2e/helpers.ts

Lines changed: 82 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import type { Page } from '@playwright/test'
22

3+
const CI_SETTLE_DELAY_MS = 250
4+
const LOCAL_SETTLE_DELAY_MS = 100
5+
6+
function getSettleDelayMs(): number {
7+
return process.env.CI ? CI_SETTLE_DELAY_MS : LOCAL_SETTLE_DELAY_MS
8+
}
9+
310
/**
411
* Wait for all fonts to be loaded and a rendering frame to complete.
512
* Replaces waitForTimeout(1000) after page.goto()
@@ -8,14 +15,43 @@ import type { Page } from '@playwright/test'
815
* (page.evaluate is not available in JS-disabled contexts).
916
*/
1017
export async function waitForFontsReady(page: Page): Promise<void> {
18+
await page.waitForLoadState('load')
19+
1120
try {
12-
await page.evaluate(async () => {
13-
await document.fonts.ready
14-
await page.waitForLoadState('load')
15-
})
21+
await page.evaluate(async (settleDelayMs) => {
22+
const wait = (ms: number) =>
23+
new Promise<void>((resolve) => window.setTimeout(resolve, ms))
24+
const nextFrame = () =>
25+
new Promise<void>((resolve) => requestAnimationFrame(() => resolve()))
26+
27+
if ('fonts' in document) {
28+
await document.fonts.ready
29+
}
30+
31+
const pendingImages = Array.from(document.images).filter(
32+
(image) => !image.complete,
33+
)
34+
35+
await Promise.all(
36+
pendingImages.map(
37+
(image) =>
38+
new Promise<void>((resolve) => {
39+
image.addEventListener('load', () => resolve(), {
40+
once: true,
41+
})
42+
image.addEventListener('error', () => resolve(), {
43+
once: true,
44+
})
45+
}),
46+
),
47+
)
48+
49+
await nextFrame()
50+
await nextFrame()
51+
await wait(settleDelayMs)
52+
}, getSettleDelayMs())
1653
} catch {
17-
// JS disabled — fall back to load event (fires after fonts in CSS are loaded)
18-
await page.waitForLoadState('load')
54+
await page.waitForTimeout(getSettleDelayMs())
1955
}
2056
}
2157

@@ -26,5 +62,44 @@ export async function waitForFontsReady(page: Page): Promise<void> {
2662
* Falls back to waitForLoadState('load') when JavaScript is disabled.
2763
*/
2864
export async function waitForStyleSettle(page: Page): Promise<void> {
29-
await page.waitForTimeout(100)
65+
try {
66+
await page.waitForFunction(() => {
67+
return Array.from(
68+
document.querySelectorAll<HTMLLinkElement>('link[rel="stylesheet"]'),
69+
).every((link) => {
70+
if (!link.href) {
71+
return true
72+
}
73+
74+
const { sheet } = link
75+
if (!sheet) {
76+
return false
77+
}
78+
79+
try {
80+
void sheet.cssRules
81+
return true
82+
} catch {
83+
return false
84+
}
85+
})
86+
})
87+
} catch {
88+
await page.waitForLoadState('load')
89+
}
90+
91+
try {
92+
await page.evaluate(async (settleDelayMs) => {
93+
const wait = (ms: number) =>
94+
new Promise<void>((resolve) => window.setTimeout(resolve, ms))
95+
const nextFrame = () =>
96+
new Promise<void>((resolve) => requestAnimationFrame(() => resolve()))
97+
98+
await nextFrame()
99+
await nextFrame()
100+
await wait(settleDelayMs)
101+
}, getSettleDelayMs())
102+
} catch {
103+
await page.waitForTimeout(getSettleDelayMs())
104+
}
30105
}

0 commit comments

Comments
 (0)