Skip to content

Commit cfcb3bf

Browse files
authored
ENG-3971: clean up jest console error noise in admin-ui (#8277)
1 parent b6b0b02 commit cfcb3bf

7 files changed

Lines changed: 106 additions & 109 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type: Developer Experience
2+
description: Cleaned up jest console error noise in admin-ui.
3+
pr: 8277
4+
labels: []

clients/admin-ui/__tests__/jest.setup.ts

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,23 @@ if (
2020
NodeList.prototype.includes = Array.prototype.includes;
2121
}
2222

23-
// nwsapi 2.2.18 + jsdom: when antd v6 stylesheets contain `:has()` selectors,
24-
// the resolver crashes inside `getComputedStyle` (called by Chakra's
25-
// color-mode-provider on mount). Wrap `getComputedStyle` so a thrown selector
26-
// returns an empty CSSStyleDeclaration instead of breaking the render.
23+
// Wrap `getComputedStyle` for two jsdom limitations:
24+
// 1. jsdom doesn't implement pseudo-element styles, so any `pseudoElt`
25+
// argument triggers a "Not implemented: window.computedStyle(elt,
26+
// pseudoElt)" log via its VirtualConsole. @rc-component's scrollbar
27+
// measurement passes one, so we drop it (pseudo-element styles aren't
28+
// available in jsdom anyway).
29+
// 2. nwsapi 2.2.18 crashes resolving antd v6's `:has()` selectors, so fall
30+
// back to an empty CSSStyleDeclaration when the underlying call throws.
2731
if (typeof window !== "undefined") {
2832
const originalGetComputedStyle = window.getComputedStyle.bind(window);
29-
window.getComputedStyle = ((
30-
elt: Element,
31-
pseudoElt?: string | null,
32-
): CSSStyleDeclaration => {
33+
window.getComputedStyle = ((elt: Element): CSSStyleDeclaration => {
3334
try {
34-
return originalGetComputedStyle(elt, pseudoElt ?? undefined);
35+
return originalGetComputedStyle(elt);
3536
} catch {
3637
return {
3738
getPropertyValue: () => "",
39+
length: 0,
3840
} as unknown as CSSStyleDeclaration;
3941
}
4042
}) as typeof window.getComputedStyle;
@@ -60,3 +62,30 @@ if (typeof window !== "undefined") {
6062
}
6163

6264
installMessageChannelMock();
65+
66+
// Filter console.error output for known noise that doesn't indicate a real bug.
67+
// React passes its warnings as a format string + substitutions (e.g.
68+
// `console.error("An update to %s inside a test...", "BaseSelect")`), so we
69+
// match against the unformatted first argument.
70+
// - antd List deprecation warning (no drop-in replacement exists yet)
71+
// - rc-trigger's "same shadow root" warning (jsdom doesn't implement shadow DOM)
72+
// - `NaN` height from antd-x Sender/Bubble.List measuring DOM that jsdom can't lay out
73+
// - React `act()` warnings from async updates in antd Select / next/dynamic /
74+
// rc-trigger that fire after the test assertion and can't be reasonably awaited
75+
const SUPPRESSED_CONSOLE_ERRORS = [
76+
"[antd: List] The `List` component is deprecated",
77+
"trigger element and popup element should in same shadow root",
78+
"`NaN` is an invalid value for the `%s` css style property",
79+
"An update to %s inside a test was not wrapped in act",
80+
];
81+
82+
/* eslint-disable no-console */
83+
const originalConsoleError = console.error;
84+
console.error = (...args: unknown[]) => {
85+
const message = String(args[0] ?? "");
86+
if (SUPPRESSED_CONSOLE_ERRORS.some((pattern) => message.includes(pattern))) {
87+
return;
88+
}
89+
originalConsoleError(...args);
90+
};
91+
/* eslint-enable no-console */
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
export const iso3166 = {
2-
esModule: true,
1+
export const iso3166Mock = {
2+
__esModule: true,
3+
iso31661: [],
4+
iso31662: [],
35
};

clients/admin-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"motion": "^12.23.26",
7070
"narrow-minded": "^1.2.1",
7171
"next": "^16.2.0",
72-
"nuqs": "^2.8.8",
72+
"nuqs": "^2.8.9",
7373
"papaparse": "^5.5.3",
7474
"query-string": "^9.0.0",
7575
"react": "^19.2.0",

clients/admin-ui/src/features/integrations/configure-jira/__tests__/JiraConfigTab.test.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ jest.mock("fidesui", () => ({
4040
message,
4141
description,
4242
action,
43+
showIcon: _showIcon,
44+
type: _type,
4345
...props
4446
}: Record<string, unknown>) => (
4547
<div data-testid="alert" {...props}>
@@ -48,8 +50,17 @@ jest.mock("fidesui", () => ({
4850
{action as React.ReactNode}
4951
</div>
5052
),
51-
Button: ({ children, ...props }: Record<string, unknown>) => (
52-
<button type="button" {...props}>
53+
Button: ({
54+
children,
55+
htmlType,
56+
loading: _loading,
57+
...props
58+
}: Record<string, unknown>) => (
59+
<button
60+
// eslint-disable-next-line react/button-has-type
61+
type={(htmlType as "button" | "submit" | "reset" | undefined) ?? "button"}
62+
{...props}
63+
>
5364
{children as React.ReactNode}
5465
</button>
5566
),

clients/admin-ui/tsconfig.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@
3737
"include": [
3838
"next-env.d.ts",
3939
"app-env.d.ts",
40-
"**/*.ts",
41-
"**/*.tsx",
40+
"*.ts",
41+
"src/**/*.ts",
42+
"src/**/*.tsx",
43+
"__tests__/**/*.ts",
44+
"__tests__/**/*.tsx",
4245
"**/*.d.ts",
4346
".next/types/**/*.ts",
4447
".next/dev/types/**/*.ts"

0 commit comments

Comments
 (0)