mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-04-08 02:43:26 +01:00
* Reuse global scene between tests Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * Add missing each method to mockContainer * Fix select-modifier-phase test * Sanitize overrides before tests Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * Sanitize overrides before tests Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> * [WIP] fix things * Fix tests not working with --no-isolate * Update npm tests to use no isolate * Update test-shard-template * Update package.json Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com> --------- Co-authored-by: PigeonBar <56974298+PigeonBar@users.noreply.github.com> Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
81 lines
2.1 KiB
TypeScript
81 lines
2.1 KiB
TypeScript
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"];
|
|
|
|
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));
|
|
}
|
|
if (typeof arg === "bigint") {
|
|
// Handle BigInt values
|
|
return arg.toString();
|
|
}
|
|
return arg.toString();
|
|
})
|
|
.join(";");
|
|
}
|
|
}
|