Skip to content

Commit d58aaad

Browse files
committed
Tests: 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.
1 parent 790f6dd commit d58aaad

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

Gruntfile.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,13 @@ grunt.initConfig( {
214214
]
215215
},
216216
inject: [
217-
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+
)
218224
],
219225
page: {
220226
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)