-
Notifications
You must be signed in to change notification settings - Fork 107
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
queueMicrotask() ExperimentalWarning in Node #233
Conversation
… if it's not used in user's code
if (queueMicrotaskPresent) { | ||
timers.queueMicrotask = _global.queueMicrotask; | ||
timers.queueMicrotask = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this set to true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It gives another warning for just var lolex = require("lolex");
.
Assigned native method not used later. So it's just for "yes, this feature supported". And actually we can remove it at all, because we filtering this method later inside install function to prevent faking by default. Correct me, please, if I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is here for restoring the original queueMicrotask later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought so, but during uninstall
function it restores original method from _queueMicrotask
which was assigned inside hijackMethod
from target[method]
(_global[queueMicrotask
in our case). lolex.timers
not involved in this at all.
Example code on node 11.9.0:
const lolex = require("lolex");
var clock = lolex.install({ toFake: ["setTimeout", "queueMicrotask"] });
function microtask() {
console.log("microtask");
}
function task() {
console.log("task");
}
setTimeout(task, 0);
queueMicrotask(microtask);
clock.tick();
clock.uninstall();
setTimeout(task, 0);
queueMicrotask(microtask);
Outputs
microtask // faked method
task // faked method
(node:27136) ExperimentalWarning: queueMicrotask() is experimental.
at get (internal/bootstrap/node.js:771:15)
at hijackMethod (/Users/shdq/Projects/lolex-warning/node_modules/lolex/src/lolex-src.js:486:33)
at Object.install (/Users/shdq/Projects/lolex-warning/node_modules/lolex/src/lolex-src.js:995:9)
at Object.<anonymous> (/Users/shdq/Projects/lolex-warning/index.js:3:19)
at Module._compile (internal/modules/cjs/loader.js:734:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
at Module.load (internal/modules/cjs/loader.js:626:32)
at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
at Function.Module._load (internal/modules/cjs/loader.js:558:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:797:12)
microtask // native method
task // native method
It gives this warning on line 2, because there in hijackMethod _queueMicrotask = _global[queueMicrotask]
;
I'm not insisting on true
, we can even remove it at all, because this method is not going to be faked by default after this PR, but maybe it will be against whole concept of storing all the supported timers in lolex.timers
. What do you think?
I think the property check fix is fine since there is no property called enqueueMicrotask on the process object otherwise |
@shdq thanks for taking some time fixing my issue! About Either way: would chaining |
Thank you for the suggestion, when the right side will be evaluated it gives a warning in a console. |
@shdq Yes you're right my suggestion did not make much sense :) |
Would love to see this merged; anything I can do to help? |
@boneskull sorry, had a lot on my plate lately. @fatso83 can you do a release? (If not I'll get one next week + hopefully the setTimeout promises thing) |
I tried it and it works. Thanks! |
@benjamingr I tried doing it in a hurry on a mac I was able to loan, but
So it will have to wait until next week for me. Perhaps @mroderick ? |
OK, I am having a stab at this now. |
Out as |
Hello, guys.
I did a quick fix for #232 not faking this method by default like
nextTick
, but have a couple of questions.--trace-warnings
point on_global.queueMicrotask
usage in the code.There are two places in the code:
true
when property value isnull
orundefined
. What do you think?lolex.timers
. What is the purpose of storing all the timers methods that supported by particular environment there instead of storing only just list of them? As I got from the codehijackMethod
assign_queueMicrotask
to_global.queueMicrotask
, but not totimers.queueMicrotask
. I might be incorrect.Now it is giving warnings only with
lolex.install({ toFake: ["queueMicrotask"] })
.I'm going to add some tests for this.
@benjamingr I fixed queueMicrotask() test "runs with timers and before them", which was failed, I think it was the typo.
Any comments?