Commit be1e4eee authored by Timmy Willison's avatar Timmy Willison

Convert testrunner to an AMD module and ensure jQuery is on the page when...

Convert testrunner to an AMD module and ensure jQuery is on the page when executing the testrunner (another race condition amplified by swarm)

Conflicts:
	test/data/testinit.js
	test/data/testrunner.js
parent d14904d0
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
"globals": { "globals": {
"require": false, "require": false,
"define": false,
"DOMParser": false, "DOMParser": false,
"QUnit": false, "QUnit": false,
"ok": false, "ok": false,
......
...@@ -259,9 +259,13 @@ this.iframeCallback = undefined; ...@@ -259,9 +259,13 @@ this.iframeCallback = undefined;
QUnit.config.autostart = false; QUnit.config.autostart = false;
this.loadTests = function() { this.loadTests = function() {
var loadSwarm, var loadSwarm,
url = window.location.search, url = window.location.search;
tests = [ url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + "swarmURL=".length ) );
"data/testrunner.js", loadSwarm = url && url.indexOf("http") === 0;
// Get testSubproject from testrunner first
require([ "data/testrunner.js" ], function( testSubproject ) {
var tests = [
"unit/core.js", "unit/core.js",
"unit/callbacks.js", "unit/callbacks.js",
"unit/deferred.js", "unit/deferred.js",
...@@ -281,8 +285,6 @@ this.loadTests = function() { ...@@ -281,8 +285,6 @@ this.loadTests = function() {
"unit/offset.js", "unit/offset.js",
"unit/dimensions.js" "unit/dimensions.js"
]; ];
url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + "swarmURL=".length ) );
loadSwarm = url && url.indexOf("http") === 0;
// Ensure load order (to preserve test numbers) // Ensure load order (to preserve test numbers)
(function loadDep() { (function loadDep() {
...@@ -295,15 +297,6 @@ this.loadTests = function() { ...@@ -295,15 +297,6 @@ this.loadTests = function() {
// Call load to build module filter select element // Call load to build module filter select element
QUnit.load(); QUnit.load();
// Load the TestSwarm listener if swarmURL is in the address.
if ( loadSwarm ) {
require( [ "http://swarm.jquery.org/js/inject.js?" + (new Date()).getTime() ], function() {
QUnit.start();
});
} else {
QUnit.start();
}
/** /**
* Run in noConflict mode * Run in noConflict mode
*/ */
...@@ -317,7 +310,17 @@ this.loadTests = function() { ...@@ -317,7 +310,17 @@ this.loadTests = function() {
supportjQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) { supportjQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) {
window[ name ] = window[ name ]; window[ name ] = window[ name ];
}); });
// Load the TestSwarm listener if swarmURL is in the address.
if ( loadSwarm ) {
require( [ "http://swarm.jquery.org/js/inject.js?" + (new Date()).getTime() ], function() {
QUnit.start();
});
} else {
QUnit.start();
}
}); });
} }
})(); })();
});
}; };
This diff is collapsed.
...@@ -29,6 +29,13 @@ ...@@ -29,6 +29,13 @@
).replace(/\w+/g, function(n) { ).replace(/\w+/g, function(n) {
document.createElement(n); document.createElement(n);
}); });
// 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.amd ) {
loadTests();
}
</script> </script>
</head> </head>
......
...@@ -54,11 +54,9 @@ ...@@ -54,11 +54,9 @@
// Load jQuery // Load jQuery
document.write( "<script id='jquery-js' src='" + path + src + "'><\x2Fscript>" ); document.write( "<script id='jquery-js' src='" + path + src + "'><\x2Fscript>" );
// Load tests if available
// These can be loaded async as QUnit won't start until finished
if ( typeof loadTests !== "undefined" ) {
loadTests();
// Synchronous-only tests // Synchronous-only tests
// Other tests are loaded from the test page
if ( typeof loadTests !== "undefined" ) {
document.write( "<script src='" + path + "test/unit/ready.js'><\x2Fscript>"); document.write( "<script src='" + path + "test/unit/ready.js'><\x2Fscript>");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment