-
-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Remove console.warn of babel-plugin-import when the tests are running #5345
Comments
Yep, we should check environment before printing any warning. Could you just PR to fix this? Thanks. |
More info: ➜ ant-design git:(master) grep -r 'warning(' ./components | grep tsx
./components/_util/warning.tsx: warning(false, message);
./components/badge/index.tsx: warning(
./components/breadcrumb/Breadcrumb.tsx: warning(
./components/breadcrumb/Breadcrumb.tsx: warning(
./components/date-picker/Calendar.tsx: warning(false, 'DatePicker.Calendar is deprecated, use Calendar instead.');
./components/date-picker/createPicker.tsx: warning(!('onOK' in props), 'It should be `DatePicker[onOk]` or `MonthPicker[onOk]`, instead of `onOK`!');
./components/date-picker/RangePicker.tsx: warning(!('onOK' in props), 'It should be `RangePicker[onOk]`, instead of `onOK`!');
./components/date-picker/wrapPicker.tsx: warning(
./components/form/Form.tsx: warning(
./components/form/Form.tsx: warning(!props.form, 'It is unnecessary to pass `form` to `Form` after antd@1.7.0.');
./components/form/Form.tsx: warning(
./components/form/FormItem.tsx: warning(
./components/menu/index.tsx: warning(
./components/message/index.tsx: // Departed usage, please use warning()
./components/message/index.tsx: warning(content: ConfigContent, duration?: ConfigDuration, onClose?: ConfigOnClose) {
./components/popover/index.tsx: warning(
./components/table/Table.tsx: warning(
./components/table/Table.tsx: warning(recordKey !== undefined,
./components/tabs/index.tsx: warning(
➜ ant-design git:(master) grep -r 'warn(' ./components | grep tsx
./components/index.tsx: console.warn(`You are using a whole package of antd,
./components/message/index.tsx: warn(content: ConfigContent, duration?: ConfigDuration, onClose?: ConfigOnClose) { |
Hello, In fact Antd currently check the enviroment:
Maybe something like:
And modify the
Instead of:
And, finally, modify the last two lines the file
...will work. What do you think about? |
Actually, I told @benjycui same solution this afternoon. |
Hello, I'm getting this same warning in my tests and can't seem to get rid of it even while setting NODE_ENV=test.
I'm using babel-plugin-import in my .babelrc and don't see these warnings in the dom, but have to leaf through many in my tests... Any help is appreciated. Thanks! |
Just updated to the latest release... "antd": "^3.4.0", and still seeing warnings with Jest with NODE_ENV=test can set NODE_ENV=production and suppress the errors. The weird thing is that it looks like the PR (merged into master on Mar 20) appears to fix the current issue. BUT... The current master does not show the changes (would guess that some later commit removed the fix???) |
Having slept on this overnight, had a change of heart. I am thinking it is best practice to be testing your code against the version that will be going into production. So setting NODE_ENV=production before running your test is likely a best practice. If I need to mock things in tests, I should be using Jest's features to do this instead of having the code behave differently under tests than production. |
it was undone by @afc163 in #9814 Im kind of leaning toward @larkintuckerllc that test env should have similar config as prod and dev but even with react-app-rewire this is messy to fix with |
Not only that, but this assumes the user is using Babel. I use Typescript with Webpack. I know that, because of Webpack, dead code is going to be eliminated. This warning is useless in this scenario and there's no way to turn it off. I don't need this warning cluttering up my terminal. You shouldn't expect the user to change NODE_ENV to production to disable this. In tests, NODE_ENV should be test. You also really shouldn't encourage the user to know about the directory structure of your library. You have exposed a context module, as is the usual pattern; let users use it without being told off. |
I second @danpantry 's opinion in that for our team, it's a design choice to not use babel-plugin-import (we are using next.js and sass-loader is configured very differently and doesn't quite support babel-plugin-import ). It's just annoying to keep seeing this message in testing environment. |
Please file a new issue. |
Environment(required)
What did you do? Please provide steps to re-produce your problem.
Run
npm test
in:What do you expected?
No warnings.
What happen?
Both projects always show this message:
I think it will be important remove it when you're executing the tests.
I think, too, the solution is change this kind of code:
Providing another conditional for remove warnings if you are lauching the tests. What do you think about it?
Re-producible online demo
Just download the antd project and run
npm test
.The text was updated successfully, but these errors were encountered: