Skip to content

Commit

Permalink
Reinstate tests (#61)
Browse files Browse the repository at this point in the history
- simply run tasks
- make them work
- ensure we await for the server to have stopped
- run them locally 240 times to ensure they are not flaky
  • Loading branch information
mxdvl authored Dec 8, 2024
1 parent 0b5dd28 commit 68f4dd2
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ jobs:
- name: Lint
run: deno lint

- name: Test
run: deno test -A --no-check

- name: Check
run: deno check src/**.ts
12 changes: 12 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions src/build.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { assert, assertEquals } from "jsr:@std/assert";
import { delay } from "jsr:@std/async";

Deno.test({
name: "tasks",
async fn(test) {
await test.step({
name: "build",
async fn() {
const command = new Deno.Command("deno", {
args: ["task", "build"],
});
const { code } = await command.output();

assertEquals(code, 0);
},
});

await test.step({
name: "dev",
async fn() {
const command = new Deno.Command("deno", {
args: ["task", "dev"],
stdout: "null",
stderr: "null",
});

const process = command.spawn();

/**
* Represents a failing promise while we get a real one
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408
*/
const pending = new Response(null, { status: 408 });

let response = pending;
while (!response.ok) {
response = await fetch("http://localhost:4507/mononykus/")
.catch(() => pending);
await delay(12);
}

const html = await response.text();

assert(html.startsWith("<!DOCTYPE html>"));
assert(html.includes("<title>Mononykus – Deno + Svelte</title>"));

process.kill();

await process.output();
},
});
},
});
6 changes: 5 additions & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ export const watch = async (

await _rebuild();

Deno.serve({ port: 4507, signal }, create_handler({ base, out_dir }));
const { finished } = Deno.serve(
{ port: 4507, signal },
create_handler({ base, out_dir }),
);

const watcher = Deno.watchFs(site_dir);
signal.addEventListener("abort", () => {
Expand All @@ -183,6 +186,7 @@ export const watch = async (

console.log("\nShutting down gracefully, light as a feather…");
await esbuild.stop();
await finished;
};

if (import.meta.main) {
Expand Down

0 comments on commit 68f4dd2

Please sign in to comment.