Skip to content

Commit 360259e

Browse files
committed
Tests: Make Puppeter really fire Chrome on macOS
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
1 parent afb83c3 commit 360259e

3 files changed

Lines changed: 29 additions & 4 deletions

File tree

Gruntfile.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,18 @@ grunt.initConfig( {
209209
} ),
210210
options: {
211211
puppeteer: {
212-
ignoreDefaultArgs: true,
213212
args: [
214-
"--headless",
215-
"--disable-web-security",
216213
"--allow-file-access-from-files"
217214
]
218215
},
219216
inject: [
220-
require.resolve( "grunt-contrib-qunit/chrome/bridge" )
217+
require.resolve(
218+
"./tests/lib/grunt-contrib-qunit-bridges/bridge-wrapper.js.intro"
219+
),
220+
require.resolve( "grunt-contrib-qunit/chrome/bridge" ),
221+
require.resolve(
222+
"./tests/lib/grunt-contrib-qunit-bridges/bridge-wrapper.js.outro"
223+
)
221224
],
222225
page: {
223226
viewportSize: { width: 700, height: 500 }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// The bridge in `node_modules/grunt-contrib-qunit/chrome/bridge.js` is injected
2+
// into every iframe, even an empty one injected during QUnit tests. The bridge,
3+
// in turn, requires QUnit to be present on the page, throwing errors otherwise.
4+
// To workaround that, add another wrapper which detects a missing QUnit and skips
5+
// the whole logic.
6+
7+
( function ( factory ) {
8+
if ( typeof define === 'function' && define.amd ) {
9+
require( [ 'qunit' ], factory );
10+
} else {
11+
factory( window.QUnit );
12+
}
13+
} )( function( QUnit ) {
14+
15+
if ( !QUnit ) {
16+
17+
// No QUnit => possibly an empty iframe injected in tests; ignore.
18+
return;
19+
}
20+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
} );

0 commit comments

Comments
 (0)