From bca88b67e33e657380435d440ce847e4573db8b2 Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Sun, 17 Sep 2023 17:38:03 -0700 Subject: Workaround #5604 (#5615) Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> --- test/js/web/timers/performance.test.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'test/js') diff --git a/test/js/web/timers/performance.test.js b/test/js/web/timers/performance.test.js index dd50c4dc6..0d6cd577b 100644 --- a/test/js/web/timers/performance.test.js +++ b/test/js/web/timers/performance.test.js @@ -20,3 +20,28 @@ it("performance.now() should be monotonic", () => { it("performance.timeOrigin + performance.now() should be similar to Date.now()", () => { expect(Math.abs(performance.timeOrigin + performance.now() - Date.now()) < 1000).toBe(true); }); + +// https://github.com/oven-sh/bun/issues/5604 +it("performance.now() DOMJIT", () => { + // This test is very finnicky. + // It has to return true || return false to reproduce. Throwing an error doesn't work. + function run(start, prev) { + while (true) { + const current = performance.now(); + + if (Number.isNaN(current) || current < prev) { + return false; + } + + if (current - start > 200) { + return true; + } + prev = current; + } + } + + const start = performance.now(); + if (!run(start, start)) { + throw new Error("performance.now() is not monotonic"); + } +}); -- cgit v1.2.3