question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Remove console.warn of babel-plugin-import when the tests are running

See original GitHub issue

Environment(required)

  • antd version: 2.8 & 2.9
  • OS and its version: Ubuntu 16.04
  • Browser and its version: Chrome 57.0.2987.98 (64-bit)

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:

PASS  components/locale-provider/__tests__/index.test.js
  Console
    console.warn components/index.tsx:60
      You are using a whole package of antd,
      please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.

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:

if (process.env.NODE_ENV !== 'production') {
    if (typeof console !== 'undefined' && console.warn && typeof window !== 'undefined') {
        console.warn(`You are using a whole package of antd,
please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.`);
    }
}

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.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
andriijascommented, May 4, 2018
2reactions
trinitroglycerincommented, Apr 24, 2018

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.

http://www.linfo.org/rule_of_silence.html

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native 0.60.3 babel-plugin-transform-remove-console ...
this will remove console.log in the production build. if you wanna a test in development you can pass development instead of production.
Read more >
babel-plugin-transform-remove-console
exclude - An array of console methods to exclude from removal. You can read more about configuring plugin options here. Example; Installation; Usage....
Read more >
babel-plugin-transform-remove-console - npm package - Snyk
The npm package babel-plugin-transform-remove-console was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was ...
Read more >
deploy-testing (#14830) · Jobs · m4lab_tv1 / User Account · GitLab
1Running with gitlab-runner 14.8.1 (6a42249e) ... 14Checking out d983558b as testing. ... 79Removing node_modules/@babel/plugin-proposal-dynamic-import/.
Read more >
Configuration | Stryker Mutator
Enable checker plugins here. A checker plugin will be invoked for each mutant before it is run in a test runner. It can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found