Skip to content

Commit f9f9a3d

Browse files
authored
test: fix YFM HTML test stability (#1094)
1 parent 0baa85d commit f9f9a3d

3 files changed

Lines changed: 2 additions & 38 deletions

File tree

demo/tests/playwright/core/types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export interface WaitFixture {
5757
visible(selector: Locator): Promise<void>;
5858
hidden(selector: Locator): Promise<void>;
5959
timeout(delay?: number): Promise<void>;
60-
markupRendered(delay?: number, stableThreshold?: number): Promise<void>;
6160
}
6261

6362
export interface CaptureScreenshotParams extends PageScreenshotOptions {

demo/tests/playwright/core/wait.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import type {Locator} from '@playwright/test';
33
import type {PlaywrightFixture, WaitFixture} from './types';
44

55
const DEFAULT_DELAY = 100;
6-
const MAX_STABLE_CHECKS = 50;
7-
const REQUIRED_STABLE_COUNT = 2;
8-
9-
type Snapshot = {text: string; height: number};
106

117
export const wait: PlaywrightFixture<WaitFixture> = async ({page}, use) => {
128
await use({
@@ -27,36 +23,5 @@ export const wait: PlaywrightFixture<WaitFixture> = async ({page}, use) => {
2723
timeout: async (delay = DEFAULT_DELAY) => {
2824
await page.waitForTimeout(delay);
2925
},
30-
markupRendered: async (delay = DEFAULT_DELAY, stableThreshold = REQUIRED_STABLE_COUNT) => {
31-
const locator = page.locator('.playground__markup');
32-
await locator.waitFor({state: 'visible'});
33-
34-
let prev: Snapshot = {text: '', height: 0};
35-
let stableCount = 0;
36-
37-
for (let i = 0; i < MAX_STABLE_CHECKS; i++) {
38-
const curr = await getMarkupPreviewMetrics(locator);
39-
40-
if (isStable(prev, curr)) {
41-
stableCount++;
42-
if (stableCount >= stableThreshold) break;
43-
} else {
44-
stableCount = 0;
45-
prev = curr;
46-
}
47-
48-
await page.waitForTimeout(delay);
49-
}
50-
},
5126
});
5227
};
53-
54-
async function getMarkupPreviewMetrics(locator: Locator): Promise<Snapshot> {
55-
const text = (await locator.textContent())?.trim() ?? '';
56-
const height = (await locator.boundingBox())?.height ?? 0;
57-
return {text, height};
58-
}
59-
60-
function isStable(prev: Snapshot, curr: Snapshot): boolean {
61-
return Boolean(curr.text) && prev.text === curr.text && prev.height === curr.height;
62-
}

demo/tests/visual-tests/YfmExtensions.visual.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ test.describe('Extensions, YFM', () => {
2323
await mount(<YFMStories.YfmTabs />);
2424
await expectScreenshot();
2525
});
26-
test('YFM HTML', async ({mount, expectScreenshot, wait}) => {
26+
test('YFM HTML', async ({mount, expectScreenshot, page}) => {
2727
await mount(<YFMStories.YfmHtmlBlock />);
2828

29-
await wait.markupRendered(1000, 3);
29+
await page.waitForTimeout(700);
3030
await expectScreenshot();
3131
});
3232
test('YFM File', async ({mount, expectScreenshot}) => {

0 commit comments

Comments
 (0)