Skip to content

Commit

Permalink
Use existing test warning filter for server tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
acdlite committed Jun 9, 2021
1 parent 1a3f1af commit c6a4957
Showing 1 changed file with 22 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'use strict';

const stream = require('stream');
const shouldIgnoreConsoleError = require('../../../../../scripts/jest/shouldIgnoreConsoleError');

module.exports = function(initModules) {
let ReactDOM;
Expand Down Expand Up @@ -74,23 +75,29 @@ module.exports = function(initModules) {
}

const result = await fn();
if (
console.error.calls &&
console.error.calls.count() !== count &&
console.error.calls.count() !== 0
) {
console.log(
`We expected ${count} warning(s), but saw ${console.error.calls.count()} warning(s).`,
);
if (console.error.calls.count() > 0) {
console.log(`We saw these warnings:`);
for (let i = 0; i < console.error.calls.count(); i++) {
console.log(...console.error.calls.argsFor(i));
if (console.error.calls && console.error.calls.count() !== 0) {
const filteredWarnings = [];
for (let i = 0; i < console.error.calls.count(); i++) {
const args = console.error.calls.argsFor(i);
const [format, ...rest] = args;
if (!shouldIgnoreConsoleError(format, rest)) {
filteredWarnings.push(args);
}
}
if (filteredWarnings.length !== count) {
console.log(
`We expected ${count} warning(s), but saw ${filteredWarnings.length} warning(s).`,
);
if (filteredWarnings.count > 0) {
console.log(`We saw these warnings:`);
for (let i = 0; i < filteredWarnings.length; i++) {
console.log(...filteredWarnings[i]);
}
}
if (__DEV__) {
expect(console.error).toHaveBeenCalledTimes(count);
}
}
}
if (__DEV__) {
expect(console.error).toHaveBeenCalledTimes(count);
}
return result;
}
Expand Down

0 comments on commit c6a4957

Please sign in to comment.