forked from denoland/docland
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ts
89 lines (74 loc) · 2.55 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright 2021 the Deno authors. All rights reserved. MIT license.
import { assertEquals, assertStringIncludes } from "./deps_test.ts";
import { app } from "./main.ts";
import { assert } from "./util.ts";
let start: Promise<string> | undefined;
let close: AbortController | undefined;
function setup(): Promise<string> {
if (start) {
return start;
}
let resolve: (value: string | PromiseLike<string>) => void;
start = new Promise((res) => resolve = res);
close = new AbortController();
// deno-lint-ignore no-explicit-any
function onListen({ secure, hostname, port }: any) {
app.removeEventListener("listen", onListen);
const url = `${secure ? "https" : "http"}://${hostname}:${port}/`;
resolve(url);
}
app.addEventListener("listen", onListen);
app.listen({ signal: close.signal, port: 5001 });
return start;
}
function teardown() {
if (!close) {
return;
}
close.abort();
close = undefined;
}
Deno.test({
name: "route testing",
async fn() {
const server = await setup();
let res = await fetch(server);
assertEquals(res.status, 200);
assertStringIncludes(await res.text(), ">Deno Doc<");
res = await fetch(`${server}deno/stable`);
assertEquals(res.status, 200);
assertStringIncludes(
await res.text(),
"<title>Deno CLI APIs | Deno Doc</title>",
);
// validate that badge.svg is available
res = await fetch(`${server}badge.svg`);
assertEquals(res.status, 200);
assertEquals(res.headers.get("content-type"), "image/svg+xml");
await res.arrayBuffer();
// validate that builtin doc nodes get merged properly
res = await fetch(`${server}deno/stable/~/Deno.connect`);
assertEquals(res.status, 200);
let text = await res.text();
assertStringIncludes(text, ">Deno.connect<");
// validate that namespaced type references are resolved
assertStringIncludes(text, `href="/deno/stable/~/Deno.ConnectOptions"`);
// doc query URLs are redirected to perm-link of the redirected URL
res = await fetch(
`${server}doc?url=https%3A%2F%2Fdeno.land%2Fstd%2Ftesting%2Fasserts.ts`,
);
assertEquals(res.status, 200);
assert(
res.url.match(
/http:\/{2}(0\.){3}0:5001\/https:\/{2}deno\.land\/std@\d+\.\d+\.\d+\/testing\/asserts\.ts/,
),
);
await res.text();
// valid results for non-index modules
res = await fetch(`${server}https://deno.land/[email protected]/http/server.ts`);
assertEquals(res.status, 200);
text = await res.text();
assertStringIncludes(text, `Server">Server</a>`);
teardown();
},
});