sinonjs / fake-timers

Fake setTimeout and friends (collectively known as "timers"). Useful in your JavaScript tests. Extracted from Sinon.JS
BSD 3-Clause "New" or "Revised" License
806 stars 107 forks source link

requiring lolex prints a warning #232

Closed ehmicky closed 5 years ago

ehmicky commented 5 years ago

require('lolex') prints the following warning:

(node:30019) ExperimentalWarning: queueMicrotask() is experimental.

What did you expect to happen? There should be no warnings printed on the console when queueMicrotask() is not used by the calling code. This could for example be done by wrapping timers.queueMicrotask() so that global.queueMicrotask is only accessed when timers.queueMicrotask() is called.

Experimental warnings can be turned off with --no-warnings but this is inconvenient as it removes other potentially useful warnings.

Why suppressing this warning matters: some users (like me) might have precise expectations on what's printed on the console, if console output is being parsed, for example for logging purpose. Also some users might see this warning and without additional context think it was triggered from their code, making them debug a non-issue.

What actually happens There is a warning printed on console.

How to reproduce See above.

benjamingr commented 5 years ago

@shdq

shdq commented 5 years ago

I'll take a look at this.

benjamingr commented 5 years ago

@shdq thanks, a quick fix would be not to shim enqueueMicrotask by default.

ehmicky commented 5 years ago

Also for the detection: instead of typeof global.queueMicrotask === 'function' (which prints a warning), something like global.hasOwnProperty('queueMicrotask') does not print a warning.

SimenB commented 5 years ago

In general, should updating the default shimmed functions be considered a breaking change? So don't shim new stuff by default, then for new majors activate everything?

benjamingr commented 5 years ago

Good idea @SimenB , this is the second time I can recall it's breaking stuff.

abrenneke commented 5 years ago

Some console things, for example ava's default reporter, start to break a little if there are any console logs or warnings during operation, and because each ava node process ends up logging a new warning, the output gets rather messy because of this issue. I've turned off node warnings with NODE_NO_WARNINGS=1, but obviously I'd like to turn those back on.

ehmicky commented 5 years ago

@SneakyMax A pending PR #233 exists. Until this PR is merged, if you want to only hide the warning printed by Lolex, you can use log-process-errors to remove this warning during Ava tests:

// Those two lines must be run before `require('lolex')` is first called
const logProcessErrors = require('log-process-errors')
logProcessErrors({
  level: { 
    warning({ message }) {
      if (message.includes('queueMicrotask() is experimental')) {
        return 'silent' 
      }
    } 
  }
})
ehmicky commented 5 years ago

Fixed by #233.