Skip to content

Commit aa69dca

Browse files
authored
chore(mocha-config): mute unhelpful messages in unit tests (#6190)
* chore(mocha-config): mute unhelpful messages in unit tests * chore(query-bar): fix mock data to resolve the missing key warning
1 parent a7496ff commit aa69dca

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

configs/mocha-config-compass/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
const path = require('path');
44
const base = require('@mongodb-js/mocha-config-devtools');
55

6-
const fs = require('fs');
7-
86
module.exports = {
97
...base,
108
reporter: path.resolve(__dirname, 'reporter.js'),
119
require: [
10+
path.resolve(__dirname, 'register', 'mute-console-warnings-register.js'),
1211
...base.require,
1312
path.resolve(__dirname, 'register', 'resolve-from-source-register.js'),
1413
path.resolve(__dirname, 'register', 'node-env-register.js'),

configs/mocha-config-compass/react.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const base = require('@mongodb-js/mocha-config-devtools/react');
66
module.exports = {
77
...base,
88
require: [
9+
path.resolve(__dirname, 'register', 'mute-console-warnings-register.js'),
910
...base.require,
1011
path.resolve(__dirname, 'register', 'resolve-from-source-register.js'),
1112
path.resolve(__dirname, 'register', 'jsdom-extra-mocks-register.js'),
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// A bunch of leafygreen / React messages that only generate noise in tests
2+
// without being meaningfully actionable for us
3+
const ignoreLeafygreenWarnings = [
4+
/validateDOMNesting\(/,
5+
/Failed (prop|%s) type/,
6+
/recommend using the Leafygreen/,
7+
/The property `aria-controls` is required/,
8+
/For screen-reader accessibility, label or aria-labelledby/,
9+
[
10+
/Can't perform a React state update/,
11+
/./,
12+
/@leafygreen-ui\/(tooltip|toast)/,
13+
],
14+
/react-16-node-hanging-test-fix/,
15+
];
16+
17+
const console = globalThis.console;
18+
19+
for (const method of ['warn', 'error']) {
20+
/* eslint-disable no-console */
21+
const fn = console[method];
22+
console[method] = function (...args) {
23+
if (typeof args[0] === 'string') {
24+
if (
25+
ignoreLeafygreenWarnings.some((regex) => {
26+
return Array.isArray(regex)
27+
? regex.every((r, index) => {
28+
return r.test(args[index]);
29+
})
30+
: regex.test(args[0]);
31+
})
32+
) {
33+
return;
34+
}
35+
}
36+
return fn.apply(this, args);
37+
};
38+
/* eslint-enable no-console */
39+
}

packages/compass-query-bar/src/components/query-history/favorite-list.spec.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe('Favorite List [Component]', function () {
4040
isReadonly: true,
4141
queries: [
4242
{
43+
_id: 1,
4344
filter: { a: 1 },
4445
update: { $set: { a: 2 } },
4546
} as any,
@@ -65,6 +66,7 @@ describe('Favorite List [Component]', function () {
6566
isReadonly: false,
6667
queries: [
6768
{
69+
_id: 1,
6870
filter: { a: 1 },
6971
update: { $set: { a: 2 } },
7072
} as any,

packages/compass-query-bar/src/components/query-history/recent-list.spec.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ describe('Recent List [Component]', function () {
4242
isReadonly: true,
4343
queries: [
4444
{
45+
_id: 1,
4546
filter: { a: 1 },
4647
update: { $set: { a: 2 } },
4748
_lastExecuted: new Date(),
@@ -68,6 +69,7 @@ describe('Recent List [Component]', function () {
6869
isReadonly: false,
6970
queries: [
7071
{
72+
_id: 1,
7173
filter: { a: 1 },
7274
update: { $set: { a: 2 } },
7375
_lastExecuted: new Date(),

0 commit comments

Comments
 (0)