forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.js
More file actions
42 lines (37 loc) · 1.21 KB
/
console.js
File metadata and controls
42 lines (37 loc) · 1.21 KB
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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
function ignoreStrings(
methodName: string,
stringsToIgnore: Array<string>,
): void {
console[methodName] = (...args) => {
const maybeString = args[0];
if (typeof maybeString === 'string') {
for (let i = 0; i < stringsToIgnore.length; i++) {
if (maybeString.startsWith(stringsToIgnore[i])) {
return;
}
}
}
// HACKY In the test harness, DevTools overrides the parent window's console.
// Our test app code uses the iframe's console though.
// To simulate a more accurate end-to-end environment,
// the shell's console patching should pass through to the parent override methods.
window.parent.console[methodName](...args);
};
}
export function ignoreErrors(errorsToIgnore: Array<string>): void {
ignoreStrings('error', errorsToIgnore);
}
export function ignoreWarnings(warningsToIgnore: Array<string>): void {
ignoreStrings('warn', warningsToIgnore);
}
export function ignoreLogs(logsToIgnore: Array<string>): void {
ignoreStrings('log', logsToIgnore);
}