cloudflare / workers-sdk

⛅️ Home to Wrangler, the CLI for Cloudflare Workers®
https://developers.cloudflare.com/workers/
Apache License 2.0
2.71k stars 711 forks source link

🐛 BUG: pre-io Date.now() behaviour inconsistent with live runtime #6261

Open johtso opened 4 months ago

johtso commented 4 months ago

Which Cloudflare product(s) does this pertain to?

Miniflare

What version(s) of the tool(s) are you using?

wrangler 3.64.0

What version of Node are you using?

v20.14.0

What operating system and version are you using?

Mac Sonoma 14.5

Describe the Bug

Observed behavior

Calling Date.now() before io (for example in the root of a module) returns the current time instead of returning 0 as it does in the live runtime.

Expected behavior

It should behave the same as Date.now() in the live runtime, returning 0

Steps to reproduce

console.log(Date.now()) at the root of any worker and run locally.

Please provide a link to a minimal reproduction

No response

Please provide any relevant error logs

No response

johtso commented 4 months ago

Actually, think I might have this backwards. If in local development time is supposed to increment regardless of IO, shouldn't performance.now() return the current time, the same as Date.now() when called at the root of a module?

irvinebroque commented 3 months ago

@jasnell