pokerogue/test/testUtils/errorInterceptor.ts
Sirz Benjie 408b66f913
[Misc][Refactor][GitHub] Ditch eslint for biome, and add a formatter (#5495)
Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
2025-03-09 14:13:25 -07:00

50 lines
1.0 KiB
TypeScript

export default class ErrorInterceptor {
private static instance: ErrorInterceptor;
public running;
constructor() {
this.running = [];
}
public static getInstance(): ErrorInterceptor {
if (!ErrorInterceptor.instance) {
ErrorInterceptor.instance = new ErrorInterceptor();
}
return ErrorInterceptor.instance;
}
clear() {
this.running = [];
}
add(obj) {
this.running.push(obj);
}
remove(obj) {
const index = this.running.indexOf(obj);
if (index !== -1) {
this.running.splice(index, 1);
}
}
}
process.on("uncaughtException", error => {
console.log(error);
const toStop = ErrorInterceptor.getInstance().running;
for (const elm of toStop) {
elm.rejectAll(error);
}
global.testFailed = true;
});
// Global error handler for unhandled promise rejections
process.on("unhandledRejection", (reason, _promise) => {
console.log(reason);
const toStop = ErrorInterceptor.getInstance().running;
for (const elm of toStop) {
elm.rejectAll(reason);
}
global.testFailed = true;
});