[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,6 +1,9 @@
const { expect } = require("playwright/test");
const helpers = require("../helpers/global-setup");
describe("Alert module", () => {
let page;
afterAll(async () => {
await helpers.stopApplication();
});
@@ -9,6 +12,7 @@ describe("Alert module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/alert/welcome_false.js");
await helpers.getDocument();
page = helpers.getPage();
});
it("should not show any welcome message", async () => {
@@ -16,8 +20,7 @@ describe("Alert module", () => {
await new Promise((resolve) => setTimeout(resolve, 1000));
// Check that no alert/notification elements are present
const alertElements = document.querySelectorAll(".ns-box .ns-box-inner .light.bright.small");
expect(alertElements).toHaveLength(0);
await expect(page.locator(".ns-box .ns-box-inner .light.bright.small")).toHaveCount(0);
});
});
@@ -25,15 +28,14 @@ describe("Alert module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/alert/welcome_true.js");
await helpers.getDocument();
page = helpers.getPage();
// Wait for the application to initialize
await new Promise((resolve) => setTimeout(resolve, 1000));
});
it("should show the translated welcome message", async () => {
const elem = await helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small");
expect(elem).not.toBeNull();
expect(elem.textContent).toContain("Welcome, start was successful!");
await expect(page.locator(".ns-box .ns-box-inner .light.bright.small")).toContainText("Welcome, start was successful!");
});
});
@@ -41,12 +43,11 @@ describe("Alert module", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/alert/welcome_string.js");
await helpers.getDocument();
page = helpers.getPage();
});
it("should show the custom welcome message", async () => {
const elem = await helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small");
expect(elem).not.toBeNull();
expect(elem.textContent).toContain("Custom welcome message!");
await expect(page.locator(".ns-box .ns-box-inner .light.bright.small")).toContainText("Custom welcome message!");
});
});
});