Add Partials (#1824)

This commit is contained in:
Marvin Hagemeister
2023-09-27 13:34:30 +02:00
committed by GitHub
parent d9829e25e6
commit 665d35bbc2
92 changed files with 3271 additions and 116 deletions
+41 -8
View File
@@ -363,14 +363,25 @@ export async function waitForText(
text: string,
) {
await page.waitForSelector(selector);
await page.waitForFunction(
(sel, value) => {
return document.querySelector(sel)!.textContent === value;
},
{ timeout: 2000 },
selector,
String(text),
);
try {
await page.waitForFunction(
(sel, value) => {
return document.querySelector(sel)!.textContent === value;
},
{ timeout: 2000 },
selector,
String(text),
);
} catch (err) {
const body = await page.content();
// deno-lint-ignore no-explicit-any
const pretty = prettyDom(parseHtml(body) as any);
console.log(
`Text "${text}" not found on selector "${selector}" in html:\n\n${pretty}`,
);
throw err;
}
}
export async function waitForStyle(
@@ -486,6 +497,28 @@ export function getStdOutput(
return { stdout, stderr };
}
export async function waitFor(
fn: () => Promise<unknown> | unknown,
): Promise<void> {
let now = Date.now();
const limit = now + 2000;
while (now < limit) {
try {
if (await fn()) return;
} catch (err) {
if (now > limit) {
throw err;
}
} finally {
await delay(100);
now = Date.now();
}
}
throw new Error(`Timed out`);
}
function walk(doc: Document, node: HTMLElement): string | null {
for (let i = 0; i < node.childNodes.length; i++) {
const child = node.childNodes[i];