describe("serves application when running main", () => {
it("should serve the application", async () => {
const command = new Deno.Command(Deno.execPath(), {
args: ["run", "-A", resolve(import.meta.dirname!, "./main.ts")],
stdout: "piped",
stderr: "piped",
});
await using child = command.spawn();
const stdout = mergeReadableStreams(child.stdout, child.stderr)
.pipeThrough(new TextDecoderStream())
.pipeThrough(new TextLineStream());
// Wait for server to start by monitoring stdout
for await (const line of stdout) {
if (line.includes("Listening on")) {
break;
}
}
const res = await fetch("http://localhost:8000/");
assertEquals(res.status, 200);
assertEquals(await res.text(), "Hello, World!");
});
});
describe("serves application when running main", () => {
it("should serve the application", async () => {
const command = new Deno.Command(Deno.execPath(), {
args: ["run", "-A", resolve(import.meta.dirname!, "./main.ts")],
stdout: "piped",
stderr: "piped",
});
await using child = command.spawn();
const stdout = mergeReadableStreams(child.stdout, child.stderr)
.pipeThrough(new TextDecoderStream())
.pipeThrough(new TextLineStream());
// Wait for server to start by monitoring stdout
for await (const line of stdout) {
if (line.includes("Listening on")) {
break;
}
}
const res = await fetch("http://localhost:8000/");
assertEquals(res.status, 200);
assertEquals(await res.text(), "Hello, World!");
});
});