import { describe } from "bun:test";
import { itBundled } from "./expectBundled";
describe("bundler", () => {
for (const backend of ["api", "cli"] as const) {
itBundled(`compile/${backend}/HTMLServerBasic`, {
compile: true,
backend: backend,
files: {
"/entry.ts": /* js */ `
import index from "./index.html";
using server = Bun.serve({
port: 0,
routes: {
"/": index,
},
});
const res = await fetch(server.url);
console.log("Status:", res.status);
console.log("Content-Type:", res.headers.get("content-type"));
const html = await res.text();
console.log("Has HTML tag:", html.includes(""));
console.log("Has h1:", html.includes("Hello HTML"));
`,
"/index.html": /* html */ `
Test Page
Hello HTML
`,
"/styles.css": /* css */ `
body {
background: blue;
}
`,
"/app.js": /* js */ `
console.log("Client app loaded");
`,
},
run: {
stdout: "Status: 200\nContent-Type: text/html;charset=utf-8\nHas HTML tag: true\nHas h1: true",
},
});
itBundled(`compile/${backend}/HTMLServerMultipleRoutes`, {
compile: true,
backend: backend,
files: {
"/entry.ts": /* js */ `
import home from "./home.html";
import about from "./about.html";
using server = Bun.serve({
port: 0,
routes: {
"/": home,
"/about": about,
},
});
// Test home route
const homeRes = await fetch(server.url);
console.log("Home status:", homeRes.status);
const homeHtml = await homeRes.text();
console.log("Home has content:", homeHtml.includes("Home Page"));
// Test about route
const aboutRes = await fetch(server.url + "about");
console.log("About status:", aboutRes.status);
const aboutHtml = await aboutRes.text();
console.log("About has content:", aboutHtml.includes("About Page"));
`,
"/home.html": /* html */ `
Home
Home Page
`,
"/about.html": /* html */ `
About
About Page
`,
"/styles.css": /* css */ `
body {
margin: 0;
font-family: sans-serif;
}
`,
"/app.js": /* js */ `
console.log("App loaded");
`,
},
run: {
stdout: "Home status: 200\nHome has content: true\nAbout status: 200\nAbout has content: true",
},
});
}
});