infernojs / inferno

:fire: An extremely fast, React-like JavaScript library for building modern user interfaces

Home Page:https://infernojs.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Many "Inferno is in development mode" logs during testing

jrwdexter opened this issue · comments

Observed Behaviour

When running tests that utilize Inferno as part of the framework, every test will log Inferno is in development mode. to the console. This is due to the NODE_ENV !== 'production' check in index.ts within Inferno.

This logging behavior, without an ability to stop it, pollutes test logs with these statements.

Expected Current Behaviour

I don't know if there's an exact specified behavior. Having a way to turn off these logs (without setting the whole process to 'production') would be helpful.

If this is a design choice, the options as far as I can tell are to:

  • Add a new environment variable (or other setting) to disable Inferno log statements
  • Detect a variable when this log should happen - to ensure it gets run when a "real" browser is running, and not a test suite.
  • "Just deal with" extra log statements in various capacities
  • Ask users to monkey patch console.log to avoid extra logging
  • Ask users to switch test suites running to 'production'

A few of the above are non-ideal, and I would argue switching test suite to production is just a bad idea.

Ideally, I think that an environment variable or environment detection makes the most sense.

Hi

I think you have something wrong in your test suite build if you see more than one message it means you have more than one infernojs bundled in your javascript bundle. Is that intentional?

commented

I have this console.log for each testing suite. But, to be honest, I don't want console.log at all, even in browser.

what about disabling the console log then?

window.console.log = () => {}
commented

Monkey patching? I once did this and then lost some valuable data in tests. It was my bad, should never rely on console.log, but some 3rd-party libraries still can use it.

Is there a need for displaying this message? I understand and appreciate that the library displays console.warn when I use minified version during developing. But if every library will spam in console with "you are in development mode", console will become a useless place.

It is valuable information because people do bundling mistakes and then report issues to inferno saying its slow or post benchmarks to internet and don't even use optimized version, well yeah its slow if the build is not even in production mode.

commented

Understandable.

I suppose that wrapping this console.log into if (process.env.NODE_ENV !== 'test') won't affect developers and production users but will add a small improvement for developing process. It is not a big change, but even small changes make us happier.

Okay sure, would you like to send PR?

hi @Havunen, sorry to necrobump this, I ran into the same issue, in my case however i'm not using jest, but another test framework, also i'm executing specs in the browser (without process object).

I was wondering if you would be open for a PR which "generalizes" this warning-skipping logic to cover both node and browser environment and renaming into something like SKIP_INFERNO_WARNINGS?

I was wondering if you would be open for a PR which "generalizes" this warning-skipping logic to cover both node and browser environment and renaming into something like SKIP_INFERNO_WARNINGS?

Sounds good to me as long as the code can be treeshaken off from the production bundle