You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently timers.ts uses Date.now() to determine if timer callbacks should be called.
Sometimes people need to fake time in their tests to verify it behaves correctly. SinonJS fakes time by temporarily replacing globalThis.Date, and the timer functions on globalThis. Currently if you replace globalThis.Date or globalThis.Date.now in deno, the callbacks for timers will not be called. In the browser setTimeout and setInterval do not use the global date object, so you can safely override those globals without disrupting timers. That is necessary to be able to create a fake date implemention that has time advancing forward on its own. The way SinonJS does it is by calling setInterval with a callback that advances the fake Date implementation forward in intervals.
I believe this could be accomplished by creating a local variable in the timers.ts file like const now = Date.now.bind(Date); then replacing all calls to Date.now() with now(). That would make it so that the timers are not effected by globalThis.Date being changed or replaced.
The text was updated successfully, but these errors were encountered:
This is actually not just limited to timer, but all builtins. Deno currently just uses the globals from the environment, yet they subject to overwrites and can cause unexpected behaviors (even security related). For example, the simplest way to crash REPL is window.Object = 1.
Currently timers.ts uses
Date.now()
to determine if timer callbacks should be called.Sometimes people need to fake time in their tests to verify it behaves correctly. SinonJS fakes time by temporarily replacing
globalThis.Date
, and the timer functions onglobalThis
. Currently if you replaceglobalThis.Date
orglobalThis.Date.now
in deno, the callbacks for timers will not be called. In the browser setTimeout and setInterval do not use the global date object, so you can safely override those globals without disrupting timers. That is necessary to be able to create a fake date implemention that has time advancing forward on its own. The way SinonJS does it is by calling setInterval with a callback that advances the fake Date implementation forward in intervals.I believe this could be accomplished by creating a local variable in the timers.ts file like
const now = Date.now.bind(Date);
then replacing all calls toDate.now()
withnow()
. That would make it so that the timers are not effected byglobalThis.Date
being changed or replaced.The text was updated successfully, but these errors were encountered: