fix: show marker confusion (#1823)

This commit is contained in:
Marvin Hagemeister
2023-09-26 11:54:36 +02:00
committed by GitHub
parent 5a47ffaf59
commit 78606477ec
6 changed files with 337 additions and 359 deletions
+46
View File
@@ -123,6 +123,8 @@ function _printDomNode(
if (node.nodeType === 3) {
return space + colors.dim(node.textContent ?? "") + "\n";
} else if (node.nodeType === 8) {
return space + colors.dim(`<--${(node as Text).data}-->`) + "\n";
}
let out = space;
@@ -483,3 +485,47 @@ export function getStdOutput(
return { stdout, stderr };
}
function walk(doc: Document, node: HTMLElement): string | null {
for (let i = 0; i < node.childNodes.length; i++) {
const child = node.childNodes[i];
if (child.nodeType === doc.COMMENT_NODE) {
return child.data;
} else if (child.nodeType === doc.TEXT_NODE) {
continue;
} else if (
child.nodeType === doc.ELEMENT_NODE && node.localName !== "template"
) {
const res = walk(doc, child);
if (res !== null) return res;
}
}
return null;
}
export async function assertNoPageComments(page: Page) {
const doc = parseHtml(await page.content());
// deno-lint-ignore no-explicit-any
const result = walk(doc, doc.body as any);
if (result !== null) {
console.log(prettyDom(doc));
throw new Error(
`Expected no HTML comments to be present, but found comment "${result}"`,
);
}
}
export function assertNoComments(doc: Document) {
// deno-lint-ignore no-explicit-any
const result = walk(doc, doc.body as any);
if (result !== null) {
console.log(prettyDom(doc));
throw new Error(
`Expected no HTML comments to be present, but found comment "${result}"`,
);
}
}