tests: ensure asset mapping works correctly in islands client side (#245)

This commit is contained in:
Sylvain Cau
2022-06-22 12:02:51 +02:00
committed by GitHub
parent 871985a172
commit 6bca35be0f
2 changed files with 23 additions and 1 deletions
+2
View File
@@ -1,12 +1,14 @@
/** @jsx h */ /** @jsx h */
import { h } from "preact"; import { h } from "preact";
import Counter from "../../islands/Counter.tsx"; import Counter from "../../islands/Counter.tsx";
import Test from "../../islands/Test.tsx";
export default function Home() { export default function Home() {
return ( return (
<div> <div>
<Counter id="counter1" start={3} /> <Counter id="counter1" start={3} />
<Counter id="counter2" start={10} /> <Counter id="counter2" start={10} />
<Test message="" />
</div> </div>
); );
} }
+21 -1
View File
@@ -1,4 +1,10 @@
import { assert, delay, puppeteer, TextLineStream } from "./deps.ts"; import {
assert,
assertStringIncludes,
delay,
puppeteer,
TextLineStream,
} from "./deps.ts";
Deno.test({ Deno.test({
name: "island tests", name: "island tests",
@@ -52,6 +58,20 @@ Deno.test({
await counterTest("counter2", 10); await counterTest("counter2", 10);
}); });
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("http://localhost:8000/islands"));
const body = await resp.text();
const imgFilePath = body.match(/img id="img-in-island" src="(.*?)"/)
?.[1]!;
assertStringIncludes(srcString, imgFilePath);
});
await browser.close(); await browser.close();
await lines.cancel(); await lines.cancel();