1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.enableErrorOutputSuppression = enableErrorOutputSuppression;
|
7 | exports.suppressErrorOutput = suppressErrorOutput;
|
8 | const consoleFilters = [/^The above error occurred in the <.*?> component:/,
|
9 | /^Error: Uncaught .+/ // jsdom output
|
10 | ];
|
11 |
|
12 | function suppressErrorOutput() {
|
13 | const originalError = console.error;
|
14 |
|
15 | const error = (...args) => {
|
16 | const message = typeof args[0] === 'string' ? args[0] : null;
|
17 |
|
18 | if (!message || !consoleFilters.some(filter => filter.test(message))) {
|
19 | originalError(...args);
|
20 | }
|
21 | };
|
22 |
|
23 | console.error = error;
|
24 | return () => {
|
25 | console.error = originalError;
|
26 | };
|
27 | }
|
28 |
|
29 | function errorFilteringDisabled() {
|
30 | try {
|
31 | return !!process.env.RHTL_DISABLE_ERROR_FILTERING;
|
32 | } catch {
|
33 |
|
34 | return false;
|
35 | }
|
36 | }
|
37 |
|
38 | function enableErrorOutputSuppression() {
|
39 |
|
40 | if (typeof beforeEach === 'function' && typeof afterEach === 'function' && !errorFilteringDisabled()) {
|
41 | let restoreConsole;
|
42 | beforeEach(() => {
|
43 | restoreConsole = suppressErrorOutput();
|
44 | });
|
45 | afterEach(() => restoreConsole());
|
46 | }
|
47 | } |
\ | No newline at end of file |