[core] refactor: replace XMLHttpRequest with fetch and migrate e2e tests to Playwright (#3950)

### 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
This commit is contained in:
Kristjan ESPERANTO
2025-11-08 21:59:05 +01:00
committed by GitHub
parent 2b08288346
commit f29f424a62
31 changed files with 508 additions and 361 deletions

View File

@@ -1,19 +1,20 @@
const { expect } = require("playwright/test");
const helpers = require("../helpers/global-setup");
describe("Compliments module", () => {
let page;
/**
* move similar tests in function doTest
* @param {Array} complimentsArray The array of compliments.
* @returns {boolean} result
* @returns {Promise<void>}
*/
const doTest = async (complimentsArray) => {
let elem = await helpers.waitForElement(".compliments");
expect(elem).not.toBeNull();
elem = await helpers.waitForElement(".module-content");
expect(elem).not.toBeNull();
expect(complimentsArray).toContain(elem.textContent);
return true;
await expect(page.locator(".compliments")).toBeVisible();
const contentLocator = page.locator(".module-content");
await contentLocator.waitFor({ state: "visible" });
const content = await contentLocator.textContent();
expect(complimentsArray).toContain(content);
};
afterAll(async () => {
@@ -25,10 +26,11 @@ describe("Compliments module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js");
await helpers.getDocument();
page = helpers.getPage();
});
it("shows anytime because if configure empty parts of day compliments and set anytime compliments", async () => {
await expect(doTest(["Anytime here"])).resolves.toBe(true);
await doTest(["Anytime here"]);
});
});
@@ -36,10 +38,11 @@ describe("Compliments module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js");
await helpers.getDocument();
page = helpers.getPage();
});
it("shows anytime compliments", async () => {
await expect(doTest(["Anytime here"])).resolves.toBe(true);
await doTest(["Anytime here"]);
});
});
});
@@ -48,10 +51,11 @@ describe("Compliments module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_remote.js");
await helpers.getDocument();
page = helpers.getPage();
});
it("should show compliments from a remote file", async () => {
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
await doTest(["Remote compliment file works!"]);
});
});
@@ -60,10 +64,11 @@ describe("Compliments module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_specialDayUnique_false.js");
await helpers.getDocument();
page = helpers.getPage();
});
it("compliments array can contain all values", async () => {
await expect(doTest(["Special day message", "Typical message 1", "Typical message 2", "Typical message 3"])).resolves.toBe(true);
await doTest(["Special day message", "Typical message 1", "Typical message 2", "Typical message 3"]);
});
});
@@ -71,10 +76,11 @@ describe("Compliments module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_specialDayUnique_true.js");
await helpers.getDocument();
page = helpers.getPage();
});
it("compliments array contains only special value", async () => {
await expect(doTest(["Special day message"])).resolves.toBe(true);
await doTest(["Special day message"]);
});
});
@@ -82,10 +88,11 @@ describe("Compliments module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_e2e_cron_entry.js");
await helpers.getDocument();
page = helpers.getPage();
});
it("compliments array contains only special value", async () => {
await expect(doTest(["anytime cron"])).resolves.toBe(true);
await doTest(["anytime cron"]);
});
});
});
@@ -95,10 +102,11 @@ describe("Compliments module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_file.js");
await helpers.getDocument();
page = helpers.getPage();
});
it("shows 'Remote compliment file works!' as only anytime list set", async () => {
//await helpers.startApplication("tests/configs/modules/compliments/compliments_file.js", "01 Jan 2022 10:00:00 GMT");
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
await doTest(["Remote compliment file works!"]);
});
// afterAll(async () =>{
// await helpers.stopApplication()
@@ -109,12 +117,13 @@ describe("Compliments module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js");
await helpers.getDocument();
page = helpers.getPage();
});
it("shows 'test in morning' as test time set to 10am", async () => {
//await helpers.startApplication("tests/configs/modules/compliments/compliments_file_change.js", "01 Jan 2022 10:00:00 GMT");
await expect(doTest(["Remote compliment file works!"])).resolves.toBe(true);
await doTest(["Remote compliment file works!"]);
await new Promise((r) => setTimeout(r, 10000));
await expect(doTest(["test in morning"])).resolves.toBe(true);
await doTest(["test in morning"]);
});
// afterAll(async () =>{
// await helpers.stopApplication()