Files
MagicMirror/tests/e2e/serveronly_spec.js
T

52 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-07-01 21:17:31 +02:00
const delay = (time) => {
return new Promise((resolve) => setTimeout(resolve, time));
};
2025-09-11 21:50:11 +02:00
const runConfigCheck = async () => {
const serverProcess = await require("node:child_process").spawnSync("node", ["--run", "config:check"], { env: process.env });
return await serverProcess.status;
};
2023-07-01 21:17:31 +02:00
describe("App environment", () => {
let serverProcess;
2025-11-03 19:47:01 +01:00
2023-07-01 21:17:31 +02:00
beforeAll(async () => {
2025-11-03 19:47:01 +01:00
// Use fixed port 8080 (tests run sequentially)
const testPort = 8080;
2023-07-01 21:17:31 +02:00
process.env.MM_CONFIG_FILE = "tests/configs/default.js";
2025-11-03 19:47:01 +01:00
process.env.MM_PORT = testPort.toString();
serverProcess = await require("node:child_process").spawn("node", ["--run", "server"], { env: process.env, detached: true });
2024-09-18 07:37:09 +02:00
// we have to wait until the server is started
2023-07-01 21:17:31 +02:00
await delay(2000);
});
2023-07-01 21:17:31 +02:00
afterAll(async () => {
await process.kill(-serverProcess.pid);
});
it("get request from http://localhost:8080 should return 200", async () => {
2023-10-01 20:13:41 +02:00
const res = await fetch("http://localhost:8080");
2023-07-01 21:17:31 +02:00
expect(res.status).toBe(200);
});
it("get request from http://localhost:8080/nothing should return 404", async () => {
2023-10-01 20:13:41 +02:00
const res = await fetch("http://localhost:8080/nothing");
2023-07-01 21:17:31 +02:00
expect(res.status).toBe(404);
});
});
2025-09-11 13:08:56 +02:00
describe("Check config", () => {
it("config check should return without errors", async () => {
process.env.MM_CONFIG_FILE = "tests/configs/default.js";
const exitCode = await runConfigCheck();
expect(exitCode).toBe(0);
2025-09-11 21:50:11 +02:00
});
it("config check should fail with non existent config file", async () => {
process.env.MM_CONFIG_FILE = "tests/configs/not_exists.js";
const exitCode = await runConfigCheck();
expect(exitCode).toBe(1);
2025-09-11 13:08:56 +02:00
});
});