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,65 +259,68 @@ this.iframeCallback = undefined; ...@@ -259,65 +259,68 @@ 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 = [
"data/testrunner.js",
"unit/core.js",
"unit/callbacks.js",
"unit/deferred.js",
"unit/support.js",
"unit/data.js",
"unit/queue.js",
"unit/attributes.js",
"unit/event.js",
"unit/selector.js",
"unit/traversing.js",
"unit/manipulation.js",
"unit/wrap.js",
"unit/css.js",
"unit/serialize.js",
"unit/ajax.js",
"unit/effects.js",
"unit/offset.js",
"unit/dimensions.js"
];
url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + "swarmURL=".length ) ); url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + "swarmURL=".length ) );
loadSwarm = url && url.indexOf("http") === 0; loadSwarm = url && url.indexOf("http") === 0;
// Ensure load order (to preserve test numbers) // Get testSubproject from testrunner first
(function loadDep() { require([ "data/testrunner.js" ], function( testSubproject ) {
var dep = tests.shift(); var tests = [
if ( dep ) { "unit/core.js",
require( [ dep ], loadDep ); "unit/callbacks.js",
} else { "unit/deferred.js",
// Subproject tests must be last because they replace our test fixture "unit/support.js",
testSubproject( "Sizzle", "../bower_components/sizzle/test/", /^unit\/.*\.js$/, function() { "unit/data.js",
// Call load to build module filter select element "unit/queue.js",
QUnit.load(); "unit/attributes.js",
"unit/event.js",
// Load the TestSwarm listener if swarmURL is in the address. "unit/selector.js",
if ( loadSwarm ) { "unit/traversing.js",
require( [ "http://swarm.jquery.org/js/inject.js?" + (new Date()).getTime() ], function() { "unit/manipulation.js",
QUnit.start(); "unit/wrap.js",
"unit/css.js",
"unit/serialize.js",
"unit/ajax.js",
"unit/effects.js",
"unit/offset.js",
"unit/dimensions.js"
];
// Ensure load order (to preserve test numbers)
(function loadDep() {
var dep = tests.shift();
if ( dep ) {
require( [ dep ], loadDep );
} else {
// Subproject tests must be last because they replace our test fixture
testSubproject( "Sizzle", "../bower_components/sizzle/test/", /^unit\/.*\.js$/, function() {
// Call load to build module filter select element
QUnit.load();
/**
* Run in noConflict mode
*/
jQuery.noConflict();
// Expose Sizzle for Sizzle's selector tests
// We remove Sizzle's globalization in jQuery
window.Sizzle = window.Sizzle || jQuery.find;
// For checking globals pollution despite auto-created globals in various environments
supportjQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) {
window[ name ] = window[ name ];
}); });
} else {
QUnit.start();
}
/**
* Run in noConflict mode
*/
jQuery.noConflict();
// Expose Sizzle for Sizzle's selector tests // Load the TestSwarm listener if swarmURL is in the address.
// We remove Sizzle's globalization in jQuery if ( loadSwarm ) {
window.Sizzle = window.Sizzle || jQuery.find; require( [ "http://swarm.jquery.org/js/inject.js?" + (new Date()).getTime() ], function() {
QUnit.start();
// For checking globals pollution despite auto-created globals in various environments });
supportjQuery.each( [ jQuery.expando, "getInterface", "Packages", "java", "netscape" ], function( i, name ) { } else {
window[ name ] = window[ name ]; 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 // Synchronous-only tests
// These can be loaded async as QUnit won't start until finished // Other tests are loaded from the test page
if ( typeof loadTests !== "undefined" ) { if ( typeof loadTests !== "undefined" ) {
loadTests();
// Synchronous-only tests
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