From 092b270604257df73c1edfe8e424d3ed5a5811a7 Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Mon, 3 Nov 2025 20:22:49 +0100 Subject: [PATCH 1/5] [tests] suppress debug logs in CI environment Set LOG_LEVEL=ERROR in vitest-setup.js when running in CI to reduce verbose console output while keeping full logging for local development. --- CHANGELOG.md | 2 +- tests/utils/vitest-setup.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef425ce43a..e623f1c54b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ planned for 2026-01-01 - [check_config] refactor: improve error handling (#3927) - [calendar] test: remove "Recurring event per timezone" test (#3929) - [calendar] chore: remove `requiresVersion: "2.1.0"` (#3932) -- [tests] migrate from `jest` to `vitest` (#3940) +- [tests] migrate from `jest` to `vitest` (#3940, #3941) ### Fixed diff --git a/tests/utils/vitest-setup.js b/tests/utils/vitest-setup.js index 2be76a4908..818a1b8dd6 100644 --- a/tests/utils/vitest-setup.js +++ b/tests/utils/vitest-setup.js @@ -1,11 +1,16 @@ /** - * Vitest setup file for module aliasing + * Vitest setup file for module aliasing and CI logging * This allows require("logger") to work in unit tests */ const Module = require("node:module"); const path = require("node:path"); +// Suppress debug/info logs in CI to keep output clean +if (process.env.CI === "true" && !process.env.LOG_LEVEL) { + process.env.LOG_LEVEL = "ERROR"; +} + // Store the original require const originalRequire = Module.prototype.require; From 95d1a200d9337dc990d091871842f5ba04f6df27 Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Mon, 3 Nov 2025 20:50:12 +0100 Subject: [PATCH 2/5] test: convert calendar symbol test to use local mock Replace external calendarlabs.com URL with local mock file to improve test stability and CI reliability. External URLs can cause timeouts and introduce non-deterministic failures unrelated to the tested functionality. The test still validates the same symbol array feature but now runs faster and more reliably without external dependencies. --- tests/configs/modules/calendar/symboltest.js | 3 +-- tests/mocks/calendar_symbols.ics | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/mocks/calendar_symbols.ics diff --git a/tests/configs/modules/calendar/symboltest.js b/tests/configs/modules/calendar/symboltest.js index f31c54d84b..29856ce9a2 100644 --- a/tests/configs/modules/calendar/symboltest.js +++ b/tests/configs/modules/calendar/symboltest.js @@ -12,9 +12,8 @@ let config = { maximumEntries: 1, calendars: [ { - fetchInterval: 7 * 24 * 60 * 60 * 1000, symbol: ["calendar-check", "google"], - url: "https://ics.calendarlabs.com/76/mm3137/US_Holidays.ics" + url: "http://localhost:8080/tests/mocks/calendar_symbols.ics" } ] } diff --git a/tests/mocks/calendar_symbols.ics b/tests/mocks/calendar_symbols.ics new file mode 100644 index 0000000000..dfaabe0968 --- /dev/null +++ b/tests/mocks/calendar_symbols.ics @@ -0,0 +1,15 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//MagicMirror//Test Calendar Symbols//EN +CALSCALE:GREGORIAN +METHOD:PUBLISH +X-WR-CALNAME:Symbol Test Calendar +BEGIN:VEVENT +UID:symbol-event-1@magicmirror.test +DTSTART:20241009T100000Z +DTEND:20241009T110000Z +DTSTAMP:20241008T000000Z +SUMMARY:First Event +STATUS:CONFIRMED +END:VEVENT +END:VCALENDAR From b3b84d53ab35ae5853c62d7a66754539914baa8b Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Mon, 3 Nov 2025 21:05:42 +0100 Subject: [PATCH 3/5] fix: Apply LOG_LEVEL to logger via setLogLevel() --- tests/utils/vitest-setup.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/utils/vitest-setup.js b/tests/utils/vitest-setup.js index 818a1b8dd6..fb9163367d 100644 --- a/tests/utils/vitest-setup.js +++ b/tests/utils/vitest-setup.js @@ -6,19 +6,25 @@ const Module = require("node:module"); const path = require("node:path"); -// Suppress debug/info logs in CI to keep output clean -if (process.env.CI === "true" && !process.env.LOG_LEVEL) { - process.env.LOG_LEVEL = "ERROR"; -} - // Store the original require const originalRequire = Module.prototype.require; +// Track if we've already applied log level +let logLevelApplied = false; + // Override require to handle our custom aliases Module.prototype.require = function (id) { // Handle "logger" alias if (id === "logger") { - return originalRequire.call(this, path.resolve(__dirname, "../../js/logger.js")); + const logger = originalRequire.call(this, path.resolve(__dirname, "../../js/logger.js")); + + // Suppress debug/info logs in CI to keep output clean + if (!logLevelApplied && process.env.CI === "true") { + logger.setLogLevel("ERROR"); + logLevelApplied = true; + } + + return logger; } // Handle all other requires normally From 492bc57369197089ea088f363b6d8f252b3a3191 Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Mon, 3 Nov 2025 21:35:32 +0100 Subject: [PATCH 4/5] refactor(test): use existing 12_events.ics for symbol test --- tests/configs/modules/calendar/symboltest.js | 2 +- tests/mocks/calendar_symbols.ics | 15 --------------- 2 files changed, 1 insertion(+), 16 deletions(-) delete mode 100644 tests/mocks/calendar_symbols.ics diff --git a/tests/configs/modules/calendar/symboltest.js b/tests/configs/modules/calendar/symboltest.js index 29856ce9a2..4fc4391771 100644 --- a/tests/configs/modules/calendar/symboltest.js +++ b/tests/configs/modules/calendar/symboltest.js @@ -13,7 +13,7 @@ let config = { calendars: [ { symbol: ["calendar-check", "google"], - url: "http://localhost:8080/tests/mocks/calendar_symbols.ics" + url: "http://localhost:8080/tests/mocks/12_events.ics" } ] } diff --git a/tests/mocks/calendar_symbols.ics b/tests/mocks/calendar_symbols.ics deleted file mode 100644 index dfaabe0968..0000000000 --- a/tests/mocks/calendar_symbols.ics +++ /dev/null @@ -1,15 +0,0 @@ -BEGIN:VCALENDAR -VERSION:2.0 -PRODID:-//MagicMirror//Test Calendar Symbols//EN -CALSCALE:GREGORIAN -METHOD:PUBLISH -X-WR-CALNAME:Symbol Test Calendar -BEGIN:VEVENT -UID:symbol-event-1@magicmirror.test -DTSTART:20241009T100000Z -DTEND:20241009T110000Z -DTSTAMP:20241008T000000Z -SUMMARY:First Event -STATUS:CONFIRMED -END:VEVENT -END:VCALENDAR From 40642fd30c29817e2dba17ecea350387e0c120d6 Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Mon, 3 Nov 2025 23:24:26 +0100 Subject: [PATCH 5/5] test: suppress intentional error logs in test environment --- js/server_functions.js | 5 ++++- modules/default/updatenotification/git_helper.js | 5 ++++- tests/utils/vitest-setup.js | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/js/server_functions.js b/js/server_functions.js index 6772c7a480..4223204d2c 100644 --- a/js/server_functions.js +++ b/js/server_functions.js @@ -58,7 +58,10 @@ async function cors (req, res) { res.send(data); } } catch (error) { - Log.error(error); + // Only log errors in non-test environments to keep test output clean + if (process.env.mmTestMode !== "true") { + Log.error(error); + } res.send(error); } } diff --git a/modules/default/updatenotification/git_helper.js b/modules/default/updatenotification/git_helper.js index 52161ee910..0444c9500c 100644 --- a/modules/default/updatenotification/git_helper.js +++ b/modules/default/updatenotification/git_helper.js @@ -183,7 +183,10 @@ class GitHelper { this.gitResultList.push(gitInfo); } } catch (e) { - Log.error(`Failed to retrieve repo info for ${repo.module}: ${e}`); + // Only log errors in non-test environments to keep test output clean + if (process.env.mmTestMode !== "true") { + Log.error(`Failed to retrieve repo info for ${repo.module}: ${e}`); + } } } diff --git a/tests/utils/vitest-setup.js b/tests/utils/vitest-setup.js index fb9163367d..dfb5b1c521 100644 --- a/tests/utils/vitest-setup.js +++ b/tests/utils/vitest-setup.js @@ -6,6 +6,9 @@ const Module = require("node:module"); const path = require("node:path"); +// Set test mode flag for application code to detect test environment +process.env.mmTestMode = "true"; + // Store the original require const originalRequire = Module.prototype.require;