Add Partials (#1824)
This commit is contained in:
+41
-8
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user