Open History to see the last commit
1export function getRequiredLink(
2 container: ParentNode,
3 testId: string,
4 cache?: Map<string, HTMLAnchorElement>,
5) {
6 const cachedLink = cache?.get(testId)
7 if (cachedLink) {
8 return cachedLink
9 }
10β
11 const link = container.querySelector<HTMLAnchorElement>(
12 `[data-testid="${testId}"]`,
13 )
14 if (!link) {
15 throw new Error(`Unable to find benchmark link: ${testId}`)
16 }
17β
18 cache?.set(testId, link)
19 return link
20}
21β
22export async function waitForRequiredLink(
23 container: ParentNode,
24 testId: string,
25 cache?: Map<string, HTMLAnchorElement>,
26) {
27 for (let attempt = 0; attempt < 10; attempt++) {
28 const link = container.querySelector<HTMLAnchorElement>(
29 `[data-testid="${testId}"]`,
30 )
31β
32 if (link) {
33 cache?.set(testId, link)
34 return link
35 }
36β
37 await new Promise<void>((resolve) => {
38 requestAnimationFrame(() => resolve())
39 })
40 }
41β
42 return getRequiredLink(container, testId, cache)
43}