mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-23 08:42:19 +02:00
Change MockConsoleLog to an actual class
This commit is contained in:
parent
21c111b18c
commit
6049f6a776
@ -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(";");
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user