From a9889ddb314d5887986535410455e0de4f790765 Mon Sep 17 00:00:00 2001 From: Mert Akinc <7282195+m-akinc@users.noreply.github.com> Date: Thu, 25 Jul 2024 09:54:32 -0500 Subject: [PATCH 1/4] Improve performance on Playwright Windows WebKit --- spec/helpers/nodeDefineJasmineUnderTest.js | 4 +++- src/core/ClearStack.js | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/spec/helpers/nodeDefineJasmineUnderTest.js b/spec/helpers/nodeDefineJasmineUnderTest.js index 7e4021a9..fd51c24a 100644 --- a/spec/helpers/nodeDefineJasmineUnderTest.js +++ b/spec/helpers/nodeDefineJasmineUnderTest.js @@ -16,7 +16,9 @@ return path.join(__dirname, '../../', 'src/', file); }); - const files = src_files.flatMap(g => glob.sync(g)); + const files = src_files.flatMap(g => + glob.sync(g, { windowsPathsNoEscape: true }) + ); files.forEach(function(resolvedFile) { require(resolvedFile); }); diff --git a/src/core/ClearStack.js b/src/core/ClearStack.js index 3be593c4..23b6da78 100644 --- a/src/core/ClearStack.js +++ b/src/core/ClearStack.js @@ -70,7 +70,9 @@ getJasmineRequireObj().clearStack = function(j$) { const SAFARI = global.navigator && - /^((?!chrome|android).)*safari/i.test(global.navigator.userAgent); + /(^((?!chrome|android).)*safari)|(^((?!chrome|android|firefox).)+$)/i.test( + global.navigator.userAgent + ); if (NODE_JS) { // Unlike browsers, Node doesn't require us to do a periodic setTimeout From 97b6f33cc28a46efc34f9fb3215612e3cc36d665 Mon Sep 17 00:00:00 2001 From: Mert Akinc <7282195+m-akinc@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:45:23 -0500 Subject: [PATCH 2/4] Add test, update rexex pattern and constant name --- spec/core/ClearStackSpec.js | 13 +++++++++++++ src/core/ClearStack.js | 8 +++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/spec/core/ClearStackSpec.js b/spec/core/ClearStackSpec.js index 626969f5..3f9b47b1 100644 --- a/spec/core/ClearStackSpec.js +++ b/spec/core/ClearStackSpec.js @@ -22,6 +22,19 @@ describe('ClearStack', function() { }); }); + describe('in WebKit (Playwright\'s build for Windows)', function() { + usesQueueMicrotaskWithSetTimeout(function() { + return { + navigator: { + userAgent: + 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/605.1.15 (KHTML, like Gecko)' + }, + // queueMicrotask should be used even though MessageChannel is present + MessageChannel: fakeMessageChannel + }; + }); + }); + describe('in browsers other than Safari', function() { usesMessageChannel(function() { return { diff --git a/src/core/ClearStack.js b/src/core/ClearStack.js index 23b6da78..b5711c08 100644 --- a/src/core/ClearStack.js +++ b/src/core/ClearStack.js @@ -68,9 +68,11 @@ getJasmineRequireObj().clearStack = function(j$) { global.process.versions && typeof global.process.versions.node === 'string'; - const SAFARI = + // Windows builds of WebKit have a fairly generic user agent string when no application name is provided. + // See: https://github.com/WebKit/WebKit/blob/d898a3cffd9c992980016cb1fbdba272cb0c992d/Source/WebCore/platform/win/UserAgentWin.cpp#L37 + const SAFARI_OR_WIN_WEBKIT = global.navigator && - /(^((?!chrome|android).)*safari)|(^((?!chrome|android|firefox).)+$)/i.test( + /(^((?!chrome|android).)*safari)|(Win64; x64\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\)$)/i.test( global.navigator.userAgent ); @@ -79,7 +81,7 @@ getJasmineRequireObj().clearStack = function(j$) { // so we avoid the overhead. return nodeQueueMicrotaskImpl(global); } else if ( - SAFARI || + SAFARI_OR_WIN_WEBKIT || j$.util.isUndefined(global.MessageChannel) /* tests */ ) { // queueMicrotask is dramatically faster than MessageChannel in Safari, From bc3ed7433658e4b97e38365d6e602571852db443 Mon Sep 17 00:00:00 2001 From: Mert Akinc <7282195+m-akinc@users.noreply.github.com> Date: Fri, 26 Jul 2024 17:54:04 -0500 Subject: [PATCH 3/4] Formatting fix --- spec/core/ClearStackSpec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/core/ClearStackSpec.js b/spec/core/ClearStackSpec.js index 3f9b47b1..b60aee7e 100644 --- a/spec/core/ClearStackSpec.js +++ b/spec/core/ClearStackSpec.js @@ -22,7 +22,7 @@ describe('ClearStack', function() { }); }); - describe('in WebKit (Playwright\'s build for Windows)', function() { + describe("in WebKit (Playwright's build for Windows)", function() { usesQueueMicrotaskWithSetTimeout(function() { return { navigator: { From 554dfd4923d39ba1a24c965f3d08933ec53082a0 Mon Sep 17 00:00:00 2001 From: Mert Akinc <7282195+m-akinc@users.noreply.github.com> Date: Mon, 5 Aug 2024 12:27:11 -0500 Subject: [PATCH 4/4] Update comments as requested --- src/core/ClearStack.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/ClearStack.js b/src/core/ClearStack.js index b5711c08..c8b2ed21 100644 --- a/src/core/ClearStack.js +++ b/src/core/ClearStack.js @@ -68,8 +68,8 @@ getJasmineRequireObj().clearStack = function(j$) { global.process.versions && typeof global.process.versions.node === 'string'; - // Windows builds of WebKit have a fairly generic user agent string when no application name is provided. - // See: https://github.com/WebKit/WebKit/blob/d898a3cffd9c992980016cb1fbdba272cb0c992d/Source/WebCore/platform/win/UserAgentWin.cpp#L37 + // Windows builds of WebKit have a fairly generic user agent string when no application name is provided: + // e.g. "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/605.1.15 (KHTML, like Gecko)" const SAFARI_OR_WIN_WEBKIT = global.navigator && /(^((?!chrome|android).)*safari)|(Win64; x64\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\)$)/i.test( @@ -84,8 +84,9 @@ getJasmineRequireObj().clearStack = function(j$) { SAFARI_OR_WIN_WEBKIT || j$.util.isUndefined(global.MessageChannel) /* tests */ ) { - // queueMicrotask is dramatically faster than MessageChannel in Safari, - // at least through version 16. + // queueMicrotask is dramatically faster than MessageChannel in Safari + // and other WebKit-based browsers, such as the one distributed by Playwright + // to test Safari-like behavior on Windows. // Some of our own integration tests provide a mock queueMicrotask in all // environments because it's simpler to mock than MessageChannel. return browserQueueMicrotaskImpl(global);