From 4c0708f77e53c579a2ac8ec917a492f2ae45901d Mon Sep 17 00:00:00 2001 From: Maxime Aubanel Date: Fri, 22 Sep 2023 13:15:41 +0200 Subject: [PATCH 1/4] Remove logs from UI library --- jest.setup.js | 5 +++++ next.config.js | 5 +++++ src/app/[locale]/page.tsx | 5 +++++ tools/removeLogs.js | 30 ++++++++++++++++++++++++++++++ tsconfig.json | 1 + 5 files changed, 46 insertions(+) create mode 100644 tools/removeLogs.js diff --git a/jest.setup.js b/jest.setup.js index 545d7cd..cbe86d8 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -7,6 +7,11 @@ import { server } from "@/tools-test/mocks/server"; import { mockUseUserId, mockUseUserIdData } from "@/tools-test/mocks/userId.mock"; import { mockUseWalletInfo, mockUseWalletInfoData } from "@/tools-test/mocks/walletInfo.mock"; +/** + * @dev temporary removing some logs. + */ +require("./tools/removeLogs"); + global.TextEncoder = TextEncoder; global.TextDecoder = TextDecoder; global.ArrayBuffer = ArrayBuffer; diff --git a/next.config.js b/next.config.js index 6875869..f9f4862 100644 --- a/next.config.js +++ b/next.config.js @@ -10,6 +10,11 @@ const nextConfig = { module.exports = nextConfig; +/** + * @dev temporary removing some logs in server. + */ +require("./tools/removeLogs"); + // Injected content via Sentry wizard below // eslint-disable-next-line @typescript-eslint/no-var-requires diff --git a/src/app/[locale]/page.tsx b/src/app/[locale]/page.tsx index f0fb416..395d697 100644 --- a/src/app/[locale]/page.tsx +++ b/src/app/[locale]/page.tsx @@ -1,5 +1,10 @@ "use client"; +/** + * @dev temporary removing some logs in client. + */ +require("@/tools/removeLogs"); + import Image from "next/image"; import styles from "./page.module.css"; import ThemeSelector from "@/components/ThemeSelector"; diff --git a/tools/removeLogs.js b/tools/removeLogs.js new file mode 100644 index 0000000..19ba183 --- /dev/null +++ b/tools/removeLogs.js @@ -0,0 +1,30 @@ +/** + * @dev We are removing error and warning logs from `@ledgerhq/react-ui`. + */ +const originalError = console.error; +const originalWarn = console.warn; + +const EXCLUDED_ERRORS = [ + "If you accidentally passed it from a parent component, remove it from the DOM element.", + "You provided a `checked` prop to a form field without an `onChange` handler.", +]; + +const EXCLUDED_WARNINGS = [ + " is being sent through to the DOM, which will likely trigger a React console error.", +]; + +console.error = (...args) => { + const error = args.join(); + if (EXCLUDED_ERRORS.some((excluded) => error.includes(excluded))) { + return; + } + originalError.call(console, ...args); +}; + +console.warn = (...args) => { + const warning = args.join(); + if (EXCLUDED_WARNINGS.some((excluded) => warning.includes(excluded))) { + return; + } + originalWarn.call(console, ...args); +}; diff --git a/tsconfig.json b/tsconfig.json index 69d86e7..9ebee60 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,6 +24,7 @@ "@/components/*": ["./src/components/*"], "@/styles/*": ["./src/styles/*"], "@/redux/*": ["./src/redux/*"], + "@/tools/*": ["./tools/*"], "@/tools-test/*": ["./tools/test/*"], "@/hooks/*": ["./src/hooks/*"] } From 870ca505a2e7ebe88f62e8a243930e9110416aee Mon Sep 17 00:00:00 2001 From: Maxime Aubanel Date: Fri, 22 Sep 2023 13:24:24 +0200 Subject: [PATCH 2/4] Path doesn't work with @ in tests --- src/app/[locale]/page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/[locale]/page.tsx b/src/app/[locale]/page.tsx index 395d697..25cb673 100644 --- a/src/app/[locale]/page.tsx +++ b/src/app/[locale]/page.tsx @@ -3,7 +3,7 @@ /** * @dev temporary removing some logs in client. */ -require("@/tools/removeLogs"); +require("../../../tools/removeLogs"); import Image from "next/image"; import styles from "./page.module.css"; From d13c8a793e31cc78593547a8e5d47e00380b6dec Mon Sep 17 00:00:00 2001 From: Maxime Aubanel Date: Fri, 22 Sep 2023 16:17:06 +0200 Subject: [PATCH 3/4] Fix import --- src/app/[locale]/page.tsx | 2 +- tools/removeLogs.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app/[locale]/page.tsx b/src/app/[locale]/page.tsx index 25cb673..19128b1 100644 --- a/src/app/[locale]/page.tsx +++ b/src/app/[locale]/page.tsx @@ -3,7 +3,7 @@ /** * @dev temporary removing some logs in client. */ -require("../../../tools/removeLogs"); +import("@/tools/removeLogs"); import Image from "next/image"; import styles from "./page.module.css"; diff --git a/tools/removeLogs.js b/tools/removeLogs.js index 19ba183..1bc643d 100644 --- a/tools/removeLogs.js +++ b/tools/removeLogs.js @@ -28,3 +28,5 @@ console.warn = (...args) => { } originalWarn.call(console, ...args); }; + +module.exports = {}; From e5b3c2cff4cda309fd170b1caea04ca1f84b5356 Mon Sep 17 00:00:00 2001 From: Maxime Aubanel Date: Fri, 22 Sep 2023 16:27:31 +0200 Subject: [PATCH 4/4] Fix import --- jest.setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.setup.js b/jest.setup.js index cbe86d8..d8bd9fd 100644 --- a/jest.setup.js +++ b/jest.setup.js @@ -10,7 +10,7 @@ import { mockUseWalletInfo, mockUseWalletInfoData } from "@/tools-test/mocks/wal /** * @dev temporary removing some logs. */ -require("./tools/removeLogs"); +import("./tools/removeLogs"); global.TextEncoder = TextEncoder; global.TextDecoder = TextDecoder;