main
js 43 lines 1.32 KB
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 function ignoreStrings(
11 methodName: string,
12 stringsToIgnore: Array<string>,
13 ): void {
14 // $FlowFixMe[prop-missing] index access only allowed for objects with index keys
15 console[methodName] = (...args: $ReadOnlyArray<mixed>) => {
16 const maybeString = args[0];
17 if (typeof maybeString === 'string') {
18 for (let i = 0; i < stringsToIgnore.length; i++) {
19 if (maybeString.startsWith(stringsToIgnore[i])) {
20 return;
21 }
22 }
23 }
24
25 // HACKY In the test harness, DevTools overrides the parent window's console.
26 // Our test app code uses the iframe's console though.
27 // To simulate a more accurate end-to-end environment,
28 // the shell's console patching should pass through to the parent override methods.
29 window.parent.console[methodName](...args);
30 };
31 }
32
33 export function ignoreErrors(errorsToIgnore: Array<string>): void {
34 ignoreStrings('error', errorsToIgnore);
35 }
36
37 export function ignoreWarnings(warningsToIgnore: Array<string>): void {
38 ignoreStrings('warn', warningsToIgnore);
39 }
40
41 export function ignoreLogs(logsToIgnore: Array<string>): void {
42 ignoreStrings('log', logsToIgnore);
43 }