diff --git a/test/utils/mocks/mockConsoleLog.ts b/test/utils/mocks/mockConsoleLog.ts index 9c3cbca6bb6..a046af12034 100644 --- a/test/utils/mocks/mockConsoleLog.ts +++ b/test/utils/mocks/mockConsoleLog.ts @@ -1,72 +1,75 @@ -const MockConsoleLog = (_logDisabled = false, _phaseText = false) => { - let logs: any[] = []; - const logDisabled: boolean = _logDisabled; - const phaseText: boolean = _phaseText; - const originalLog = console.log; - const originalError = console.error; - const originalDebug = console.debug; - const originalWarn = console.warn; - const notified: any[] = []; +const originalLog = console.log; +const originalError = console.error; +const originalDebug = console.debug; +const originalWarn = console.warn; - const blacklist = [ "Phaser", "variant icon does not exist", "Texture \"%s\" not found" ]; - const whitelist = [ "Phase" ]; - return ({ - log(...args) { - const argsStr = this.getStr(args); - logs.push(argsStr); - if (logDisabled && (!phaseText)) { - return; - } - if ((phaseText && !whitelist.some((b) => argsStr.includes(b))) || blacklist.some((b) => argsStr.includes(b))) { - return; - } - originalLog(args); - }, - error(...args) { - const argsStr = this.getStr(args); - logs.push(argsStr); - originalError(args); // Appelle le console.error originel - }, - debug(...args) { - const argsStr = this.getStr(args); - logs.push(argsStr); - if (logDisabled && (!phaseText)) { - return; - } - if (!whitelist.some((b) => argsStr.includes(b)) || blacklist.some((b) => argsStr.includes(b))) { - return; - } - originalDebug(args); - }, - warn(...args) { - const argsStr = this.getStr(args); - logs.push(args); - if (logDisabled && (!phaseText)) { - return; - } - if (!whitelist.some((b) => argsStr.includes(b)) || blacklist.some((b) => argsStr.includes(b))) { - return; - } - originalWarn(args); - }, - notify(msg) { - originalLog(msg); - notified.push(msg); - }, - getLogs() { - return logs; - }, - clearLogs() { - logs = []; - }, - getStr(...args) { - return args.map(arg => { +// eslint-disable-next-line quotes +const blacklist = [ "Phaser", "variant icon does not exist", 'Texture "%s" not found' ]; +const whitelist = [ "Phase" ]; + +export class MockConsoleLog { + constructor( + private logDisabled = false, + private phaseText = false, + ) {} + private logs: any[] = []; + private notified: any[] = []; + + public log(...args) { + const argsStr = this.getStr(args); + this.logs.push(argsStr); + if (this.logDisabled && !this.phaseText) { + return; + } + if ((this.phaseText && !whitelist.some((b) => argsStr.includes(b))) || blacklist.some((b) => argsStr.includes(b))) { + return; + } + originalLog(args); + } + public error(...args) { + const argsStr = this.getStr(args); + this.logs.push(argsStr); + originalError(args); // Appelle le console.error originel + } + public debug(...args) { + const argsStr = this.getStr(args); + this.logs.push(argsStr); + if (this.logDisabled && !this.phaseText) { + return; + } + if (!whitelist.some((b) => argsStr.includes(b)) || blacklist.some((b) => argsStr.includes(b))) { + return; + } + originalDebug(args); + } + warn(...args) { + const argsStr = this.getStr(args); + this.logs.push(args); + if (this.logDisabled && !this.phaseText) { + return; + } + if (!whitelist.some((b) => argsStr.includes(b)) || blacklist.some((b) => argsStr.includes(b))) { + return; + } + originalWarn(args); + } + notify(msg) { + originalLog(msg); + this.notified.push(msg); + } + getLogs() { + return this.logs; + } + clearLogs() { + this.logs = []; + } + getStr(...args) { + return args + .map((arg) => { if (typeof arg === "object" && arg !== null) { // Handle objects including arrays - return JSON.stringify(arg, (key, value) => - typeof value === "bigint" ? value.toString() : value - ); + return JSON.stringify(arg, (_key, value) => (typeof value === "bigint" ? value.toString() : value)); } else if (typeof arg === "bigint") { // Handle BigInt values return arg.toString(); @@ -74,9 +77,7 @@ const MockConsoleLog = (_logDisabled = false, _phaseText = false) => { // Handle all other types return arg.toString(); } - }).join(";"); - }, - }); -}; - -export default MockConsoleLog; + }) + .join(";"); + } +} diff --git a/test/utils/testFileInitialization.ts b/test/utils/testFileInitialization.ts index 19e9255ebb2..a97e551fd0a 100644 --- a/test/utils/testFileInitialization.ts +++ b/test/utils/testFileInitialization.ts @@ -13,7 +13,7 @@ import { initVouchers } from "#app/system/voucher"; import { initStatsKeys } from "#app/ui/game-stats-ui-handler"; import { setCookie } from "#app/utils"; import { blobToString } from "#test/testUtils/gameManagerUtils"; -import { mockConsoleLog } from "#test/testUtils/mocks/mockConsoleLog"; +import { MockConsoleLog } from "#test/testUtils/mocks/mockConsoleLog"; import { mockLocalStorage } from "#test/testUtils/mocks/mockLocalStorage"; import { MockImage } from "#test/testUtils/mocks/mocksContainer/mockImage"; import Phaser from "phaser"; @@ -32,7 +32,7 @@ export function initTestFile() { value: mockLocalStorage(), }); Object.defineProperty(window, "console", { - value: mockConsoleLog(false), + value: new MockConsoleLog(false), }); Object.defineProperty(document, "fonts", { writable: true,