23 lines
1.2 KiB
JavaScript
23 lines
1.2 KiB
JavaScript
const test = require("node:test");
|
|
const assert = require("node:assert");
|
|
const http = require("node:http");
|
|
const { handler } = require("../src/server.js");
|
|
|
|
function get(path) {
|
|
return new Promise((resolve) => {
|
|
const s = http.createServer(handler).listen(0, () => {
|
|
http.get({ port: s.address().port, path }, (r) => {
|
|
let b = ""; r.on("data", (d) => (b += d)); r.on("end", () => { s.close(); resolve({ status: r.statusCode, body: b }); });
|
|
});
|
|
});
|
|
});
|
|
}
|
|
test("Сценарий: healthz отвечает 200", async () => { assert.equal((await get("/healthz")).status, 200); });
|
|
test("Сценарий: главная показывает страницу продукта", async () => {
|
|
const r = await get("/"); assert.equal(r.status, 200); assert.match(r.body, /Как проверить/);
|
|
});
|
|
test("Сценарий: язык переключается", async () => { assert.match((await get("/?lang=en")).body, /How to check/); });
|
|
test("Сценарий: неизвестный адрес — 404", async () => {
|
|
const r = await get("/x"); assert.equal(r.status, 404); assert.match(r.body, /Такой страницы нет/);
|
|
});
|