mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-23 21:50:24 +00:00
Release 2.32.0 (#3826)
## [2.32.0] - 2025-07-01 Thanks to: @bughaver, @bugsounet, @khassel, @KristjanESPERANTO, @plebcity, @rejas, @sdetweil. > ⚠️ This release needs nodejs version `v22.14.0 or higher` ### Added - [config] Allow to change module order for final renderer (or dynamically with CSS): Feature `order` in config (#3762) - [clock] Added option 'disableNextEvent' to hide next sun event (#3769) - [clock] Implement short syntax for clock week (#3775) ### Changed - [refactor] Simplify module loading process (#3766) - Use `node --run` instead of `npm run` (#3764) and adapt `start:dev` script (#3773) - [workflow] Run linter and spellcheck with LTS node version (#3767) - [workflow] Split "Run test" step into two steps for more clarity (#3767) - [linter] Review linter setup (#3783) - Fix command to lint markdown in `CONTRIBUTING.md` - Re-activate JSDoc linting and fix linting issues - Refactor ESLint config to use `defineConfig` and `globalIgnores` - Replace `eslint-plugin-import` with `eslint-plugin-import-x` - Switch Stylelint config to flat format and simplify Stylelint scripts - [workflow] Replace Node.js version v23 with v24 (#3770) - [refactor] Replace deprecated constants `fs.F_OK` and `fs.R_OK` (#3789) - [refactor] Replace `ansis` with built-in function `util.styleText` (#3793) - [core] Integrate stuff from `vendor` and `fonts` folders into main `package.json`, simplifies install and maintaining dependencies (#3795, #3805) - [l10n] Complete translations (with the help of translation tools) (#3794) - [refactor] Refactored `calendarfetcherutils` in Calendar module to handle timezones better (#3806) - Removed as many of the date conversions as possible - Use `moment-timezone` when calculating recurring events, this will fix problems from the past with offsets and DST not being handled properly - Added some tests to test the behavior of the refactored methods to make sure the correct event dates are returned - [linter] Enable ESLint rule `no-console` and replace `console` with `Log` in some files (#3810) - [tests] Review and refactor translation tests (#3792) ### Fixed - [fix] Handle spellcheck issues (#3783) - [calendar] fix fullday event rrule until with timezone offset (#3781) - [feat] Add rule `no-undef` in config file validation to fix #3785 (#3786) - [fonts] Fix `roboto.css` to avoid error message `Unknown descriptor 'var(' in @font-face rule.` in firefox console (#3787) - [tests] Fix and refactor e2e test `Same keys` in `translations_spec.js` (#3809) - [tests] Fix e2e tests newsfeed and calendar to exit without open handles (#3817) ### Updated - [core] Update dependencies including electron to v36 (#3774, #3788, #3811, #3804, #3815, #3823) - [core] Update package type to `commonjs` - [logger] Review factory code part: use `switch/case` instead of `if/else if` (#3812) --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Michael Teeuw <michael@xonaymedia.nl> Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ross Younger <crazyscot@gmail.com> Co-authored-by: Veeck <github@veeck.de> Co-authored-by: Bugsounet - Cédric <github@bugsounet.fr> Co-authored-by: jkriegshauser <joshuakr@nvidia.com> Co-authored-by: illimarkangur <116028111+illimarkangur@users.noreply.github.com> Co-authored-by: sam detweiler <sdetweil@gmail.com> Co-authored-by: vppencilsharpener <tim.pray@gmail.com> Co-authored-by: veeck <michael.veeck@nebenan.de> Co-authored-by: Paranoid93 <6515818+Paranoid93@users.noreply.github.com> Co-authored-by: Brian O'Connor <btoconnor@users.noreply.github.com> Co-authored-by: WallysWellies <59727507+WallysWellies@users.noreply.github.com> Co-authored-by: Jason Stieber <jrstieber@gmail.com> Co-authored-by: jargordon <50050429+jargordon@users.noreply.github.com> Co-authored-by: Daniel <32464403+dkallen78@users.noreply.github.com> Co-authored-by: Ryan Williams <65094007+ryan-d-williams@users.noreply.github.com> Co-authored-by: Panagiotis Skias <panagiotis.skias@gmail.com> Co-authored-by: Marc Landis <dirk.rettschlag@gmail.com> Co-authored-by: HeikoGr <20295490+HeikoGr@users.noreply.github.com> Co-authored-by: Pedro Lamas <pedrolamas@gmail.com> Co-authored-by: veeck <gitkraken@veeck.de> Co-authored-by: Magnus <34011212+MagMar94@users.noreply.github.com> Co-authored-by: Ikko Eltociear Ashimine <eltociear@gmail.com> Co-authored-by: DevIncomin <56730075+Developer-Incoming@users.noreply.github.com> Co-authored-by: Nathan <n8nyoung@gmail.com> Co-authored-by: mixasgr <mixasgr@users.noreply.github.com> Co-authored-by: Savvas Adamtziloglou <savvas-gr@greeklug.gr> Co-authored-by: Konstantinos <geraki@gmail.com> Co-authored-by: OWL4C <124401812+OWL4C@users.noreply.github.com> Co-authored-by: BugHaver <43462320+bughaver@users.noreply.github.com> Co-authored-by: BugHaver <43462320+lsaadeh@users.noreply.github.com> Co-authored-by: Koen Konst <koenspero@gmail.com> Co-authored-by: Koen Konst <c.h.konst@avisi.nl>
This commit is contained in:
@@ -23,18 +23,18 @@ describe("AnimateCSS integration Test", () => {
|
||||
let styles = window.getComputedStyle(elem);
|
||||
|
||||
if (animationIn && animationIn !== "") {
|
||||
expect(styles._values["animation-name"]).toBe(animationIn);
|
||||
expect(styles._values.get("animation-name")).toBe(animationIn);
|
||||
} else {
|
||||
expect(styles._values["animation-name"]).toBeUndefined();
|
||||
expect(styles._values.get("animation-name")).toBeUndefined();
|
||||
}
|
||||
|
||||
if (animationOut && animationOut !== "") {
|
||||
elem = await helpers.waitForElement(`.compliments.animate__animated.animate__${animationOut}`);
|
||||
expect(elem).not.toBeNull();
|
||||
styles = window.getComputedStyle(elem);
|
||||
expect(styles._values["animation-name"]).toBe(animationOut);
|
||||
expect(styles._values.get("animation-name")).toBe(animationOut);
|
||||
} else {
|
||||
expect(styles._values["animation-name"]).toBeUndefined();
|
||||
expect(styles._values.get("animation-name")).toBeUndefined();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
@@ -3,7 +3,7 @@ const helpers = require("./helpers/global-setup");
|
||||
describe("All font files from roboto.css should be downloadable", () => {
|
||||
const fontFiles = [];
|
||||
// Statements below filters out all 'url' lines in the CSS file
|
||||
const fileContent = require("node:fs").readFileSync(`${__dirname}/../../fonts/roboto.css`, "utf8");
|
||||
const fileContent = require("node:fs").readFileSync(`${__dirname}/../../css/roboto.css`, "utf8");
|
||||
const regex = /\burl\(['"]([^'"]+)['"]\)/g;
|
||||
let match = regex.exec(fileContent);
|
||||
while (match !== null) {
|
||||
|
@@ -27,13 +27,21 @@ exports.startApplication = async (configFilename, exec) => {
|
||||
process.env.MM_CONFIG_FILE = configFilename;
|
||||
}
|
||||
process.env.mmTestMode = "true";
|
||||
process.setMaxListeners(0);
|
||||
if (exec) exec;
|
||||
global.app = require("../../../js/app");
|
||||
|
||||
return global.app.start();
|
||||
};
|
||||
|
||||
exports.stopApplication = async () => {
|
||||
exports.stopApplication = async (waitTime = 1000) => {
|
||||
if (global.window) {
|
||||
// no closing causes jest errors and memory leaks
|
||||
global.window.close();
|
||||
delete global.window;
|
||||
// give above closing some extra time to finish
|
||||
await new Promise((resolve) => setTimeout(resolve, waitTime));
|
||||
}
|
||||
if (!global.app) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* Suppresses errors concerning web server already shut down.
|
||||
* @param {string} err The error message.
|
||||
*/
|
||||
const mockError = (err) => {
|
||||
if (
|
||||
err.includes("ECONNREFUSED")
|
||||
|| err.includes("ECONNRESET")
|
||||
|| err.includes("socket hang up")
|
||||
|| err.includes("exports is not defined")
|
||||
|| err.includes("module is not defined")
|
||||
|| err.includes("write EPIPE")
|
||||
|| err.includes("AggregateError")
|
||||
|| err.includes("ERR_SOCKET_CONNECTION_TIMEOUT")
|
||||
) {
|
||||
jest.fn();
|
||||
} else {
|
||||
console.dir(err);
|
||||
}
|
||||
};
|
||||
|
||||
global.console = {
|
||||
log: jest.fn(),
|
||||
dir: console.dir,
|
||||
error: mockError,
|
||||
warn: console.warn,
|
||||
info: jest.fn(),
|
||||
debug: console.debug
|
||||
};
|
@@ -119,7 +119,6 @@ describe("Calendar module", () => {
|
||||
});
|
||||
});
|
||||
|
||||
process.setMaxListeners(0);
|
||||
for (let i = -12; i < 12; i++) {
|
||||
describe("Recurring event per timezone", () => {
|
||||
beforeAll(async () => {
|
||||
|
31
tests/e2e/modules/clock_de_spec.js
Normal file
31
tests/e2e/modules/clock_de_spec.js
Normal file
@@ -0,0 +1,31 @@
|
||||
const helpers = require("../helpers/global-setup");
|
||||
|
||||
describe("Clock set to german language module", () => {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("with showWeek config enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/de/clock_showWeek.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows week with correct format", async () => {
|
||||
const weekRegex = /^[0-9]{1,2}. Kalenderwoche$/;
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showWeek short config enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/de/clock_showWeek_short.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows week with correct format", async () => {
|
||||
const weekRegex = /^[0-9]{1,2}KW$/;
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
@@ -62,4 +62,16 @@ describe("Clock set to spanish language module", () => {
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showWeek short config enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek_short.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows week with correct format", async () => {
|
||||
const weekRegex = /^S[0-9]{1,2}$/;
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -40,9 +40,9 @@ describe("Clock module", () => {
|
||||
});
|
||||
|
||||
it("check for discreet elements of clock", async () => {
|
||||
let elemClock = helpers.waitForElement(".clock-hour-digital");
|
||||
let elemClock = await helpers.waitForElement(".clock-hour-digital");
|
||||
await expect(elemClock).not.toBeNull();
|
||||
elemClock = helpers.waitForElement(".clock-minute-digital");
|
||||
elemClock = await helpers.waitForElement(".clock-minute-digital");
|
||||
await expect(elemClock).not.toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -92,6 +92,9 @@ describe("Clock module", () => {
|
||||
it("should show the sun times", async () => {
|
||||
const elem = await helpers.waitForElement(".clock .digital .sun");
|
||||
expect(elem).not.toBeNull();
|
||||
|
||||
const elem2 = await helpers.waitForElement(".clock .digital .sun .fas.fa-sun");
|
||||
expect(elem2).not.toBeNull();
|
||||
});
|
||||
|
||||
it("should show the moon times", async () => {
|
||||
@@ -100,6 +103,21 @@ describe("Clock module", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showSunNextEvent disabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showSunNoEvent.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the sun times", async () => {
|
||||
const elem = await helpers.waitForElement(".clock .digital .sun");
|
||||
expect(elem).not.toBeNull();
|
||||
|
||||
const elem2 = document.querySelector(".clock .digital .sun .fas.fa-sun");
|
||||
expect(elem2).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showWeek config enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js");
|
||||
@@ -120,6 +138,26 @@ describe("Clock module", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showWeek short config enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_showWeek_short.js");
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the week in the correct format", async () => {
|
||||
const weekRegex = /^W[0-9]{1,2}$/;
|
||||
await expect(helpers.testMatch(".clock .week", weekRegex)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it("should show the week with the correct number of week of year", async () => {
|
||||
const currentWeekNumber = moment().week();
|
||||
const weekToShow = `W${currentWeekNumber}`;
|
||||
const elem = await helpers.waitForElement(".clock .week");
|
||||
expect(elem).not.toBeNull();
|
||||
expect(elem.textContent).toBe(weekToShow);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with analog clock face enabled", () => {
|
||||
beforeAll(async () => {
|
||||
await helpers.startApplication("tests/configs/modules/clock/clock_analog.js");
|
||||
@@ -127,7 +165,7 @@ describe("Clock module", () => {
|
||||
});
|
||||
|
||||
it("should show the analog clock face", async () => {
|
||||
const elem = helpers.waitForElement(".clock-circle");
|
||||
const elem = await helpers.waitForElement(".clock-circle");
|
||||
expect(elem).not.toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -139,9 +177,9 @@ describe("Clock module", () => {
|
||||
});
|
||||
|
||||
it("should show the analog clock face and the date", async () => {
|
||||
const elemClock = helpers.waitForElement(".clock-circle");
|
||||
const elemClock = await helpers.waitForElement(".clock-circle");
|
||||
await expect(elemClock).not.toBeNull();
|
||||
const elemDate = helpers.waitForElement(".clock .date");
|
||||
const elemDate = await helpers.waitForElement(".clock .date");
|
||||
await expect(elemDate).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
@@ -84,9 +84,7 @@ describe("Newsfeed module", () => {
|
||||
describe("Newsfeed module located in config directory", () => {
|
||||
beforeAll(() => {
|
||||
const baseDir = `${__dirname}/../../..`;
|
||||
if (!fs.existsSync(`${baseDir}/config/newsfeed`)) {
|
||||
fs.cpSync(`${baseDir}/modules/default/newsfeed`, `${baseDir}/config/newsfeed`, { recursive: true });
|
||||
}
|
||||
fs.cpSync(`${baseDir}/modules/default/newsfeed`, `${baseDir}/config/newsfeed`, { recursive: true });
|
||||
process.env.MM_MODULES_DIR = "config";
|
||||
});
|
||||
|
||||
|
@@ -6,7 +6,7 @@ const express = require("express");
|
||||
const sinon = require("sinon");
|
||||
const translations = require("../../translations/translations");
|
||||
|
||||
describe("Translations", () => {
|
||||
describe("translations", () => {
|
||||
let server;
|
||||
|
||||
beforeAll(() => {
|
||||
@@ -26,8 +26,9 @@ describe("Translations", () => {
|
||||
});
|
||||
|
||||
it("should have a translation file in the specified path", () => {
|
||||
for (let language in translations) {
|
||||
for (const language in translations) {
|
||||
const file = fs.statSync(translations[language]);
|
||||
|
||||
expect(file.isFile()).toBe(true);
|
||||
}
|
||||
});
|
||||
@@ -36,90 +37,91 @@ describe("Translations", () => {
|
||||
let dom;
|
||||
|
||||
beforeEach(() => {
|
||||
dom = new JSDOM(
|
||||
`<script>var Translator = {}; var Log = {log: () => {}}; var config = {language: 'de'};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "class.js")}"></script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "module.js")}"></script>`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
// Create a new JSDOM instance for each test
|
||||
dom = new JSDOM("", { runScripts: "dangerously", resources: "usable" });
|
||||
|
||||
// Mock the necessary global objects
|
||||
dom.window.Log = { log: jest.fn(), error: jest.fn() };
|
||||
dom.window.Translator = {};
|
||||
dom.window.config = { language: "de" };
|
||||
|
||||
// Load class.js and module.js content directly
|
||||
const classJs = fs.readFileSync(path.join(__dirname, "..", "..", "js", "class.js"), "utf-8");
|
||||
const moduleJs = fs.readFileSync(path.join(__dirname, "..", "..", "js", "module.js"), "utf-8");
|
||||
|
||||
// Execute the scripts in the JSDOM context
|
||||
dom.window.eval(classJs);
|
||||
dom.window.eval(moduleJs);
|
||||
});
|
||||
|
||||
it("should load translation file", () => {
|
||||
return new Promise((done) => {
|
||||
dom.window.onload = async () => {
|
||||
const { Translator, Module, config } = dom.window;
|
||||
config.language = "en";
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb) => null);
|
||||
|
||||
Module.register("name", { getTranslations: () => translations });
|
||||
const MMM = Module.create("name");
|
||||
|
||||
await MMM.loadTranslations();
|
||||
|
||||
expect(Translator.load.args).toHaveLength(1);
|
||||
expect(Translator.load.calledWith(MMM, "translations/en.json", false)).toBe(true);
|
||||
|
||||
done();
|
||||
};
|
||||
it("should load translation file", async () => {
|
||||
await new Promise((resolve) => {
|
||||
dom.window.onload = resolve;
|
||||
});
|
||||
|
||||
const { Translator, Module, config } = dom.window;
|
||||
config.language = "en";
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb) => null);
|
||||
|
||||
Module.register("name", { getTranslations: () => translations });
|
||||
const MMM = Module.create("name");
|
||||
|
||||
await MMM.loadTranslations();
|
||||
|
||||
expect(Translator.load.args).toHaveLength(1);
|
||||
expect(Translator.load.calledWith(MMM, "translations/en.json", false)).toBe(true);
|
||||
});
|
||||
|
||||
it("should load translation + fallback file", () => {
|
||||
return new Promise((done) => {
|
||||
dom.window.onload = async () => {
|
||||
const { Translator, Module } = dom.window;
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb) => null);
|
||||
|
||||
Module.register("name", { getTranslations: () => translations });
|
||||
const MMM = Module.create("name");
|
||||
|
||||
await MMM.loadTranslations();
|
||||
|
||||
expect(Translator.load.args).toHaveLength(2);
|
||||
expect(Translator.load.calledWith(MMM, "translations/de.json", false)).toBe(true);
|
||||
expect(Translator.load.calledWith(MMM, "translations/en.json", true)).toBe(true);
|
||||
|
||||
done();
|
||||
};
|
||||
it("should load translation + fallback file", async () => {
|
||||
await new Promise((resolve) => {
|
||||
dom.window.onload = resolve;
|
||||
});
|
||||
|
||||
const { Translator, Module } = dom.window;
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb) => null);
|
||||
|
||||
Module.register("name", { getTranslations: () => translations });
|
||||
const MMM = Module.create("name");
|
||||
|
||||
await MMM.loadTranslations();
|
||||
|
||||
expect(Translator.load.args).toHaveLength(2);
|
||||
expect(Translator.load.calledWith(MMM, "translations/de.json", false)).toBe(true);
|
||||
expect(Translator.load.calledWith(MMM, "translations/en.json", true)).toBe(true);
|
||||
});
|
||||
|
||||
it("should load translation fallback file", () => {
|
||||
return new Promise((done) => {
|
||||
dom.window.onload = async () => {
|
||||
const { Translator, Module, config } = dom.window;
|
||||
config.language = "--";
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb) => null);
|
||||
|
||||
Module.register("name", { getTranslations: () => translations });
|
||||
const MMM = Module.create("name");
|
||||
|
||||
await MMM.loadTranslations();
|
||||
|
||||
expect(Translator.load.args).toHaveLength(1);
|
||||
expect(Translator.load.calledWith(MMM, "translations/en.json", true)).toBe(true);
|
||||
|
||||
done();
|
||||
};
|
||||
it("should load translation fallback file", async () => {
|
||||
await new Promise((resolve) => {
|
||||
dom.window.onload = resolve;
|
||||
});
|
||||
|
||||
const { Translator, Module, config } = dom.window;
|
||||
config.language = "--";
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb) => null);
|
||||
|
||||
Module.register("name", { getTranslations: () => translations });
|
||||
const MMM = Module.create("name");
|
||||
|
||||
await MMM.loadTranslations();
|
||||
|
||||
expect(Translator.load.args).toHaveLength(1);
|
||||
expect(Translator.load.calledWith(MMM, "translations/en.json", true)).toBe(true);
|
||||
});
|
||||
|
||||
it("should load no file", () => {
|
||||
return new Promise((done) => {
|
||||
dom.window.onload = async () => {
|
||||
const { Translator, Module } = dom.window;
|
||||
Translator.load = sinon.stub();
|
||||
|
||||
Module.register("name", {});
|
||||
const MMM = Module.create("name");
|
||||
|
||||
await MMM.loadTranslations();
|
||||
|
||||
expect(Translator.load.callCount).toBe(0);
|
||||
|
||||
done();
|
||||
};
|
||||
it("should load no file", async () => {
|
||||
await new Promise((resolve) => {
|
||||
dom.window.onload = resolve;
|
||||
});
|
||||
|
||||
const { Translator, Module } = dom.window;
|
||||
Translator.load = sinon.stub();
|
||||
|
||||
Module.register("name", {});
|
||||
const MMM = Module.create("name");
|
||||
|
||||
await MMM.loadTranslations();
|
||||
|
||||
expect(Translator.load.callCount).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -130,101 +132,103 @@ describe("Translations", () => {
|
||||
}
|
||||
};
|
||||
|
||||
describe("Parsing language files through the Translator class", () => {
|
||||
for (let language in translations) {
|
||||
it(`should parse ${language}`, () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
const translatorJs = fs.readFileSync(path.join(__dirname, "..", "..", "js", "translator.js"), "utf-8");
|
||||
|
||||
await Translator.load(mmm, translations[language], false);
|
||||
expect(typeof Translator.translations[mmm.name]).toBe("object");
|
||||
expect(Object.keys(Translator.translations[mmm.name]).length).toBeGreaterThanOrEqual(1);
|
||||
done();
|
||||
};
|
||||
describe("parsing language files through the Translator class", () => {
|
||||
for (const language in translations) {
|
||||
it(`should parse ${language}`, async () => {
|
||||
const dom = new JSDOM("", { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.Log = { log: jest.fn() };
|
||||
dom.window.translations = translations;
|
||||
dom.window.eval(translatorJs);
|
||||
|
||||
await new Promise((resolve) => {
|
||||
dom.window.onload = resolve;
|
||||
});
|
||||
|
||||
const { Translator } = dom.window;
|
||||
await Translator.load(mmm, translations[language], false);
|
||||
|
||||
expect(typeof Translator.translations[mmm.name]).toBe("object");
|
||||
expect(Object.keys(Translator.translations[mmm.name]).length).toBeGreaterThanOrEqual(1);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Same keys", () => {
|
||||
describe("same keys", () => {
|
||||
let base;
|
||||
let missing = [];
|
||||
|
||||
beforeAll(() => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
// Some expressions are not easy to translate automatically. For the sake of a working test, we filter them out.
|
||||
const COMMON_EXCEPTIONS = ["WEEK_SHORT"];
|
||||
|
||||
// Some languages don't have certain words, so we need to filter those language specific exceptions.
|
||||
const LANGUAGE_EXCEPTIONS = {
|
||||
ca: ["DAYBEFOREYESTERDAY"],
|
||||
cv: ["DAYBEFOREYESTERDAY"],
|
||||
cy: ["DAYBEFOREYESTERDAY"],
|
||||
en: ["DAYAFTERTOMORROW", "DAYBEFOREYESTERDAY"],
|
||||
fy: ["DAYBEFOREYESTERDAY"],
|
||||
gl: ["DAYBEFOREYESTERDAY"],
|
||||
hu: ["DAYBEFOREYESTERDAY"],
|
||||
id: ["DAYBEFOREYESTERDAY"],
|
||||
it: ["DAYBEFOREYESTERDAY"],
|
||||
"pt-br": ["DAYAFTERTOMORROW"],
|
||||
tr: ["DAYBEFOREYESTERDAY"]
|
||||
};
|
||||
|
||||
// Function to initialize JSDOM and load translations
|
||||
const initializeTranslationDOM = (language) => {
|
||||
const dom = new JSDOM("", { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.Log = { log: jest.fn() };
|
||||
dom.window.translations = translations;
|
||||
dom.window.eval(translatorJs);
|
||||
|
||||
return new Promise((resolve) => {
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
|
||||
await Translator.load(mmm, translations.de, false);
|
||||
base = Object.keys(Translator.translations[mmm.name]).sort();
|
||||
done();
|
||||
await Translator.load(mmm, translations[language], false);
|
||||
resolve(Translator.translations[mmm.name]);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
beforeAll(async () => {
|
||||
// Using German as the base rather than English, since
|
||||
// some words do not have a direct translation in English.
|
||||
const germanTranslations = await initializeTranslationDOM("de");
|
||||
base = Object.keys(germanTranslations).sort();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
console.log(missing);
|
||||
});
|
||||
|
||||
// Using German as the base rather than English, since
|
||||
// at least one translated word doesn't exist in English.
|
||||
for (let language in translations) {
|
||||
if (language === "de") {
|
||||
continue;
|
||||
}
|
||||
for (const language in translations) {
|
||||
if (language === "de") continue;
|
||||
|
||||
describe(`Translation keys of ${language}`, () => {
|
||||
let keys;
|
||||
|
||||
beforeAll(() => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
|
||||
await Translator.load(mmm, translations[language], false);
|
||||
keys = Object.keys(Translator.translations[mmm.name]).sort();
|
||||
done();
|
||||
};
|
||||
});
|
||||
beforeAll(async () => {
|
||||
const languageTranslations = await initializeTranslationDOM(language);
|
||||
keys = Object.keys(languageTranslations).sort();
|
||||
});
|
||||
|
||||
it(`${language} keys should be in base`, () => {
|
||||
it(`${language} should not contain keys that are not in base language`, () => {
|
||||
keys.forEach((key) => {
|
||||
expect(base.indexOf(key)).toBeGreaterThanOrEqual(0);
|
||||
expect(base).toContain(key, `Translation key '${key}' in language '${language}' is not present in base language`);
|
||||
});
|
||||
});
|
||||
|
||||
it(`${language} should contain all base keys`, () => {
|
||||
// TODO: when all translations are fixed, use
|
||||
// expect(keys).toEqual(base);
|
||||
// instead of the try-catch-block
|
||||
it(`${language} should contain all base keys (excluding defined exceptions)`, () => {
|
||||
let filteredBase = base.filter((key) => !COMMON_EXCEPTIONS.includes(key));
|
||||
let filteredKeys = keys.filter((key) => !COMMON_EXCEPTIONS.includes(key));
|
||||
|
||||
try {
|
||||
expect(keys).toEqual(base);
|
||||
} catch (e) {
|
||||
if (e.message.match(/expect.*toEqual/)) {
|
||||
const diff = base.filter((key) => !keys.includes(key));
|
||||
missing.push(`Missing Translations for language ${language}: ${diff}`);
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
if (LANGUAGE_EXCEPTIONS[language]) {
|
||||
const exceptions = LANGUAGE_EXCEPTIONS[language];
|
||||
filteredBase = filteredBase.filter((key) => !exceptions.includes(key));
|
||||
filteredKeys = filteredKeys.filter((key) => !exceptions.includes(key));
|
||||
}
|
||||
|
||||
filteredBase.forEach((baseKey) => {
|
||||
expect(filteredKeys).toContain(baseKey, `Translation key '${baseKey}' is missing in language '${language}'`);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@@ -9,22 +9,14 @@ describe("Vendors", () => {
|
||||
});
|
||||
|
||||
describe("Get list vendors", () => {
|
||||
const vendors = require(`${__dirname}/../../vendor/vendor.js`);
|
||||
const vendors = require(`${__dirname}/../../js/vendor.js`);
|
||||
|
||||
Object.keys(vendors).forEach((vendor) => {
|
||||
it(`should return 200 HTTP code for vendor "${vendor}"`, async () => {
|
||||
const urlVendor = `http://localhost:8080/vendor/${vendors[vendor]}`;
|
||||
const urlVendor = `http://localhost:8080/${vendors[vendor]}`;
|
||||
const res = await fetch(urlVendor);
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(vendors).forEach((vendor) => {
|
||||
it(`should return 404 HTTP code for vendor https://localhost/"${vendor}"`, async () => {
|
||||
const urlVendor = `http://localhost:8080/${vendors[vendor]}`;
|
||||
const res = await fetch(urlVendor);
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user