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
793 stars 103 forks source link

Support performance.measure method #493

Open CreativeTechGuy opened 3 months ago

CreativeTechGuy commented 3 months ago

What did you expect to happen?

Faking timers with default settings (which will fake performance) should fake all of the performance methods including performance.mark, performance.measure, etc.

What actually happens

These methods exist and can be called, but seem to do nothing since calling performance.measure() returns undefined which isn't a valid return value and then the code crashes when trying to access the properties which are expected to exist on the result.

How to reproduce

const FakeTimers = await import("https://esm.sh/@sinonjs/fake-timers@11.2.2");
FakeTimers.install();
performance.mark("start");
performance.mark("end");
const measurement = performance.measure("duration", "start", "end");
console.log("duration is", measurement.duration); // Crashes here since measurement is undefined