fix: suppress translation warning in jest (#20404)

This commit is contained in:
Yongjie Zhao 2022-06-21 20:38:58 +08:00 committed by GitHub
parent 8bbbd6f03f
commit 9fad26fa19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 8 deletions

View File

@ -16970,9 +16970,9 @@
"dev": true "dev": true
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "17.0.21", "version": "18.0.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.0.tgz",
"integrity": "sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==" "integrity": "sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA=="
}, },
"node_modules/@types/node-fetch": { "node_modules/@types/node-fetch": {
"version": "2.6.1", "version": "2.6.1",
@ -54322,6 +54322,7 @@
"@types/fetch-mock": "^7.3.3", "@types/fetch-mock": "^7.3.3",
"@types/lodash": "^4.14.149", "@types/lodash": "^4.14.149",
"@types/math-expression-evaluator": "^1.2.1", "@types/math-expression-evaluator": "^1.2.1",
"@types/node": "^18.0.0",
"@types/prop-types": "^15.7.2", "@types/prop-types": "^15.7.2",
"@types/rison": "0.0.6", "@types/rison": "0.0.6",
"@types/seedrandom": "^2.4.28", "@types/seedrandom": "^2.4.28",
@ -67442,6 +67443,7 @@
"@types/fetch-mock": "^7.3.3", "@types/fetch-mock": "^7.3.3",
"@types/lodash": "^4.14.149", "@types/lodash": "^4.14.149",
"@types/math-expression-evaluator": "^1.2.1", "@types/math-expression-evaluator": "^1.2.1",
"@types/node": "^18.0.0",
"@types/prop-types": "^15.7.2", "@types/prop-types": "^15.7.2",
"@types/rison": "0.0.6", "@types/rison": "0.0.6",
"@types/seedrandom": "^2.4.28", "@types/seedrandom": "^2.4.28",
@ -69036,9 +69038,9 @@
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
"version": "17.0.21", "version": "18.0.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.0.0.tgz",
"integrity": "sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==" "integrity": "sha512-cHlGmko4gWLVI27cGJntjs/Sj8th9aYwplmZFwmmgYQQvL5NUsgVJG7OddLvNfLqYS31KFN0s3qlaD9qCaxACA=="
}, },
"@types/node-fetch": { "@types/node-fetch": {
"version": "2.6.1", "version": "2.6.1",

View File

@ -40,6 +40,7 @@
"@types/d3-time-format": "^2.1.0", "@types/d3-time-format": "^2.1.0",
"@types/lodash": "^4.14.149", "@types/lodash": "^4.14.149",
"@types/math-expression-evaluator": "^1.2.1", "@types/math-expression-evaluator": "^1.2.1",
"@types/node": "^18.0.0",
"@types/rison": "0.0.6", "@types/rison": "0.0.6",
"@types/seedrandom": "^2.4.28", "@types/seedrandom": "^2.4.28",
"@types/fetch-mock": "^7.3.3", "@types/fetch-mock": "^7.3.3",

View File

@ -56,7 +56,7 @@ export default class Translator {
*/ */
addTranslation(key: string, texts: ReadonlyArray<string>) { addTranslation(key: string, texts: ReadonlyArray<string>) {
const translations = this.i18n.options.locale_data.superset; const translations = this.i18n.options.locale_data.superset;
if (key in translations) { if (process.env.WEBPACK_MODE !== 'test' && key in translations) {
logging.warn(`Duplicate translation key "${key}", will override.`); logging.warn(`Duplicate translation key "${key}", will override.`);
} }
translations[key] = texts; translations[key] = texts;

View File

@ -41,10 +41,12 @@ describe('Translator', () => {
spy.mockImplementation((info: any) => { spy.mockImplementation((info: any) => {
throw new Error(info); throw new Error(info);
}); });
process.env.WEBPACK_MODE = 'production';
}); });
afterAll(() => { afterAll(() => {
spy.mockRestore(); spy.mockRestore();
process.env.WEBPACK_MODE = 'test';
}); });
describe('new Translator(config)', () => { describe('new Translator(config)', () => {

View File

@ -81,3 +81,5 @@ setupSupersetClient();
jest.mock('src/hooks/useTabId', () => ({ jest.mock('src/hooks/useTabId', () => ({
useTabId: () => 1, useTabId: () => 1,
})); }));
process.env.WEBPACK_MODE = 'test';

View File

@ -29,7 +29,8 @@
"types": [ "types": [
"@emotion/react/types/css-prop", "@emotion/react/types/css-prop",
"jest", "jest",
"@testing-library/jest-dom" "@testing-library/jest-dom",
"@types/node"
], ],
/* Emit */ /* Emit */