Files
MagicMirror/tests/utils/vitest-setup.js
Kristjan ESPERANTO d7348ed765 [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.
2025-11-03 23:49:21 +01:00

36 lines
976 B
JavaScript

/**
* 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") {
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
return originalRequire.apply(this, arguments);
};