-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_app_test.ts
93 lines (79 loc) · 1.96 KB
/
_app_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
90
91
92
93
import { delay } from "https://deno.land/[email protected]/async/delay.ts";
import {
assertEquals,
assertThrows,
assertThrowsAsync,
} from "https://deno.land/[email protected]/testing/asserts.ts";
import App from "./_app.ts";
import { path } from "./deps.ts";
const cwd = path.dirname(new URL(import.meta.url).pathname);
Deno.test("appPath", () => {
{
const app = new App(".");
assertEquals(app.path(), cwd);
}
{
const app = new App("example");
assertEquals(app.path(), path.join(cwd, "example"));
}
{
const app = new App("/opt/app");
assertEquals(app.path(), "/opt/app");
assertEquals(app.path("routes"), "/opt/app/routes");
assertEquals(app.path("routes/.."), "/opt/app");
assertEquals(app.path("routes", "profile"), "/opt/app/routes/profile");
}
{
const app = new App("/opt/app");
assertEquals(app.path("/tmp"), "/tmp");
}
});
Deno.test("mount", async () => {
{
assertThrowsAsync(
async () => {
const app = new App(".");
await app.mount();
},
undefined,
"routes not found",
);
}
{
const app = new App("./example");
await app.mount();
assertEquals(app.config, {
port: 4500,
extension: ".ts",
methods: ["get", "post", "put", "delete", "patch"],
});
}
});
Deno.test("start", async () => {
const app = new App("./example", { port: 4400 });
app.start();
// allow the app to start
await delay(100);
// @ts-expect-error
const rid = app.server!.listener.rid;
const resources = Deno.resources();
assertEquals(resources[rid], "tcpListener");
app.stop();
});
Deno.test("main", async () => {
{
assertThrows(() => {
App.main(["fail"]);
});
}
{
const app = App.main(["start", "./example"]);
// allow the app to start
await delay(100);
// @ts-expect-error
const rid = app.server!.listener.rid;
const resources = Deno.resources();
assertEquals(resources[rid], "tcpListener");
app.stop();
}
});