-
-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathquick-start.spec.ts
More file actions
38 lines (34 loc) · 1.15 KB
/
Copy pathquick-start.spec.ts
File metadata and controls
38 lines (34 loc) · 1.15 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
import { spawn } from "node:child_process";
import { givePort } from "../tools/ports";
describe("CJS Test", async () => {
let out = "";
const listener = (chunk: Buffer) => {
out += chunk.toString();
};
const quickStart = spawn("node", ["quick-start.js"]);
quickStart.stdout.on("data", listener);
quickStart.stderr.on("data", listener);
const port = givePort("cjs");
await vi.waitFor(() => assert(out.includes(`Listening`)), { timeout: 1e4 });
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 ({ signal }) => {
const response = await fetch(
`http://localhost:${port}/v1/hello?name=Rick`,
{ signal },
);
expect(response.status).toBe(200);
const json = await response.json();
expect(json).toEqual({ greetings: "Hello, Rick. Happy coding!" });
});
});
});