From d7348ed7652e808b48364a179a1fb4d306d7975e Mon Sep 17 00:00:00 2001 From: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Date: Mon, 3 Nov 2025 23:49:21 +0100 Subject: [PATCH] [tests] suppress debug logs in CI environment + improve calendar symbol test stability (#3941) ## CI Log Suppression **Two-level approach for clean test output:** 1. **Suppress debug/info logs**: Call `logger.setLogLevel("ERROR")` in CI to hide verbose logging 2. **Suppress intentional error logs**: Set `mmTestMode` flag and check it before logging errors that are part of test assertions (e.g., testing error handling in `git_helper.js` and `server_functions.js`) This keeps CI output clean and makes genuine failures immediately visible, while preserving full logging for local development. **Before:** 1348 log lines with verbose debug/info output **After:** 168 log clean lines with only test results ## Calendar Symbol Test Stability Convert the calendar symbol test from external URL (`calendarlabs.com`) to existing local mock file (`12_events.ics`). This eliminates CI timeouts caused by external dependencies and improves test reliability. The test still validates the same symbol array feature but now runs faster and deterministically without network dependencies. --- CHANGELOG.md | 2 +- js/server_functions.js | 5 ++++- .../default/updatenotification/git_helper.js | 5 ++++- tests/configs/modules/calendar/symboltest.js | 3 +-- tests/utils/vitest-setup.js | 18 ++++++++++++++++-- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef425ce4..e623f1c5 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/js/server_functions.js b/js/server_functions.js index 6772c7a4..4223204d 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 52161ee9..0444c950 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/configs/modules/calendar/symboltest.js b/tests/configs/modules/calendar/symboltest.js index f31c54d8..4fc43917 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/12_events.ics" } ] } diff --git a/tests/utils/vitest-setup.js b/tests/utils/vitest-setup.js index 2be76a49..dfb5b1c5 100644 --- a/tests/utils/vitest-setup.js +++ b/tests/utils/vitest-setup.js @@ -1,19 +1,33 @@ /** - * 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"); +// Set test mode flag for application code to detect test environment +process.env.mmTestMode = "true"; + // 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