mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-24 01:02: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) => {
|
const originalLog = console.log;
|
||||||
let logs: any[] = [];
|
const originalError = console.error;
|
||||||
const logDisabled: boolean = _logDisabled;
|
const originalDebug = console.debug;
|
||||||
const phaseText: boolean = _phaseText;
|
const originalWarn = console.warn;
|
||||||
const originalLog = console.log;
|
|
||||||
const originalError = console.error;
|
|
||||||
const originalDebug = console.debug;
|
|
||||||
const originalWarn = console.warn;
|
|
||||||
const notified: any[] = [];
|
|
||||||
|
|
||||||
const blacklist = [ "Phaser", "variant icon does not exist", "Texture \"%s\" not found" ];
|
|
||||||
const whitelist = [ "Phase" ];
|
|
||||||
|
|
||||||
return ({
|
// eslint-disable-next-line quotes
|
||||||
log(...args) {
|
const blacklist = [ "Phaser", "variant icon does not exist", 'Texture "%s" not found' ];
|
||||||
const argsStr = this.getStr(args);
|
const whitelist = [ "Phase" ];
|
||||||
logs.push(argsStr);
|
|
||||||
if (logDisabled && (!phaseText)) {
|
export class MockConsoleLog {
|
||||||
return;
|
constructor(
|
||||||
}
|
private logDisabled = false,
|
||||||
if ((phaseText && !whitelist.some((b) => argsStr.includes(b))) || blacklist.some((b) => argsStr.includes(b))) {
|
private phaseText = false,
|
||||||
return;
|
) {}
|
||||||
}
|
private logs: any[] = [];
|
||||||
originalLog(args);
|
private notified: any[] = [];
|
||||||
},
|
|
||||||
error(...args) {
|
public log(...args) {
|
||||||
const argsStr = this.getStr(args);
|
const argsStr = this.getStr(args);
|
||||||
logs.push(argsStr);
|
this.logs.push(argsStr);
|
||||||
originalError(args); // Appelle le console.error originel
|
if (this.logDisabled && !this.phaseText) {
|
||||||
},
|
return;
|
||||||
debug(...args) {
|
}
|
||||||
const argsStr = this.getStr(args);
|
if ((this.phaseText && !whitelist.some((b) => argsStr.includes(b))) || blacklist.some((b) => argsStr.includes(b))) {
|
||||||
logs.push(argsStr);
|
return;
|
||||||
if (logDisabled && (!phaseText)) {
|
}
|
||||||
return;
|
originalLog(args);
|
||||||
}
|
}
|
||||||
if (!whitelist.some((b) => argsStr.includes(b)) || blacklist.some((b) => argsStr.includes(b))) {
|
public error(...args) {
|
||||||
return;
|
const argsStr = this.getStr(args);
|
||||||
}
|
this.logs.push(argsStr);
|
||||||
originalDebug(args);
|
originalError(args); // Appelle le console.error originel
|
||||||
},
|
}
|
||||||
warn(...args) {
|
public debug(...args) {
|
||||||
const argsStr = this.getStr(args);
|
const argsStr = this.getStr(args);
|
||||||
logs.push(args);
|
this.logs.push(argsStr);
|
||||||
if (logDisabled && (!phaseText)) {
|
if (this.logDisabled && !this.phaseText) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!whitelist.some((b) => argsStr.includes(b)) || blacklist.some((b) => argsStr.includes(b))) {
|
if (!whitelist.some((b) => argsStr.includes(b)) || blacklist.some((b) => argsStr.includes(b))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
originalWarn(args);
|
originalDebug(args);
|
||||||
},
|
}
|
||||||
notify(msg) {
|
warn(...args) {
|
||||||
originalLog(msg);
|
const argsStr = this.getStr(args);
|
||||||
notified.push(msg);
|
this.logs.push(args);
|
||||||
},
|
if (this.logDisabled && !this.phaseText) {
|
||||||
getLogs() {
|
return;
|
||||||
return logs;
|
}
|
||||||
},
|
if (!whitelist.some((b) => argsStr.includes(b)) || blacklist.some((b) => argsStr.includes(b))) {
|
||||||
clearLogs() {
|
return;
|
||||||
logs = [];
|
}
|
||||||
},
|
originalWarn(args);
|
||||||
getStr(...args) {
|
}
|
||||||
return args.map(arg => {
|
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) {
|
if (typeof arg === "object" && arg !== null) {
|
||||||
// Handle objects including arrays
|
// Handle objects including arrays
|
||||||
return JSON.stringify(arg, (key, value) =>
|
return JSON.stringify(arg, (_key, value) => (typeof value === "bigint" ? value.toString() : value));
|
||||||
typeof value === "bigint" ? value.toString() : value
|
|
||||||
);
|
|
||||||
} else if (typeof arg === "bigint") {
|
} else if (typeof arg === "bigint") {
|
||||||
// Handle BigInt values
|
// Handle BigInt values
|
||||||
return arg.toString();
|
return arg.toString();
|
||||||
@ -74,9 +77,7 @@ const MockConsoleLog = (_logDisabled = false, _phaseText = false) => {
|
|||||||
// Handle all other types
|
// Handle all other types
|
||||||
return arg.toString();
|
return arg.toString();
|
||||||
}
|
}
|
||||||
}).join(";");
|
})
|
||||||
},
|
.join(";");
|
||||||
});
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export default MockConsoleLog;
|
|
||||||
|
@ -13,7 +13,7 @@ import { initVouchers } from "#app/system/voucher";
|
|||||||
import { initStatsKeys } from "#app/ui/game-stats-ui-handler";
|
import { initStatsKeys } from "#app/ui/game-stats-ui-handler";
|
||||||
import { setCookie } from "#app/utils";
|
import { setCookie } from "#app/utils";
|
||||||
import { blobToString } from "#test/testUtils/gameManagerUtils";
|
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 { mockLocalStorage } from "#test/testUtils/mocks/mockLocalStorage";
|
||||||
import { MockImage } from "#test/testUtils/mocks/mocksContainer/mockImage";
|
import { MockImage } from "#test/testUtils/mocks/mocksContainer/mockImage";
|
||||||
import Phaser from "phaser";
|
import Phaser from "phaser";
|
||||||
@ -32,7 +32,7 @@ export function initTestFile() {
|
|||||||
value: mockLocalStorage(),
|
value: mockLocalStorage(),
|
||||||
});
|
});
|
||||||
Object.defineProperty(window, "console", {
|
Object.defineProperty(window, "console", {
|
||||||
value: mockConsoleLog(false),
|
value: new MockConsoleLog(false),
|
||||||
});
|
});
|
||||||
Object.defineProperty(document, "fonts", {
|
Object.defineProperty(document, "fonts", {
|
||||||
writable: true,
|
writable: true,
|
||||||
|
Loading…
Reference in New Issue
Block a user