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
+2 -2
View File
@@ -129,7 +129,7 @@ function hideMarker(marker: Marker) {
const parent = endNode!.parentNode!; const parent = endNode!.parentNode!;
if ( if (
SHOW_MARKERS && startNode !== null && !SHOW_MARKERS && startNode !== null &&
startNode.nodeType === Node.COMMENT_NODE startNode.nodeType === Node.COMMENT_NODE
) { ) {
const text = new Text(""); const text = new Text("");
@@ -139,7 +139,7 @@ function hideMarker(marker: Marker) {
} }
if ( if (
SHOW_MARKERS && endNode !== null && endNode.nodeType === Node.COMMENT_NODE !SHOW_MARKERS && endNode !== null && endNode.nodeType === Node.COMMENT_NODE
) { ) {
const text = new Text(""); const text = new Text("");
marker.endNode = text; marker.endNode = text;
@@ -31,6 +31,7 @@ import * as $$7 from "./islands/IslandFn.tsx";
import * as $$8 from "./islands/IslandInsideIsland.tsx"; import * as $$8 from "./islands/IslandInsideIsland.tsx";
import * as $$9 from "./islands/IslandWithProps.tsx"; import * as $$9 from "./islands/IslandWithProps.tsx";
import * as $$10 from "./islands/PassThrough.tsx"; import * as $$10 from "./islands/PassThrough.tsx";
import * as $$11 from "./islands/ReadyMarker.tsx";
const manifest = { const manifest = {
routes: { routes: {
@@ -65,6 +66,7 @@ const manifest = {
"./islands/IslandInsideIsland.tsx": $$8, "./islands/IslandInsideIsland.tsx": $$8,
"./islands/IslandWithProps.tsx": $$9, "./islands/IslandWithProps.tsx": $$9,
"./islands/PassThrough.tsx": $$10, "./islands/PassThrough.tsx": $$10,
"./islands/ReadyMarker.tsx": $$11,
}, },
baseUrl: import.meta.url, baseUrl: import.meta.url,
}; };
@@ -0,0 +1,15 @@
import { useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
export function ReadyMarker() {
const sig = useSignal(false);
useEffect(() => {
sig.value = true;
}, []);
return (
<p class={sig.value ? "mounted" : "pending"}>
{sig.value ? "mounted" : "pending"}
</p>
);
}
@@ -2,6 +2,7 @@ import IslandConditional from "../islands/IslandConditional.tsx";
import BooleanButton from "../islands/BooleanButton.tsx"; import BooleanButton from "../islands/BooleanButton.tsx";
import { useSignal } from "@preact/signals"; import { useSignal } from "@preact/signals";
import Counter from "../islands/Counter.tsx"; import Counter from "../islands/Counter.tsx";
import { ReadyMarker } from "../islands/ReadyMarker.tsx";
export default function Page() { export default function Page() {
const show = useSignal(true); const show = useSignal(true);
@@ -16,6 +17,7 @@ export default function Page() {
</div> </div>
</IslandConditional> </IslandConditional>
<BooleanButton signal={show} /> <BooleanButton signal={show} />
<ReadyMarker />
</div> </div>
); );
} }
+270 -357
View File
@@ -1,11 +1,6 @@
import { assert, assertEquals, assertStringIncludes, Page } from "./deps.ts";
import { import {
assert, assertNoPageComments,
assertEquals,
assertStringIncludes,
delay,
Page,
} from "./deps.ts";
import {
assertNotSelector, assertNotSelector,
assertSelector, assertSelector,
assertTextMatch, assertTextMatch,
@@ -16,139 +11,115 @@ import {
withPageName, withPageName,
} from "./test_utils.ts"; } from "./test_utils.ts";
Deno.test({ Deno.test("island tests", async (t) => {
name: "island tests", await withPage(async (page, address) => {
async fn(t) { async function counterTest(counterId: string, originalValue: number) {
await withPage(async (page, address) => { const pElem = await page.waitForSelector(`#${counterId} > p`);
async function counterTest(counterId: string, originalValue: number) {
const pElem = await page.waitForSelector(`#${counterId} > p`);
const value = await pElem?.evaluate((el) => el.textContent); const value = await pElem?.evaluate((el) => el.textContent);
assert(value === `${originalValue}`, `${counterId} first value`); assert(value === `${originalValue}`, `${counterId} first value`);
await clickWhenListenerReady(page, `#b-${counterId}`); await clickWhenListenerReady(page, `#b-${counterId}`);
await waitForText(page, `#${counterId} > p`, String(originalValue + 1)); await waitForText(page, `#${counterId} > p`, String(originalValue + 1));
} }
await page.goto(`${address}/islands`, { await page.goto(`${address}/islands`);
waitUntil: "networkidle2",
});
await t.step("Ensure 5 islands on 1 page are revived", async () => { await t.step("Ensure 5 islands on 1 page are revived", async () => {
await counterTest("counter1", 3); await counterTest("counter1", 3);
await counterTest("counter2", 10); await counterTest("counter2", 10);
await counterTest("folder-counter", 3); await counterTest("folder-counter", 3);
await counterTest("subfolder-counter", 3); await counterTest("subfolder-counter", 3);
await counterTest("kebab-case-file-counter", 5); await counterTest("kebab-case-file-counter", 5);
});
await t.step("Ensure an island revive an img 'hash' path", async () => {
// Ensure src path has __frsh_c=
const pElem = await page.waitForSelector(`#img-in-island`);
const srcString = (await pElem?.getProperty("src"))?.toString()!;
assertStringIncludes(srcString, "image.png?__frsh_c=");
// Ensure src path is the same as server rendered
const resp = await fetch(new Request(`${address}/islands`));
const body = await resp.text();
const imgFilePath = body.match(/img id="img-in-island" src="(.*?)"/)
?.[1]!;
assertStringIncludes(srcString, imgFilePath);
});
}); });
},
await t.step("Ensure an island revive an img 'hash' path", async () => {
// Ensure src path has __frsh_c=
const pElem = await page.waitForSelector(`#img-in-island`);
const srcString = (await pElem?.getProperty("src"))?.toString()!;
assertStringIncludes(srcString, "image.png?__frsh_c=");
// Ensure src path is the same as server rendered
const resp = await fetch(new Request(`${address}/islands`));
const body = await resp.text();
const imgFilePath = body.match(/img id="img-in-island" src="(.*?)"/)
?.[1]!;
assertStringIncludes(srcString, imgFilePath);
});
});
}); });
Deno.test({ Deno.test("multiple islands exported from one file", async (t) => {
name: "multiple islands exported from one file", await withPage(async (page, address) => {
async fn(t) { async function counterTest(counterId: string, originalValue: number) {
await withPage(async (page, address) => { const pElem = await page.waitForSelector(`#${counterId} > p`);
async function counterTest(counterId: string, originalValue: number) {
const pElem = await page.waitForSelector(`#${counterId} > p`);
const value = await pElem?.evaluate((el) => el.textContent); const value = await pElem?.evaluate((el) => el.textContent);
assert(value === `${originalValue}`, `${counterId} first value`); assert(value === `${originalValue}`, `${counterId} first value`);
await clickWhenListenerReady(page, `#b-${counterId}`); await clickWhenListenerReady(page, `#b-${counterId}`);
await waitForText(page, `#${counterId} > p`, String(originalValue + 1)); await waitForText(page, `#${counterId} > p`, String(originalValue + 1));
} }
await page.goto(`${address}/islands/multiple_island_exports`, { await page.goto(`${address}/islands/multiple_island_exports`);
waitUntil: "networkidle2",
});
await t.step("Ensure 3 islands on 1 page are revived", async () => { await t.step("Ensure 3 islands on 1 page are revived", async () => {
await counterTest("counter0", 4); await counterTest("counter0", 4);
await counterTest("counter1", 3); await counterTest("counter1", 3);
await counterTest("counter2", 10); await counterTest("counter2", 10);
});
}); });
}, });
}); });
function withPage(fn: (page: Page, address: string) => Promise<void>) { function withPage(fn: (page: Page, address: string) => Promise<void>) {
return withPageName("./tests/fixture/main.ts", fn); return withPageName("./tests/fixture/main.ts", fn);
} }
Deno.test({ Deno.test("island tests with </script>", async (t) => {
name: "island tests with </script>", await withPage(async (page, address) => {
page.on("dialog", () => {
async fn(t) { assert(false, "There is XSS");
await withPage(async (page, address) => {
page.on("dialog", () => {
assert(false, "There is XSS");
});
await page.goto(`${address}/evil`, {
waitUntil: "networkidle2",
});
await t.step("prevent XSS on Island", async () => {
const bodyElem = await page.waitForSelector(`body`);
const value = await bodyElem?.evaluate((el) => el.getInnerHTML());
assertStringIncludes(
value,
`{"message":"\\u003c/script\\u003e\\u003cscript\\u003ealert('test')\\u003c/script\\u003e"}`,
`XSS is not escaped`,
);
});
}); });
},
await page.goto(`${address}/evil`, {
waitUntil: "networkidle2",
});
await t.step("prevent XSS on Island", async () => {
const bodyElem = await page.waitForSelector(`body`);
const value = await bodyElem?.evaluate((el) => el.getInnerHTML());
assertStringIncludes(
value,
`{"message":"\\u003c/script\\u003e\\u003cscript\\u003ealert('test')\\u003c/script\\u003e"}`,
`XSS is not escaped`,
);
});
});
}); });
Deno.test({ Deno.test("island with fragment as root", async () => {
name: "island with fragment as root", await withPage(async (page, address) => {
await page.goto(`${address}/islands/root_fragment`);
async fn(_t) { const clickableSelector = "#root-fragment-click-me";
await withPage(async (page, address) => {
await page.goto(`${address}/islands/root_fragment`, {
waitUntil: "networkidle2",
});
const clickableSelector = "#root-fragment-click-me"; await page.waitForSelector(clickableSelector);
await page.waitForSelector(clickableSelector); await waitForText(page, `#island-parent`, "HelloWorld");
await waitForText(page, `#island-parent`, "HelloWorld"); await clickWhenListenerReady(page, clickableSelector);
await waitForText(page, `#island-parent`, "HelloWorldI'm rendered now");
await clickWhenListenerReady(page, clickableSelector); });
await waitForText(page, `#island-parent`, "HelloWorldI'm rendered now");
});
},
}); });
Deno.test({ Deno.test(
name: "island with fragment as root and conditional child first", "island with fragment as root and conditional child first",
async () => {
async fn(_t) {
await withPage(async (page, address) => { await withPage(async (page, address) => {
await page.goto( await page.goto(
`${address}/islands/root_fragment_conditional_first`, `${address}/islands/root_fragment_conditional_first`,
{
waitUntil: "networkidle2",
},
); );
const clickableSelector = "#root-fragment-conditional-first-click-me"; const clickableSelector = "#root-fragment-conditional-first-click-me";
@@ -164,149 +135,104 @@ Deno.test({
); );
}); });
}, },
);
Deno.test("island that returns `null`", async () => {
await withPage(async (page, address) => {
await page.goto(`${address}/islands/returning_null`);
await page.waitForSelector(".added-by-use-effect");
});
}); });
Deno.test({ Deno.test("island using `npm:` specifiers", async () => {
name: "island that returns `null`", await withPageName("./tests/fixture_npm/main.ts", async (page, address) => {
await page.setJavaScriptEnabled(false);
await page.goto(address);
await page.waitForSelector("#server-true");
async fn(_t) { await page.setJavaScriptEnabled(true);
await withPage(async (page, address) => { await page.reload();
await page.goto(`${address}/islands/returning_null`, { await page.waitForSelector("#browser-true");
waitUntil: "networkidle2", });
});
await page.waitForSelector(".added-by-use-effect");
});
},
}); });
Deno.test({ Deno.test("works with older preact-render-to-string v5", async () => {
name: "island using `npm:` specifiers", await withPageName(
"./tests/fixture_preact_rts_v5/main.ts",
async fn(_t) { async (page, address) => {
await withPageName("./tests/fixture_npm/main.ts", async (page, address) => { await page.goto(address);
await page.setJavaScriptEnabled(false); await page.waitForSelector("#foo");
await page.goto(address, { waitUntil: "networkidle2" }); await waitForText(page, "#foo", "it works");
assert(await page.waitForSelector("#server-true")); +await assertNoPageComments(page);
},
await page.setJavaScriptEnabled(true); );
await page.reload({ waitUntil: "networkidle2" });
assert(await page.waitForSelector("#browser-true"));
});
},
}); });
Deno.test({ Deno.test("pass single JSX child to island", async () => {
name: "works with older preact-render-to-string v5", await withPageName(
"./tests/fixture_island_nesting/main.ts",
async fn(_t) { async (page, address) => {
await withPageName( await page.goto(`${address}/island_jsx_child`);
"./tests/fixture_preact_rts_v5/main.ts", await page.waitForSelector(".island");
async (page, address) => { await waitForText(page, ".island", "it works");
await page.goto(address, { await assertNoPageComments(page);
waitUntil: "networkidle2", },
}); );
await page.waitForSelector("#foo");
await waitForText(page, "#foo", "it works");
},
);
},
}); });
Deno.test({ Deno.test("pass multiple JSX children to island", async () => {
name: "pass single JSX child to island", await withPageName(
"./tests/fixture_island_nesting/main.ts",
async (page, address) => {
await page.goto(`${address}/island_jsx_children`);
await page.waitForSelector(".island");
async fn(_t) { await waitForText(page, ".island", "it works");
await withPageName( await assertNoPageComments(page);
"./tests/fixture_island_nesting/main.ts", },
async (page, address) => { );
await page.goto(`${address}/island_jsx_child`, {
waitUntil: "networkidle2",
});
await page.waitForSelector(".island");
await waitForText(page, ".island", "it works");
},
);
},
}); });
Deno.test({ Deno.test("pass multiple text JSX children to island", async () => {
name: "pass multiple JSX children to island", await withPageName(
"./tests/fixture_island_nesting/main.ts",
async (page, address) => {
await page.goto(`${address}/island_jsx_text`);
await page.waitForSelector(".island");
async fn(_t) { await waitForText(page, ".island", "it works");
await withPageName( await assertNoPageComments(page);
"./tests/fixture_island_nesting/main.ts", },
async (page, address) => { );
await page.goto(`${address}/island_jsx_children`, {
waitUntil: "networkidle2",
});
await page.waitForSelector(".island");
await delay(100);
const text = await page.$eval(".island", (el) => el.textContent);
assertEquals(text, "it works");
},
);
},
}); });
Deno.test({ Deno.test("render island in island", async () => {
name: "pass multiple text JSX children to island", await withPageName(
"./tests/fixture_island_nesting/main.ts",
async fn(_t) { async (page, address) => {
await withPageName( await page.goto(`${address}/island_in_island`);
"./tests/fixture_island_nesting/main.ts", await page.waitForSelector(".island");
async (page, address) => { await waitForText(page, ".island .island p", "it works");
await page.goto(`${address}/island_jsx_text`, { await assertNoPageComments(page);
waitUntil: "networkidle2", },
}); );
await page.waitForSelector(".island");
await delay(100);
const text = await page.$eval(".island", (el) => el.textContent);
assertEquals(text, "it works");
},
);
},
}); });
Deno.test({ Deno.test("render island inside island definition", async () => {
name: "render island in island", await withPageName(
"./tests/fixture_island_nesting/main.ts",
async (page, address) => {
await page.goto(`${address}/island_in_island_definition`);
await page.waitForSelector(".island");
async fn(_t) { await waitForText(page, ".island .island p", "it works");
await withPageName(
"./tests/fixture_island_nesting/main.ts",
async (page, address) => {
await page.goto(`${address}/island_in_island`, {
waitUntil: "networkidle2",
});
await page.waitForSelector(".island");
await waitForText(page, ".island .island p", "it works");
},
);
},
});
Deno.test({ // Check that there is no duplicated content which could happen
name: "render island inside island definition", // when islands aren't initialized correctly
await waitForText(page, "#page", "it works");
async fn(_t) { await assertNoPageComments(page);
await withPageName( },
"./tests/fixture_island_nesting/main.ts", );
async (page, address) => {
await page.goto(`${address}/island_in_island_definition`, {
waitUntil: "networkidle2",
});
await page.waitForSelector(".island");
await waitForText(page, ".island .island p", "it works");
// Check that there is no duplicated content which could happen
// when islands aren't initialized correctly
await waitForText(page, "#page", "it works");
},
);
},
}); });
Deno.test("render island inside island with conditional children", async () => { Deno.test("render island inside island with conditional children", async () => {
@@ -315,27 +241,25 @@ Deno.test("render island inside island with conditional children", async () => {
async (page, address) => { async (page, address) => {
await page.goto(`${address}/dropdown`); await page.goto(`${address}/dropdown`);
await page.waitForSelector("button"); await page.waitForSelector("button");
await assertNoPageComments(page);
const doc = parseHtml(await page.content()); const doc = parseHtml(await page.content());
assertNotSelector(doc, ".result"); assertNotSelector(doc, ".result");
await page.click("button"); await page.click("button");
await page.waitForSelector(".result"); await page.waitForSelector(".result");
await assertNoPageComments(page);
}, },
); );
}); });
Deno.test({ Deno.test(
name: "render island with JSX children that render another island with JSX children",
"render island with JSX children that render another island with JSX children", async () => {
async fn(_t) {
await withPageName( await withPageName(
"./tests/fixture_island_nesting/main.ts", "./tests/fixture_island_nesting/main.ts",
async (page, address) => { async (page, address) => {
await page.goto(`${address}/island_jsx_island_jsx`, { await page.goto(`${address}/island_jsx_island_jsx`);
waitUntil: "networkidle2",
});
await page.waitForSelector(".island"); await page.waitForSelector(".island");
await waitForText( await waitForText(
@@ -343,94 +267,81 @@ Deno.test({
".island .server .island .server p", ".island .server .island .server p",
"it works", "it works",
); );
await assertNoPageComments(page);
}, },
); );
}, },
);
Deno.test("render sibling islands", async () => {
await withPageName(
"./tests/fixture_island_nesting/main.ts",
async (page, address) => {
await page.goto(`${address}/island_siblings`);
await page.waitForSelector(".island");
await waitForText(page, ".island .a", "it works");
await waitForText(page, ".island + .island .b", "it works");
await assertNoPageComments(page);
},
);
}); });
Deno.test({ Deno.test("render sibling islands that render nothing initially", async () => {
name: "render sibling islands", await withPageName(
"./tests/fixture_island_nesting/main.ts",
async (page, address) => {
await page.goto(`${address}/island_conditional`);
await page.waitForSelector(".island");
await assertNoPageComments(page);
async fn(_t) { await page.click("button");
await withPageName(
"./tests/fixture_island_nesting/main.ts",
async (page, address) => {
await page.goto(`${address}/island_siblings`, {
waitUntil: "networkidle2",
});
await page.waitForSelector(".island");
await waitForText(page, ".island .a", "it works"); // Button text is matched too, but this allows us
await waitForText(page, ".island + .island .b", "it works"); // to assert correct ordering. The "island content" should
}, // be left of "Toggle"
); await waitForText(page, "#page", "island contentToggle");
}, await assertNoPageComments(page);
},
);
}); });
Deno.test({ Deno.test("serialize inner island props", async () => {
name: "render sibling islands that render nothing initially", await withPageName(
"./tests/fixture_island_nesting/main.ts",
async (page, address) => {
await page.goto(`${address}/island_nested_props`);
await page.waitForSelector(".island");
async fn(_t) { await waitForText(page, ".island .island p", "it works");
await withPageName( await assertNoPageComments(page);
"./tests/fixture_island_nesting/main.ts", },
async (page, address) => { );
await page.goto(`${address}/island_conditional`);
await page.waitForSelector(".island");
await page.click("button");
// Button text is matched too, but this allows us
// to assert correct ordering. The "island content" should
// be left of "Toggle"
await waitForText(page, "#page", "island contentToggle");
},
);
},
}); });
Deno.test({ Deno.test("render island inside island when passed as fn child", async () => {
name: "serialize inner island props", await withPageName(
async fn(_t) { "./tests/fixture_island_nesting/main.ts",
await withPageName( async (page, address) => {
"./tests/fixture_island_nesting/main.ts", await page.goto(`${address}/island_fn_child`);
async (page, address) => { await page.waitForSelector(".island");
await page.goto(`${address}/island_nested_props`); await waitForText(page, "#page", "it works");
await page.waitForSelector(".island"); await assertNoPageComments(page);
},
await waitForText(page, ".island .island p", "it works"); );
},
);
},
}); });
Deno.test({ Deno.test("render nested islands in correct order", async () => {
name: "render island inside island when passed as fn child", await withPageName(
"./tests/fixture_island_nesting/main.ts",
async fn(_t) { async (page, address) => {
await withPageName( await page.goto(`${address}/island_order`);
"./tests/fixture_island_nesting/main.ts", await page.waitForSelector(".island");
async (page, address) => { await waitForText(page, "#page", "leftcenterright");
await page.goto(`${address}/island_fn_child`); await assertNoPageComments(page);
await page.waitForSelector(".island"); },
await waitForText(page, "#page", "it works"); );
},
);
},
});
Deno.test({
name: "render nested islands in correct order",
async fn(_t) {
await withPageName(
"./tests/fixture_island_nesting/main.ts",
async (page, address) => {
await page.goto(`${address}/island_order`);
await page.waitForSelector(".island");
await waitForText(page, "#page", "leftcenterright");
},
);
},
}); });
Deno.test({ Deno.test({
@@ -442,74 +353,76 @@ Deno.test({
async (page, address) => { async (page, address) => {
await page.goto(`${address}/island_conditional_lazy`); await page.goto(`${address}/island_conditional_lazy`);
await waitForText(page, ".island p", "island content"); await waitForText(page, ".island p", "island content");
await assertNoPageComments(page);
await page.click("button"); await page.click("button");
await waitForText(page, ".island p", "server rendered"); await waitForText(page, ".island p", "server rendered");
await assertNoPageComments(page);
}, },
); );
}, },
}); });
Deno.test({ Deno.test(
name: "revive island in lazy server rendered children conditionally", "revive island in lazy server rendered children conditionally",
async () => {
async fn() {
await withPageName( await withPageName(
"./tests/fixture_island_nesting/main.ts", "./tests/fixture_island_nesting/main.ts",
async (page, address) => { async (page, address) => {
await page.goto(`${address}/island_conditional_lazy_island`); await page.goto(`${address}/island_conditional_lazy_island`);
await waitForText(page, ".island p", "island content"); await waitForText(page, ".island p", "island content");
await page.waitForSelector(".mounted");
await assertNoPageComments(page);
await page.click("button"); await page.click("button");
await waitForText(page, ".island .server", "server rendered"); await waitForText(page, ".island .server", "server rendered");
await assertNoPageComments(page);
await page.click("button.counter"); await page.click("button.counter");
await waitForText(page, ".island .count", "1"); await waitForText(page, ".island .count", "1");
await assertNoPageComments(page);
}, },
); );
}, },
}); );
Deno.test({ Deno.test("revive boolean attributes", async () => {
name: "revive boolean attributes", await withPageName(
"./tests/fixture/main.ts",
async (page, address) => {
await page.goto(`${address}/preact/boolean_attrs`);
await waitForText(page, ".form-revived", "Revived: true");
await assertNoPageComments(page);
async fn() { const checked = await page.$eval(
await withPageName( "input[type=checkbox]",
"./tests/fixture/main.ts", (el) => el.checked,
async (page, address) => { );
await page.goto(`${address}/preact/boolean_attrs`); assertEquals(checked, true, "Checkbox is not checked");
await waitForText(page, ".form-revived", "Revived: true");
const checked = await page.$eval( const required = await page.$eval(
"input[type=checkbox]", "input[type=text]",
(el) => el.checked, (el) => el.required,
); );
assertEquals(checked, true, "Checkbox is not checked"); assertEquals(required, true, "Text input is not marked as required");
const required = await page.$eval( const radioChecked = await page.$eval(
"input[type=text]", "input[type=radio][value='2']",
(el) => el.required, (el) => el.checked,
); );
assertEquals(required, true, "Text input is not marked as required"); assertEquals(
radioChecked,
true,
"Text input is not marked as required",
);
const radioChecked = await page.$eval( const selected = await page.$eval(
"input[type=radio][value='2']", "select",
(el) => el.checked, (el) => el.options[el.selectedIndex].text,
); );
assertEquals( assertEquals(selected, "bar", "'bar' value is not selected");
radioChecked, },
true, );
"Text input is not marked as required",
);
const selected = await page.$eval(
"select",
(el) => el.options[el.selectedIndex].text,
);
assertEquals(selected, "bar", "'bar' value is not selected");
},
);
},
}); });
Deno.test("throws when passing non-jsx children to an island", async (t) => { Deno.test("throws when passing non-jsx children to an island", async (t) => {
+46
View File
@@ -123,6 +123,8 @@ function _printDomNode(
if (node.nodeType === 3) { if (node.nodeType === 3) {
return space + colors.dim(node.textContent ?? "") + "\n"; return space + colors.dim(node.textContent ?? "") + "\n";
} else if (node.nodeType === 8) {
return space + colors.dim(`<--${(node as Text).data}-->`) + "\n";
} }
let out = space; let out = space;
@@ -483,3 +485,47 @@ export function getStdOutput(
return { stdout, stderr }; 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}"`,
);
}
}