From 0f31f53a26a59cad407f6e422341209deb7c3d21 Mon Sep 17 00:00:00 2001 From: Adnaan Badr Date: Sun, 19 Jul 2026 10:07:48 +0000 Subject: [PATCH] test(file-tree): wait for the star to change, not for the button to exist TestFileTreeE2E flaked roughly one run in three, and failed livetemplate#504's Docs Examples check. The star step waited on the wrong thing: chromedp.Click(star button) chromedp.WaitVisible(li[data-key=...] button[name=star]) <- already visible chromedp.Evaluate(textContent.includes('star')) <- races the WS round trip That button is on screen before the click; only its text changes. So the wait was satisfied instantly and the assertion read the pre-update DOM. The diagnostic dump on the CI failure showed the star HAD applied by the time it ran, which is what pointed at a read race rather than a broken update. Now waits on the text actually changing, via e2etest.WaitFor. Only this step was affected: every other wait in the test targets an element the update creates (li[data-key=/internal/store] and friends), which genuinely does not exist until the update lands. Verified 8 consecutive passes, against roughly 1-in-3 failures before. Confirmed not a livetemplate regression before changing the test: with the real file-tree template and the real toggle-toggle-toggle-star sequence, the built tree JSON is byte-identical between livetemplate#504 and its parent, so the wrapper-tagging change does not affect anything this test exercises. --- examples/file-tree/file_tree_test.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/file-tree/file_tree_test.go b/examples/file-tree/file_tree_test.go index 2c44798..c52e0e3 100644 --- a/examples/file-tree/file_tree_test.go +++ b/examples/file-tree/file_tree_test.go @@ -358,7 +358,12 @@ func TestFileTreeE2E(t *testing.T) { var starred, siblingSurvived bool if err := chromedp.Run(ctx, chromedp.Click(`button[name="star"][value="`+deepFile+`"]`, chromedp.ByQuery), - chromedp.WaitVisible(`li[data-key="`+deepFile+`"] button[name="star"]`, chromedp.ByQuery), + // Wait for the star itself to change, not for the button to exist. The + // button is already on screen before the click — only its text changes — + // so a WaitVisible here is satisfied instantly and the assertion below + // races the WebSocket round trip. Every other wait in this test targets + // an element the update creates, which is why only this step flaked. + e2etest.WaitFor(`document.querySelector('li[data-key="`+deepFile+`"] button[name="star"]').textContent.includes('★')`, 10*time.Second), chromedp.Evaluate(`document.querySelector('li[data-key="`+deepFile+`"] button[name="star"]').textContent.includes('★')`, &starred), chromedp.Evaluate(`document.querySelector('li[data-key="/internal/store/sql/migrate.go"]').__lvtMark === 'sibling'`, &siblingSurvived), ); err != nil {