-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathserve_test.ts
46 lines (39 loc) · 1.36 KB
/
serve_test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { assertEquals, assertStringIncludes } from "./test_deps.ts";
Deno.test("cli.ts serve <entrypoint> --port <port> --livereload-port <port> -- serves the site at the given port and livereload port", async () => {
const cmd = new Deno.Command(Deno.execPath(), {
args: [
"run",
"-A",
"cli.ts",
"serve",
"examples/simple/index.html",
"--port",
"4567",
"--livereload-port",
"34567",
],
stdout: "piped",
stderr: "inherit",
});
const p = cmd.spawn();
const textDecoder = new TextDecoder();
const r = p.stdout.getReader();
const log = textDecoder.decode((await r.read()).value);
console.log(log);
assertStringIncludes(log, "Server running");
let res = await fetch("http://localhost:4567/index.html");
assertEquals(
await res.text(),
`<!DOCTYPE html><html><head></head><body><div>aaa</div>\n<script src="http://localhost:34567/livereload.js"></script></body></html>`,
);
// Non existent path returns the same response as the main html.
// This is useful for apps which use client side routing.
res = await fetch("http://localhost:4567/asdf");
assertEquals(
await res.text(),
`<!DOCTYPE html><html><head></head><body><div>aaa</div>\n<script src="http://localhost:34567/livereload.js"></script></body></html>`,
);
p.kill();
await r.cancel();
await p.status;
});