|
|
|
@@ -1,11 +1,6 @@
|
|
|
|
|
import { assert, assertEquals, assertStringIncludes, Page } from "./deps.ts";
|
|
|
|
|
import {
|
|
|
|
|
assert,
|
|
|
|
|
assertEquals,
|
|
|
|
|
assertStringIncludes,
|
|
|
|
|
delay,
|
|
|
|
|
Page,
|
|
|
|
|
} from "./deps.ts";
|
|
|
|
|
import {
|
|
|
|
|
assertNoPageComments,
|
|
|
|
|
assertNotSelector,
|
|
|
|
|
assertSelector,
|
|
|
|
|
assertTextMatch,
|
|
|
|
@@ -16,9 +11,7 @@ import {
|
|
|
|
|
withPageName,
|
|
|
|
|
} from "./test_utils.ts";
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "island tests",
|
|
|
|
|
async fn(t) {
|
|
|
|
|
Deno.test("island tests", async (t) => {
|
|
|
|
|
await withPage(async (page, address) => {
|
|
|
|
|
async function counterTest(counterId: string, originalValue: number) {
|
|
|
|
|
const pElem = await page.waitForSelector(`#${counterId} > p`);
|
|
|
|
@@ -30,9 +23,7 @@ Deno.test({
|
|
|
|
|
await waitForText(page, `#${counterId} > p`, String(originalValue + 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await page.goto(`${address}/islands`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
await page.goto(`${address}/islands`);
|
|
|
|
|
|
|
|
|
|
await t.step("Ensure 5 islands on 1 page are revived", async () => {
|
|
|
|
|
await counterTest("counter1", 3);
|
|
|
|
@@ -57,12 +48,9 @@ Deno.test({
|
|
|
|
|
assertStringIncludes(srcString, imgFilePath);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "multiple islands exported from one file",
|
|
|
|
|
async fn(t) {
|
|
|
|
|
Deno.test("multiple islands exported from one file", async (t) => {
|
|
|
|
|
await withPage(async (page, address) => {
|
|
|
|
|
async function counterTest(counterId: string, originalValue: number) {
|
|
|
|
|
const pElem = await page.waitForSelector(`#${counterId} > p`);
|
|
|
|
@@ -74,9 +62,7 @@ Deno.test({
|
|
|
|
|
await waitForText(page, `#${counterId} > p`, String(originalValue + 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await page.goto(`${address}/islands/multiple_island_exports`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
await page.goto(`${address}/islands/multiple_island_exports`);
|
|
|
|
|
|
|
|
|
|
await t.step("Ensure 3 islands on 1 page are revived", async () => {
|
|
|
|
|
await counterTest("counter0", 4);
|
|
|
|
@@ -84,17 +70,13 @@ Deno.test({
|
|
|
|
|
await counterTest("counter2", 10);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function withPage(fn: (page: Page, address: string) => Promise<void>) {
|
|
|
|
|
return withPageName("./tests/fixture/main.ts", fn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "island tests with </script>",
|
|
|
|
|
|
|
|
|
|
async fn(t) {
|
|
|
|
|
Deno.test("island tests with </script>", async (t) => {
|
|
|
|
|
await withPage(async (page, address) => {
|
|
|
|
|
page.on("dialog", () => {
|
|
|
|
|
assert(false, "There is XSS");
|
|
|
|
@@ -115,17 +97,11 @@ Deno.test({
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "island with fragment as root",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("island with fragment as root", async () => {
|
|
|
|
|
await withPage(async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/islands/root_fragment`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
await page.goto(`${address}/islands/root_fragment`);
|
|
|
|
|
|
|
|
|
|
const clickableSelector = "#root-fragment-click-me";
|
|
|
|
|
|
|
|
|
@@ -136,19 +112,14 @@ Deno.test({
|
|
|
|
|
await clickWhenListenerReady(page, clickableSelector);
|
|
|
|
|
await waitForText(page, `#island-parent`, "HelloWorldI'm rendered now");
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "island with fragment as root and conditional child first",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test(
|
|
|
|
|
"island with fragment as root and conditional child first",
|
|
|
|
|
async () => {
|
|
|
|
|
await withPage(async (page, address) => {
|
|
|
|
|
await page.goto(
|
|
|
|
|
`${address}/islands/root_fragment_conditional_first`,
|
|
|
|
|
{
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const clickableSelector = "#root-fragment-conditional-first-click-me";
|
|
|
|
@@ -164,139 +135,94 @@ Deno.test({
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "island that returns `null`",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("island that returns `null`", async () => {
|
|
|
|
|
await withPage(async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/islands/returning_null`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await page.goto(`${address}/islands/returning_null`);
|
|
|
|
|
await page.waitForSelector(".added-by-use-effect");
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "island using `npm:` specifiers",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("island using `npm:` specifiers", async () => {
|
|
|
|
|
await withPageName("./tests/fixture_npm/main.ts", async (page, address) => {
|
|
|
|
|
await page.setJavaScriptEnabled(false);
|
|
|
|
|
await page.goto(address, { waitUntil: "networkidle2" });
|
|
|
|
|
assert(await page.waitForSelector("#server-true"));
|
|
|
|
|
await page.goto(address);
|
|
|
|
|
await page.waitForSelector("#server-true");
|
|
|
|
|
|
|
|
|
|
await page.setJavaScriptEnabled(true);
|
|
|
|
|
await page.reload({ waitUntil: "networkidle2" });
|
|
|
|
|
assert(await page.waitForSelector("#browser-true"));
|
|
|
|
|
await page.reload();
|
|
|
|
|
await page.waitForSelector("#browser-true");
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "works with older preact-render-to-string v5",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("works with older preact-render-to-string v5", async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_preact_rts_v5/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(address, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
await page.goto(address);
|
|
|
|
|
await page.waitForSelector("#foo");
|
|
|
|
|
await waitForText(page, "#foo", "it works");
|
|
|
|
|
+await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "pass single JSX child to island",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("pass single JSX child to island", async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_jsx_child`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
await page.goto(`${address}/island_jsx_child`);
|
|
|
|
|
await page.waitForSelector(".island");
|
|
|
|
|
await waitForText(page, ".island", "it works");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "pass multiple JSX children to island",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("pass multiple JSX children to island", async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_jsx_children`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
await page.goto(`${address}/island_jsx_children`);
|
|
|
|
|
await page.waitForSelector(".island");
|
|
|
|
|
|
|
|
|
|
await delay(100);
|
|
|
|
|
const text = await page.$eval(".island", (el) => el.textContent);
|
|
|
|
|
assertEquals(text, "it works");
|
|
|
|
|
await waitForText(page, ".island", "it works");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "pass multiple text JSX children to island",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("pass multiple text JSX children to island", async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_jsx_text`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
await page.goto(`${address}/island_jsx_text`);
|
|
|
|
|
await page.waitForSelector(".island");
|
|
|
|
|
|
|
|
|
|
await delay(100);
|
|
|
|
|
const text = await page.$eval(".island", (el) => el.textContent);
|
|
|
|
|
assertEquals(text, "it works");
|
|
|
|
|
await waitForText(page, ".island", "it works");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "render island in island",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("render island in island", async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_in_island`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
await page.goto(`${address}/island_in_island`);
|
|
|
|
|
await page.waitForSelector(".island");
|
|
|
|
|
await waitForText(page, ".island .island p", "it works");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "render island inside island definition",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("render island inside island definition", async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_in_island_definition`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
await page.goto(`${address}/island_in_island_definition`);
|
|
|
|
|
await page.waitForSelector(".island");
|
|
|
|
|
|
|
|
|
|
await waitForText(page, ".island .island p", "it works");
|
|
|
|
@@ -304,9 +230,9 @@ Deno.test({
|
|
|
|
|
// Check that there is no duplicated content which could happen
|
|
|
|
|
// when islands aren't initialized correctly
|
|
|
|
|
await waitForText(page, "#page", "it works");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
|
await page.goto(`${address}/dropdown`);
|
|
|
|
|
await page.waitForSelector("button");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
|
|
|
|
|
const doc = parseHtml(await page.content());
|
|
|
|
|
assertNotSelector(doc, ".result");
|
|
|
|
|
|
|
|
|
|
await page.click("button");
|
|
|
|
|
await page.waitForSelector(".result");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name:
|
|
|
|
|
Deno.test(
|
|
|
|
|
"render island with JSX children that render another island with JSX children",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_jsx_island_jsx`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
await page.goto(`${address}/island_jsx_island_jsx`);
|
|
|
|
|
await page.waitForSelector(".island");
|
|
|
|
|
|
|
|
|
|
await waitForText(
|
|
|
|
@@ -343,39 +267,34 @@ Deno.test({
|
|
|
|
|
".island .server .island .server p",
|
|
|
|
|
"it works",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "render sibling islands",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("render sibling islands", async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_siblings`, {
|
|
|
|
|
waitUntil: "networkidle2",
|
|
|
|
|
});
|
|
|
|
|
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({
|
|
|
|
|
name: "render sibling islands that render nothing initially",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("render sibling islands that render nothing initially", async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_conditional`);
|
|
|
|
|
await page.waitForSelector(".island");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
|
|
|
|
|
await page.click("button");
|
|
|
|
|
|
|
|
|
@@ -383,14 +302,12 @@ Deno.test({
|
|
|
|
|
// to assert correct ordering. The "island content" should
|
|
|
|
|
// be left of "Toggle"
|
|
|
|
|
await waitForText(page, "#page", "island contentToggle");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "serialize inner island props",
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("serialize inner island props", async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
@@ -398,39 +315,33 @@ Deno.test({
|
|
|
|
|
await page.waitForSelector(".island");
|
|
|
|
|
|
|
|
|
|
await waitForText(page, ".island .island p", "it works");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "render island inside island when passed as fn child",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("render island inside island when passed as fn child", async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_fn_child`);
|
|
|
|
|
await page.waitForSelector(".island");
|
|
|
|
|
await waitForText(page, "#page", "it works");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "render nested islands in correct order",
|
|
|
|
|
|
|
|
|
|
async fn(_t) {
|
|
|
|
|
Deno.test("render nested islands in correct order", async () => {
|
|
|
|
|
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");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
@@ -442,43 +353,46 @@ Deno.test({
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_conditional_lazy`);
|
|
|
|
|
await waitForText(page, ".island p", "island content");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
|
|
|
|
|
await page.click("button");
|
|
|
|
|
await waitForText(page, ".island p", "server rendered");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "revive island in lazy server rendered children conditionally",
|
|
|
|
|
|
|
|
|
|
async fn() {
|
|
|
|
|
Deno.test(
|
|
|
|
|
"revive island in lazy server rendered children conditionally",
|
|
|
|
|
async () => {
|
|
|
|
|
await withPageName(
|
|
|
|
|
"./tests/fixture_island_nesting/main.ts",
|
|
|
|
|
async (page, address) => {
|
|
|
|
|
await page.goto(`${address}/island_conditional_lazy_island`);
|
|
|
|
|
await waitForText(page, ".island p", "island content");
|
|
|
|
|
await page.waitForSelector(".mounted");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
|
|
|
|
|
await page.click("button");
|
|
|
|
|
await waitForText(page, ".island .server", "server rendered");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
|
|
|
|
|
await page.click("button.counter");
|
|
|
|
|
await waitForText(page, ".island .count", "1");
|
|
|
|
|
await assertNoPageComments(page);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
|
name: "revive boolean attributes",
|
|
|
|
|
|
|
|
|
|
async fn() {
|
|
|
|
|
Deno.test("revive boolean attributes", async () => {
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
const checked = await page.$eval(
|
|
|
|
|
"input[type=checkbox]",
|
|
|
|
@@ -509,7 +423,6 @@ Deno.test({
|
|
|
|
|
assertEquals(selected, "bar", "'bar' value is not selected");
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Deno.test("throws when passing non-jsx children to an island", async (t) => {
|
|
|
|
|