From 35f16e812509826a2b94b282a6b1532073662bb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Cs=C3=A1sz=C3=A1r?= Date: Sun, 1 Sep 2024 10:22:16 +0200 Subject: [PATCH] Add test for unclamping setTimeout in Safari --- spec/core/ClearStackSpec.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/spec/core/ClearStackSpec.js b/spec/core/ClearStackSpec.js index b60aee7e..2e846ffc 100644 --- a/spec/core/ClearStackSpec.js +++ b/spec/core/ClearStackSpec.js @@ -20,6 +20,32 @@ describe('ClearStack', function() { MessageChannel: fakeMessageChannel }; }); + + it('uses MessageChannel to reduce setTimeout clamping', function() { + const fakeChannel = fakeMessageChannel(); + spyOn(fakeChannel.port2, 'postMessage'); + const queueMicrotask = jasmine.createSpy('queueMicrotask'); + const global = { + navigator: { + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.0.8 (KHTML, like Gecko) Version/15.1 Safari/605.0.8' + }, + MessageChannel: function() { + return fakeChannel; + }, + queueMicrotask + }; + + const clearStack = jasmineUnderTest.getClearStack(global); + + for (let i = 0; i < 9; i++) clearStack(function() {}); + + expect(fakeChannel.port2.postMessage).not.toHaveBeenCalled(); + + clearStack(function() {}); + + expect(fakeChannel.port2.postMessage).toHaveBeenCalledTimes(1); + }); }); describe("in WebKit (Playwright's build for Windows)", function() {