Skip to content

Commit f66afd7

Browse files
committed
fix: Stabilize flaky link visibility toggle test
The test was flaky because it wasn't properly waiting for the canvas to update after changing the link render mode setting. The setting change triggers a canvas redraw via setDirty(), but the actual redraw happens asynchronously. Changes: - Add explicit wait for canvas.links_render_mode to update - Capture initial link render mode to properly verify state changes - Add double frame wait plus 100ms delay to ensure canvas redraw completes - Improve wait condition for visible links to handle undefined initial state - Add timeout protection to prevent test hanging This ensures the test reliably waits for both the setting change and the visual update before taking screenshots, eliminating the race condition that was causing intermittent failures.
1 parent fa9f5fb commit f66afd7

File tree

1 file changed

+52
-5
lines changed

1 file changed

+52
-5
lines changed

browser_tests/tests/graphCanvasMenu.spec.ts

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,72 @@ test.describe('Graph Canvas Menu', () => {
1313

1414
test('Can toggle link visibility', async ({ comfyPage }) => {
1515
const button = comfyPage.page.getByTestId('toggle-link-visibility-button')
16+
17+
// Get the initial link render mode and HIDDEN_LINK constant
18+
const { initialMode, hiddenLinkMode } = await comfyPage.page.evaluate(
19+
() => {
20+
return {
21+
initialMode: window['app']?.canvas?.links_render_mode,
22+
hiddenLinkMode: window['LiteGraph'].HIDDEN_LINK
23+
}
24+
}
25+
)
26+
27+
// First click - hide links
1628
await button.click()
29+
30+
// Wait for the setting to actually change to hidden
31+
await comfyPage.page.waitForFunction(
32+
(expectedMode) => {
33+
const canvas = window['app']?.canvas
34+
return canvas && canvas.links_render_mode === expectedMode
35+
},
36+
hiddenLinkMode,
37+
{ timeout: 5000 }
38+
)
39+
40+
// Wait for canvas to complete rendering with hidden links
41+
// Use multiple frames and a small delay to ensure canvas is fully updated
42+
await comfyPage.nextFrame()
1743
await comfyPage.nextFrame()
44+
await comfyPage.page.waitForTimeout(100) // Small delay for canvas rendering
45+
1846
await expect(comfyPage.canvas).toHaveScreenshot(
1947
'canvas-with-hidden-links.png'
2048
)
21-
const hiddenLinkRenderMode = await comfyPage.page.evaluate(() => {
22-
return window['LiteGraph'].HIDDEN_LINK
23-
})
2449
expect(await comfyPage.getSetting('Comfy.LinkRenderMode')).toBe(
25-
hiddenLinkRenderMode
50+
hiddenLinkMode
2651
)
2752

53+
// Second click - show links again
2854
await button.click()
55+
56+
// Wait for the setting to change back to the initial mode
57+
await comfyPage.page.waitForFunction(
58+
({ hiddenMode, initial }) => {
59+
const canvas = window['app']?.canvas
60+
// Check that it's not hidden and matches the expected visible mode
61+
return (
62+
canvas &&
63+
canvas.links_render_mode !== hiddenMode &&
64+
(initial === undefined || canvas.links_render_mode === initial)
65+
)
66+
},
67+
{ hiddenMode: hiddenLinkMode, initial: initialMode },
68+
{ timeout: 5000 }
69+
)
70+
71+
// Wait for canvas to complete rendering with visible links
72+
// Use multiple frames and a small delay to ensure canvas is fully updated
73+
await comfyPage.nextFrame()
2974
await comfyPage.nextFrame()
75+
await comfyPage.page.waitForTimeout(100) // Small delay for canvas rendering
76+
3077
await expect(comfyPage.canvas).toHaveScreenshot(
3178
'canvas-with-visible-links.png'
3279
)
3380
expect(await comfyPage.getSetting('Comfy.LinkRenderMode')).not.toBe(
34-
hiddenLinkRenderMode
81+
hiddenLinkMode
3582
)
3683
})
3784

0 commit comments

Comments
 (0)