// HTML tests are tests relating to HTML files themselves. import { devTest, emptyHtmlFile } from "../bake-harness"; devTest("html file is watched", { files: { "index.html": emptyHtmlFile({ scripts: ["/script.ts"], body: "
`,
"image.png": "FIRST",
},
async test(dev) {
await using c = await dev.client("/");
const url: string = await c.js`document.querySelector("img").src`;
expect(url).toBeString(); // image tag exists
await dev.fetch(url).expect.toBe("FIRST");
// Editing HTML causes reload but image still works
await c.expectReload(async () => {
await dev.patch("index.html", {
find: 'alt="test image"',
replace: 'alt="modified image"',
});
await dev.fetch("/").expect.toInclude('alt="modified image"');
});
// Editing image content causes a hard reload because the html must reflect the new image content
await c.expectReload(async () => {
await dev.patch("image.png", {
find: "FIRST",
replace: "SECOND",
});
});
const url2 = await c.js`document.querySelector("img").src`;
expect(url).not.toBe(url2);
await dev.fetch(url2).expect.toBe("SECOND");
await dev.fetch(url).expect404(); // TODO
},
});
devTest("image import in JS", {
files: {
"index.html": `
`,
"script.ts": `
import img from "./image.png";
console.log(img);
`,
"image.png": "FIRST",
},
async test(dev) {
await using c = await dev.client("/");
const img1 = await c.getStringMessage();
await dev.fetch(img1).expect.toBe("FIRST");
// Editing image content updates the image URL
await c.expectReload(async () => {
await dev.patch("image.png", {
find: "FIRST",
replace: "SECOND",
});
});
const img2 = await c.getStringMessage();
await dev.fetch(img2).expect.toBe("SECOND");
// await dev.fetch(img1).expect404();
},
});
devTest("import then create", {
files: {
"index.html": `
`,
"script.ts": `
import data from "./data";
console.log(data);
`,
},
async test(dev) {
const c = await dev.client("/", {
errors: ['script.ts:1:18: error: Could not resolve: "./data"'],
});
await c.expectReload(async () => {
await dev.write("data.ts", "export default 'data';");
});
await c.expectMessage("data");
},
});
devTest("external links", {
files: {
"index.html": `