test(acpmux): bare-pr-refs gives the code block's highlighter customElements, so it never fails on a slow runner
Problem
webviews/test/bare-pr-refs.test.tsx "a reference in a code span or a code block is not a link" failed on #23212's CI run with:
ReferenceError: customElements is not defined
at node_modules/@pierre/diffs/dist/components/web-components.js:6:43
The test's jsdom shim installs HTMLElement but not customElements. The code block's highlighted card (HighlightedCode.tsx, which imports @pierre/diffs) loads lazily after the first frame (CodeBlock.tsx loadHighlightedCode), and the library registers its web component at import time. On a slow runner that import settles while the test is still running, so it fails. On a fast host it settles after the test, so it passes. That's why the eight latest base runs pass it. The test came from #22893.
Change
Test only.
- The test awaits
loadHighlightedCode(), so the import always lands inside it. The red is then the same on every host. - The shim installs
customElementsfrom jsdom, and restores it after the test.
No assertion changes.
Changelog
none
Observed / Not run
bun test test/bare-pr-refs.test.tsx: with commit 1 alone, 3 pass and 1 fail (ReferenceError: customElements is not defined, CI's error). With commit 2: 4 pass.- Not run: CI on this head (pending).
Agent session: huge-blue
🤖 Generated with Claude Code
Need help on this PR? Tag @codesmith-bot with what you need.
Summary by cubic
Fixes the flaky bare-pr-refs test that failed on slow CI runners with ReferenceError: customElements is not defined. The code block's highlighted card lazily imports @pierre/diffs, which registers its web component at import time and builds its lines with the DOM's constructors. On slow hosts that import could land mid-test; on fast hosts it landed after.
The test now awaits loadHighlightedCode() so the import always settles inside the test, then reads the code block where the card draws it—in the diffs-container shadow root—and asserts no link appears there. The jsdom shim installs customElements plus all DOM constructors (HTML*, SVG*, CSS*, Shadow*, Document*) and restores them afterward. No assertion changes.