]> source.dussan.org Git - jquery-ui.git/commitdiff
Tests: Make Puppeter really fire Chrome on macOS
authorMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Thu, 30 Mar 2023 07:59:42 +0000 (09:59 +0200)
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Wed, 10 May 2023 08:53:57 +0000 (10:53 +0200)
Also, workaround issues with QUnit Chrome bridge: the Chrome bridge
from `grunt-contrib-qunit` is now getting injected into every single
iframe, including an empty one that has no intention of running QUnit
tests. Since that bridge requires QUnit, it fails with an error
in such cases. Workaround the issue by wrapping the bridge in
another function that bails early if QUnit is not defined.

Ref gh-2157

Gruntfile.js
tests/lib/grunt-contrib-qunit-bridges/bridge-wrapper.js.intro [new file with mode: 0644]
tests/lib/grunt-contrib-qunit-bridges/bridge-wrapper.js.outro [new file with mode: 0644]

index 3456e00644cc1983a89469fa4949c58fcb458610..6c29ebe9e073fd4d0487096744538aae98b7c57c 100644 (file)
@@ -209,15 +209,18 @@ grunt.initConfig( {
                } ),
                options: {
                        puppeteer: {
-                               ignoreDefaultArgs: true,
                                args: [
-                                       "--headless",
-                                       "--disable-web-security",
                                        "--allow-file-access-from-files"
                                ]
                        },
                        inject: [
-                               require.resolve( "grunt-contrib-qunit/chrome/bridge" )
+                               require.resolve(
+                                       "./tests/lib/grunt-contrib-qunit-bridges/bridge-wrapper.js.intro"
+                               ),
+                               require.resolve( "grunt-contrib-qunit/chrome/bridge" ),
+                               require.resolve(
+                                       "./tests/lib/grunt-contrib-qunit-bridges/bridge-wrapper.js.outro"
+                               )
                        ],
                        page: {
                                viewportSize: { width: 700, height: 500 }
diff --git a/tests/lib/grunt-contrib-qunit-bridges/bridge-wrapper.js.intro b/tests/lib/grunt-contrib-qunit-bridges/bridge-wrapper.js.intro
new file mode 100644 (file)
index 0000000..227aa6c
--- /dev/null
@@ -0,0 +1,20 @@
+// The bridge in `node_modules/grunt-contrib-qunit/chrome/bridge.js` is injected
+// into every iframe, even an empty one injected during QUnit tests. The bridge,
+// in turn, requires QUnit to be present on the page, throwing errors otherwise.
+// To workaround that, add another wrapper which detects a missing QUnit and skips
+// the whole logic.
+
+( function ( factory ) {
+       if ( typeof define === 'function' && define.amd ) {
+               require( [ 'qunit' ], factory );
+       } else {
+               factory( window.QUnit );
+       }
+} )( function( QUnit ) {
+
+if ( !QUnit ) {
+
+       // No QUnit => possibly an empty iframe injected in tests; ignore.
+       return;
+}
+
diff --git a/tests/lib/grunt-contrib-qunit-bridges/bridge-wrapper.js.outro b/tests/lib/grunt-contrib-qunit-bridges/bridge-wrapper.js.outro
new file mode 100644 (file)
index 0000000..647170a
--- /dev/null
@@ -0,0 +1,2 @@
+
+} );