Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: suppress translation warning in jest #20404

Merged
merged 2 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions superset-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions superset-frontend/packages/superset-ui-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default class Translator {
*/
addTranslation(key: string, texts: ReadonlyArray<string>) {
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.`);
}
translations[key] = texts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ describe('Translator', () => {
spy.mockImplementation((info: any) => {
throw new Error(info);
});
process.env.WEBPACK_MODE = 'production';
});

afterAll(() => {
spy.mockRestore();
process.env.WEBPACK_MODE = 'test';
});

describe('new Translator(config)', () => {
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/spec/helpers/shim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,5 @@ setupSupersetClient();
jest.mock('src/hooks/useTabId', () => ({
useTabId: () => 1,
}));

process.env.WEBPACK_MODE = 'test';
Copy link
Member Author

@zhaoyongjie zhaoyongjie Jun 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the environment variable WEBPACK_MODE was defined at webpack.config.js. add a new value test to determine if it is in the Jest process.

3 changes: 2 additions & 1 deletion superset-frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"types": [
"@emotion/react/types/css-prop",
"jest",
"@testing-library/jest-dom"
"@testing-library/jest-dom",
"@types/node"
],

/* Emit */
Expand Down