diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/data/testinit.js | 12 | ||||
-rw-r--r-- | test/index.html | 4 | ||||
-rw-r--r-- | test/jquery.js | 23 |
3 files changed, 30 insertions, 9 deletions
diff --git a/test/data/testinit.js b/test/data/testinit.js index 7a8697189..4088e4671 100644 --- a/test/data/testinit.js +++ b/test/data/testinit.js @@ -299,14 +299,16 @@ QUnit.testUnlessIE = QUnit.isIE ? QUnit.skip : QUnit.test; this.loadTests = function() { - // Directly load tests that need synchronous evaluation - if ( !QUnit.urlParams.esmodules || document.readyState === "loading" ) { + // QUnit.config is populated from QUnit.urlParams but only at the beginning + // of the test run. We need to read both. + var amd = QUnit.config.amd || QUnit.urlParams.amd; + + // Directly load tests that need evaluation before DOMContentLoaded. + if ( !amd || document.readyState === "loading" ) { document.write( "<script src='" + parentUrl + "test/unit/ready.js'><\x2Fscript>" ); } else { QUnit.module( "ready", function() { - QUnit.test( "jQuery ready", function( assert ) { - assert.ok( false, "Test should be initialized before DOM ready" ); - } ); + QUnit.skip( "jQuery ready tests skipped in async mode", function() {} ); } ); } diff --git a/test/index.html b/test/index.html index 632275bb3..fff50faab 100644 --- a/test/index.html +++ b/test/index.html @@ -19,7 +19,7 @@ <!-- See testinit for the list of tests --> <script src="data/testinit.js"></script> - <!-- A script that includes jQuery min, dev, or ES modules --> + <!-- A script that includes jQuery min, dev, ES modules or AMD --> <!-- Adds "basic" URL option, even to iframes --> <!-- iframes will not load AMD as loading needs to be synchronous for some tests --> <!-- Also executes the function above to load tests --> @@ -29,7 +29,7 @@ // Load tests if they have not been loaded // This is in a different script tag to ensure that // jQuery is on the page when the testrunner executes - if ( !QUnit.urlParams.esmodules ) { + if ( !QUnit.urlParams.esmodules && !QUnit.urlParams.amd ) { loadTests(); } </script> diff --git a/test/jquery.js b/test/jquery.js index d6d53fb26..c34c7c491 100644 --- a/test/jquery.js +++ b/test/jquery.js @@ -28,7 +28,12 @@ QUnit.config.urlConfig.push( { id: "esmodules", label: "Load as modules", - tooltip: "Load a relevant jQuery module file (and its dependencies)" + tooltip: "Load the jQuery module file (and its dependencies)" + } ); + QUnit.config.urlConfig.push( { + id: "amd", + label: "Load with AMD", + tooltip: "Load the AMD jQuery file (and its dependencies)" } ); } @@ -39,7 +44,7 @@ } ); } - // Honor AMD loading on the main window (detected by seeing QUnit on it). + // Honor ES modules loading on the main window (detected by seeing QUnit on it). // This doesn't apply to iframes because they synchronously expect jQuery to be there. if ( urlParams.esmodules && window.QUnit ) { @@ -57,6 +62,20 @@ eval( dynamicImportSource ); + // Apply similar treatment for AMD modules + } else if ( urlParams.amd && window.QUnit ) { + require.config( { + baseUrl: parentUrl + } ); + src = "amd/jquery"; + + // Include tests if specified + if ( typeof loadTests !== "undefined" ) { + require( [ src ], loadTests ); + } else { + require( [ src ] ); + } + // Otherwise, load synchronously } else { document.write( "<script id='jquery-js' nonce='jquery+hardcoded+nonce' src='" + parentUrl + src + "'><\x2Fscript>" ); |