mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-12-01 18:42:02 +00:00
### 1. Replace `XMLHttpRequest` with the modern `fetch` API for loading translation files #### Changes - **translator.js**: Use `fetch` with `async/await` instead of XHR callbacks - **loader.js**: Align URL handling and add error handling (follow-up to fetch migration) - **Tests**: Update infrastructure for `fetch` compatibility #### Benefits - Modern standard API - Cleaner, more readable code - Better error handling and fallback mechanisms ### 2. Migrate e2e tests to Playwright This wasn't originally planned for this PR, but is related. While investigating suspicious log entries which surfaced after the fetch migration I kept running into JSDOM’s limitations. That pushed me to migrate the E2E suite to Playwright instead. #### Changes - switch e2e harness to Playwright (`tests/e2e/helpers/global-setup.js`) - rewrite specs to use Playwright locators + shared `expectTextContent` - install Chromium via `npx playwright install --with-deps` in CI #### Benefits - much closer to real browser behaviour - and no more fighting JSDOM’s quirks
51 lines
1.6 KiB
JavaScript
51 lines
1.6 KiB
JavaScript
const delay = (time) => {
|
|
return new Promise((resolve) => setTimeout(resolve, time));
|
|
};
|
|
|
|
const runConfigCheck = async () => {
|
|
const serverProcess = await require("node:child_process").spawnSync("node", ["--run", "config:check"], { env: process.env });
|
|
return await serverProcess.status;
|
|
};
|
|
|
|
describe("App environment", () => {
|
|
let serverProcess;
|
|
|
|
beforeAll(async () => {
|
|
// Use fixed port 8080 (tests run sequentially)
|
|
const testPort = 8080;
|
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/default.js";
|
|
process.env.MM_PORT = testPort.toString();
|
|
serverProcess = await require("node:child_process").spawn("node", ["--run", "server"], { env: process.env, detached: true });
|
|
// we have to wait until the server is started
|
|
await delay(2000);
|
|
});
|
|
afterAll(async () => {
|
|
await process.kill(-serverProcess.pid);
|
|
});
|
|
|
|
it("get request from http://localhost:8080 should return 200", async () => {
|
|
const res = await fetch("http://localhost:8080");
|
|
expect(res.status).toBe(200);
|
|
});
|
|
|
|
it("get request from http://localhost:8080/nothing should return 404", async () => {
|
|
const res = await fetch("http://localhost:8080/nothing");
|
|
expect(res.status).toBe(404);
|
|
});
|
|
});
|
|
|
|
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);
|
|
});
|
|
|
|
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);
|
|
});
|
|
});
|