Skip to content

Commit

Permalink
tests: end-to-end build & dev
Browse files Browse the repository at this point in the history
and run them in CI
  • Loading branch information
mxdvl committed Apr 27, 2023
1 parent 13f2c49 commit 9cc2417
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/integrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ jobs:

- name: Lint
run: deno lint

- name: Test
run: deno test -A
3 changes: 3 additions & 0 deletions deno.lock

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

69 changes: 69 additions & 0 deletions src/build.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { assert } from "https://deno.land/[email protected]/testing/asserts.ts";

const site = "--site=src/_site";
const build = "src/build.ts";

Deno.test({
name: "Able to build the current project",
permissions: { run: true },
fn: async () => {
const process = Deno.run({
cmd: ["deno", "run", "-A", build, site],
stdout: "null",
stderr: "null",
});

const { success } = await process.status();
assert(success);
process.close();
},
});

Deno.test({
name: "Able to develop the current project",
permissions: { run: true, net: true },
fn: async () => {
const process = Deno.run({
cmd: [
"deno",
"run",
"-A",
build,
site,
"--dev",
"--base=mononykus",
],
stdout: "null",
stderr: "null",
});

await new Promise<void>((resolve) => {
const check_if_port_is_open = async () => {
try {
const { status } = await fetch("http://localhost:4507/mononykus/", {
method: "HEAD",
});
if (status === 200) resolve();
} catch (_) {
setTimeout(check_if_port_is_open, 60);
}
};
return check_if_port_is_open();
});

const response = await fetch("http://localhost:4507/mononykus/");

const html = await response.text();

process.kill();
process.close();

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

0 comments on commit 9cc2417

Please sign in to comment.