-
Notifications
You must be signed in to change notification settings - Fork 424
/
gizmo.js
executable file
·42 lines (35 loc) · 1.17 KB
/
gizmo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const defaultConfig = { maxErrors: 10 };
export default (userConfig) => ({ logger, stop, window }) => {
const config = { ...defaultConfig, ...userConfig };
let realOnError;
let realLoggerError;
const gizmoMogwai = () => {
let nbErrors = 0;
const incrementNbErrors = () => {
nbErrors++;
if (nbErrors === config.maxErrors) {
stop();
if (!logger) return;
window.setTimeout(() => {
logger.warn('mogwai ', 'gizmo ', 'stopped test execution after ', config.maxErrors, 'errors');
}, 4);
}
};
realOnError = window.onerror;
window.onerror = (...args) => {
incrementNbErrors();
return realOnError ? realOnError(...args) : false;
};
realLoggerError = console.error;
console.error = (...args) => {
incrementNbErrors();
realLoggerError(...args);
};
};
gizmoMogwai.cleanUp = () => {
window.onerror = realOnError;
console.error = realLoggerError.bind(console);
return gizmoMogwai;
};
return gizmoMogwai;
};