more flexible async loading helper, converted select test

This commit is contained in:
John Bender 2011-12-20 16:58:57 -08:00
parent 621348b05b
commit 810edd8472
2 changed files with 22 additions and 26 deletions

View file

@ -4,32 +4,27 @@
(function( $ ) {
$.testHelper = {
asyncLoad: function( opts ) {
var baseUrl = opts.baseUrl || "../../../js";
// synchronously loads sets of asynchronous dependencies
asyncLoad: function( seq ) {
function loadSeq( seq, i ){
if( !seq[i] ){
QUnit.start();
return;
}
require({
baseUrl: (seq[i][0].indexOf(".") > -1) ? "../../../js" : location.pathname
});
require( seq[i], function() {
loadSeq(seq, i + 1);
});
}
// stop qunit from running the tests until everything is in the page
QUnit.config.autostart = false;
// set the baseUrl to the js dir or the default
require({
baseUrl: baseUrl
});
// require the libs required to pass the test suite
require( opts.libs, function() {
// init the mobile library
require( ["jquery.mobile.init"], function() {
// reset the base dir to the current directory for including the test libs
require({
baseUrl: location.pathname
});
// after everything is inplace start the test suite
require( opts.testLibs, QUnit.start);
});
});
loadSeq( seq, 0 );
},
excludeFileProtocol: function(callback){

View file

@ -11,18 +11,19 @@
<script src="../../../tests/jquery.testHelper.js"></script>
<script src="../../../external/require.js"></script>
<script>
$.testHelper.asyncLoad({
libs: [
$.testHelper.asyncLoad([
[
"jquery.mobile.forms.select",
"jquery.mobile.forms.select.custom"
],
testLibs: [
[ "jquery.mobile.init" ],
[
"select_events",
"select_native",
"select_cached",
"select_core"
]
});
]);
</script>
<link rel="stylesheet" href="../../../css/themes/default/"/>