-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
55 lines (44 loc) · 1.09 KB
/
index.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
43
44
45
46
47
48
49
50
51
52
53
54
55
import sinon from 'sinon';
// setup spies
const watchError = () => sinon.spy(console, 'error');
const watchWarn = () => sinon.spy(console, 'warn');
const watchErrorAndWarnings = () => {
watchError();
watchWarn();
};
// Get PropType Warnings
const getWarnings = (regex, consoleObj) => {
if (consoleObj.args.length > 0) {
return consoleObj.args[0].filter((message) => {
return (
message
&& message.length > 0
&& regex.test(message)
);
});
} else {
return [];
}
};
const filterErrors = (regex) => getWarnings(regex, console.error);
const filterWarnings = (regex) => getWarnings(regex, console.warn);
const filterErrorAndWarnings = (regex) =>
filterWarnings(regex).concat(filterErrors(regex));
// Remove Spies & Restore Functions
const restoreError = () => console.error.restore();
const restoreWarn = () => console.warn.restore();
const restoreErrorAndWarnings = () => {
restoreError();
restoreWarn();
};
export {
watchWarn,
watchError,
watchErrorAndWarnings,
filterWarnings,
filterErrors,
filterErrorAndWarnings,
restoreError,
restoreWarn,
restoreErrorAndWarnings
};