Skip to content

Commit c6a4957

Browse files
committed
Use existing test warning filter for server tests
We have a warning filter for our internal tests to ignore warnings that are too noisy or that we haven't removed from our test suite yet: shouldIgnoreConsoleError. Many of our server rendering tests don't use this filter, though, because it has its own special of asserting warnings. So I added the warning filter to the server tests, too.
1 parent 1a3f1af commit c6a4957

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

packages/react-dom/src/__tests__/utils/ReactDOMServerIntegrationTestUtils.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
'use strict';
1111

1212
const stream = require('stream');
13+
const shouldIgnoreConsoleError = require('../../../../../scripts/jest/shouldIgnoreConsoleError');
1314

1415
module.exports = function(initModules) {
1516
let ReactDOM;
@@ -74,23 +75,29 @@ module.exports = function(initModules) {
7475
}
7576

7677
const result = await fn();
77-
if (
78-
console.error.calls &&
79-
console.error.calls.count() !== count &&
80-
console.error.calls.count() !== 0
81-
) {
82-
console.log(
83-
`We expected ${count} warning(s), but saw ${console.error.calls.count()} warning(s).`,
84-
);
85-
if (console.error.calls.count() > 0) {
86-
console.log(`We saw these warnings:`);
87-
for (let i = 0; i < console.error.calls.count(); i++) {
88-
console.log(...console.error.calls.argsFor(i));
78+
if (console.error.calls && console.error.calls.count() !== 0) {
79+
const filteredWarnings = [];
80+
for (let i = 0; i < console.error.calls.count(); i++) {
81+
const args = console.error.calls.argsFor(i);
82+
const [format, ...rest] = args;
83+
if (!shouldIgnoreConsoleError(format, rest)) {
84+
filteredWarnings.push(args);
85+
}
86+
}
87+
if (filteredWarnings.length !== count) {
88+
console.log(
89+
`We expected ${count} warning(s), but saw ${filteredWarnings.length} warning(s).`,
90+
);
91+
if (filteredWarnings.count > 0) {
92+
console.log(`We saw these warnings:`);
93+
for (let i = 0; i < filteredWarnings.length; i++) {
94+
console.log(...filteredWarnings[i]);
95+
}
96+
}
97+
if (__DEV__) {
98+
expect(console.error).toHaveBeenCalledTimes(count);
8999
}
90100
}
91-
}
92-
if (__DEV__) {
93-
expect(console.error).toHaveBeenCalledTimes(count);
94101
}
95102
return result;
96103
}

0 commit comments

Comments
 (0)