From ad82ce6db56039e4c2a299cd0821a5dc95391156 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Thu, 16 Jun 2022 12:52:05 +0800 Subject: [PATCH 1/2] fix: suppress translation warning in jest --- superset-frontend/package-lock.json | 14 ++++++++------ .../packages/superset-ui-core/package.json | 1 + .../superset-ui-core/src/translation/Translator.ts | 2 +- .../test/translation/Translator.test.ts | 2 ++ superset-frontend/tsconfig.json | 3 ++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index 0ec9482e2d2b3..c0b831b35d839 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -16970,9 +16970,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "17.0.21", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", - "integrity": "sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==" + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.0.tgz", + "integrity": "sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA==" }, "node_modules/@types/node-fetch": { "version": "2.6.1", @@ -54322,6 +54322,7 @@ "@types/fetch-mock": "^7.3.3", "@types/lodash": "^4.14.149", "@types/math-expression-evaluator": "^1.2.1", + "@types/node": "^18.0.0", "@types/prop-types": "^15.7.2", "@types/rison": "0.0.6", "@types/seedrandom": "^2.4.28", @@ -67442,6 +67443,7 @@ "@types/fetch-mock": "^7.3.3", "@types/lodash": "^4.14.149", "@types/math-expression-evaluator": "^1.2.1", + "@types/node": "^18.0.0", "@types/prop-types": "^15.7.2", "@types/rison": "0.0.6", "@types/seedrandom": "^2.4.28", @@ -69036,9 +69038,9 @@ "dev": true }, "@types/node": { - "version": "17.0.21", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", - "integrity": "sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==" + "version": "18.0.0", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.0.tgz", + "integrity": "sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA==" }, "@types/node-fetch": { "version": "2.6.1", diff --git a/superset-frontend/packages/superset-ui-core/package.json b/superset-frontend/packages/superset-ui-core/package.json index 424f3b877620c..1958fe1a49fae 100644 --- a/superset-frontend/packages/superset-ui-core/package.json +++ b/superset-frontend/packages/superset-ui-core/package.json @@ -40,6 +40,7 @@ "@types/d3-time-format": "^2.1.0", "@types/lodash": "^4.14.149", "@types/math-expression-evaluator": "^1.2.1", + "@types/node": "^18.0.0", "@types/rison": "0.0.6", "@types/seedrandom": "^2.4.28", "@types/fetch-mock": "^7.3.3", diff --git a/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts b/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts index 823638ceec952..902088ad5c3f5 100644 --- a/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts +++ b/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts @@ -56,7 +56,7 @@ export default class Translator { */ addTranslation(key: string, texts: ReadonlyArray) { const translations = this.i18n.options.locale_data.superset; - if (key in translations) { + if (process?.env?.NODE_ENV !== 'test' && key in translations) { logging.warn(`Duplicate translation key "${key}", will override.`); } translations[key] = texts; diff --git a/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts b/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts index 9466294aca7a2..70d5697706798 100644 --- a/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts @@ -41,10 +41,12 @@ describe('Translator', () => { spy.mockImplementation((info: any) => { throw new Error(info); }); + process.env.NODE_ENV = 'production'; }); afterAll(() => { spy.mockRestore(); + process.env.NODE_ENV = 'test'; }); describe('new Translator(config)', () => { diff --git a/superset-frontend/tsconfig.json b/superset-frontend/tsconfig.json index 818147ca7cc87..9dba1c3f89b23 100644 --- a/superset-frontend/tsconfig.json +++ b/superset-frontend/tsconfig.json @@ -29,7 +29,8 @@ "types": [ "@emotion/react/types/css-prop", "jest", - "@testing-library/jest-dom" + "@testing-library/jest-dom", + "@types/node" ], /* Emit */ From 4efc2106e34f5584dfcfb8c78c904a593a359971 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Thu, 16 Jun 2022 14:31:37 +0800 Subject: [PATCH 2/2] fix crash --- .../packages/superset-ui-core/src/translation/Translator.ts | 2 +- .../superset-ui-core/test/translation/Translator.test.ts | 4 ++-- superset-frontend/spec/helpers/shim.ts | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts b/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts index 902088ad5c3f5..d4a6982c8d32b 100644 --- a/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts +++ b/superset-frontend/packages/superset-ui-core/src/translation/Translator.ts @@ -56,7 +56,7 @@ export default class Translator { */ addTranslation(key: string, texts: ReadonlyArray) { const translations = this.i18n.options.locale_data.superset; - if (process?.env?.NODE_ENV !== 'test' && key in translations) { + if (process.env.WEBPACK_MODE !== 'test' && key in translations) { logging.warn(`Duplicate translation key "${key}", will override.`); } translations[key] = texts; diff --git a/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts b/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts index 70d5697706798..df718afe41597 100644 --- a/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/translation/Translator.test.ts @@ -41,12 +41,12 @@ describe('Translator', () => { spy.mockImplementation((info: any) => { throw new Error(info); }); - process.env.NODE_ENV = 'production'; + process.env.WEBPACK_MODE = 'production'; }); afterAll(() => { spy.mockRestore(); - process.env.NODE_ENV = 'test'; + process.env.WEBPACK_MODE = 'test'; }); describe('new Translator(config)', () => { diff --git a/superset-frontend/spec/helpers/shim.ts b/superset-frontend/spec/helpers/shim.ts index 2d3e943b73519..7955ee15e0f0f 100644 --- a/superset-frontend/spec/helpers/shim.ts +++ b/superset-frontend/spec/helpers/shim.ts @@ -81,3 +81,5 @@ setupSupersetClient(); jest.mock('src/hooks/useTabId', () => ({ useTabId: () => 1, })); + +process.env.WEBPACK_MODE = 'test';