Loading...
Loading...
Guides writing HMR/Dev Server tests in test/bake/. Use when creating or modifying dev server, hot reloading, or bundling tests.
npx skill4agent add oven-sh/bun writing-dev-server-teststest/bake/bake-harness.tsdevTestprodTestdevAndProductionTestDevClienttest/bake/client-fixture.mjsClienttest/bake/dev/*.test.tstest/bake/dev-and-prod.tsbundle.test.tscss.test.tsplugins.test.tsecosystem.test.tsesm.test.tshtml.test.tsreact-spa.test.tssourcemap.test.tsimport { devTest, emptyHtmlFile } from "../bake-harness";
devTest("html file is watched", {
files: {
"index.html": emptyHtmlFile({
scripts: ["/script.ts"],
body: "<h1>Hello</h1>",
}),
"script.ts": `console.log("hello");`,
},
async test(dev) {
await dev.fetch("/").expect.toInclude("<h1>Hello</h1>");
await dev.patch("index.html", { find: "Hello", replace: "World" });
await dev.fetch("/").expect.toInclude("<h1>World</h1>");
await using c = await dev.client("/");
await c.expectMessage("hello");
await c.expectReload(async () => {
await dev.patch("index.html", { find: "World", replace: "Bar" });
});
await c.expectMessage("hello");
},
});filesdev.fetch()dev.client()dev.write/patch/deletec.expectMessage()c.expectReload()dev.write/patch/deletenode:fsdevTest("import then create", {
files: {
"index.html": `<!DOCTYPE html><html><head></head><body><script type="module" src="/script.ts"></script></body></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");
},
});errorsawait dev.delete("other.ts", {
errors: ['index.ts:1:16: error: Could not resolve: "./other"'],
});