-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathquick-start.spec.ts
More file actions
46 lines (42 loc) · 1.22 KB
/
Copy pathquick-start.spec.ts
File metadata and controls
46 lines (42 loc) · 1.22 KB
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 { spawn } from "node:child_process";
import {
describe,
vi,
assert,
afterAll,
afterEach,
expect,
test,
} from "vitest";
import { givePort } from "../tools/ports.ts";
describe("ESM Test", async () => {
let out = "";
const listener = (chunk: Buffer) => {
out += chunk.toString();
};
const quickStart = spawn("node", ["quick-start.ts"]);
quickStart.stdout.on("data", listener);
quickStart.stderr.on("data", listener);
await vi.waitFor(() => assert(out.includes(`Listening`)), { timeout: 1e4 });
const port = givePort("compat");
afterAll(async () => {
quickStart.stdout.removeListener("data", listener);
quickStart.stderr.removeListener("data", listener);
quickStart.kill();
await vi.waitFor(() => assert(quickStart.killed), { timeout: 1e4 });
});
afterEach(() => {
console.log(out);
out = "";
});
describe("Quick Start from Readme", () => {
test("Should handle valid GET request", async () => {
const response = await fetch(
`http://localhost:${port}/v1/hello?name=Rick`,
);
expect(response.status).toBe(200);
const json = await response.json();
expect(json).toEqual({ greetings: "Hello, Rick. Happy coding!" });
});
});
});