mirror of
https://github.com/MichMich/MagicMirror.git
synced 2026-06-03 18:00:33 +00:00
The unit tests were full of warnings `ExperimentalWarning: localStorage is not available because --localstorage-file was not provided.` for node versions >=25. Additionally this PR nails node to `v26.0.0` in the automated-tests workflow until the [playwright issue](https://github.com/microsoft/playwright/issues/40724) is fixed. Will revert this after fixed playwright version is available.
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
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";
|
|
|
|
// overrides native implementation (Nodejs >= v25) to avoid warnings in tests
|
|
// "ExperimentalWarning: localStorage is not available because --localstorage-file was not provided."
|
|
Object.defineProperty(globalThis, "localStorage", { value: undefined, writable: 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);
|
|
};
|