Closed msluther closed 11 months ago
While it's not strictly a bug I think it's very reasonable to support this use case and the fix shouldn't be too hard.
This is currently impacting me, but on node v18. What would an acceptable unit test be for this?
From my own manual testing, swapping the order here: https://github.com/sinonjs/fake-timers/blob/b568150a78c41dc89c8fd73186dc8fa10b1b2c6e/src/fake-timers-src.js#L1755-L1760 is enough to resolve the issue for me anyways.
@zbyte64 feel free to open a PR
PR merged 🥳 Thanks a bunch
@sinonjs/fake-timers@9.0.0
global-jsdom
What did you expect to happen?
performance.mark
is a functionWhat actually happens
performance.mark
is undefinedHow to reproduce
Minimal repro is available here: https://github.com/msluther/sinon-timers-jsdom-bug
Effectly though it's just this in node@16:
This is related to this issue: #394
From my comment on that issue:
Hrm. So, the fix works but makes the assumption that the functions on
global.Performance.prototype
are a superset ofglobal.performance.*
functions. This is currently not the case when usingnode@16
andjsdom
.jsdom
is injecting aglobal.Performance
object based on the minimal W3C spec forhr-time
.This isn't necessarily a bug with either library, but feels like a gap between the two.
However,
@sinon/fake-timers
ends up replacing a goodglobal.performance.mark
withundefined
in this situation. Should the code here use both prototypes to make sure this is the case or maybe prefer theglobal.performance
overglobal.Performance
?The work around that I posted above still works in this case as long as its injected prior to sinon & jsdom, so I'm not blocked by any means, but just requires making sure that happens in my tests everywhere.