-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- end-to-end build & dev in CI - better type-checking Related to #35
- Loading branch information
Showing
6 changed files
with
87 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { assert } from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { build } from "./build.ts"; | ||
|
||
const base = "mononykus/"; | ||
const site_dir = "src/_site"; | ||
|
||
Deno.test({ | ||
name: "Able to build the current project", | ||
fn: async () => { | ||
await build({ base, site_dir }); | ||
}, | ||
}); | ||
|
||
Deno.test({ | ||
name: "Able to develop the current project", | ||
fn: async () => { | ||
const command = new Deno.Command( | ||
Deno.execPath(), | ||
{ | ||
args: [ | ||
"task", | ||
"dev", | ||
], | ||
stdout: "null", | ||
stderr: "null", | ||
}, | ||
); | ||
|
||
const process = command.spawn(); | ||
|
||
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(); | ||
await process.output(); | ||
|
||
assert(html.startsWith( | ||
"<!DOCTYPE html>", | ||
)); | ||
assert(html.includes( | ||
"<title>Mononykus – Deno + Svelte</title>", | ||
)); | ||
}, | ||
sanitizeResources: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
import { Handler } from "https://deno.land/[email protected]/http/server.ts"; | ||
import { serveDir } from "https://deno.land/[email protected]/http/file_server.ts"; | ||
import { normalize as normalise } from "https://deno.land/[email protected]/path/posix.ts"; | ||
|
||
interface ServerOptions { | ||
base?: string; | ||
base: string; | ||
out_dir: string; | ||
} | ||
|
||
export const create_handler = ( | ||
{ base = "", out_dir }: ServerOptions, | ||
{ base, out_dir }: ServerOptions, | ||
): Handler => ((req) => { | ||
const url = new URL(req.url); | ||
|
||
if (url.pathname.startsWith("/" + base)) { | ||
if (url.pathname.startsWith(normalise("/" + base))) { | ||
return serveDir(req, { fsRoot: out_dir, urlRoot: base }); | ||
} else { | ||
return Response.redirect(new URL(base + url.pathname, url.origin)); | ||
return Response.redirect( | ||
new URL(normalise(base + url.pathname), url.origin), | ||
); | ||
} | ||
}); |