MagicMirror/tests/e2e/helpers/mock-console.js
Kristjan ESPERANTO 291ae8546c
Handle "module is not defined" in e2e tests (#3647)
Even in successful tests, there are many module not defined` error
entries. Like this:
https://github.com/MagicMirrorOrg/MagicMirror/actions/runs/12199106844/job/34032254241#step:5:353

I think we can suppress them.
2024-12-07 08:17:04 +01:00

30 lines
646 B
JavaScript

/**
* Suppresses errors concerning web server already shut down.
* @param {string} err The error message.
*/
const mockError = (err) => {
if (
err.includes("ECONNREFUSED")
|| err.includes("ECONNRESET")
|| err.includes("socket hang up")
|| err.includes("exports is not defined")
|| err.includes("module is not defined")
|| err.includes("write EPIPE")
|| err.includes("AggregateError")
|| err.includes("ERR_SOCKET_CONNECTION_TIMEOUT")
) {
jest.fn();
} else {
console.dir(err);
}
};
global.console = {
log: jest.fn(),
dir: console.dir,
error: mockError,
warn: console.warn,
info: jest.fn(),
debug: console.debug
};