Allow switching the module loader in the unit tests.

Former-commit-id: 8521e92925cbca8ff73adf3f1a350caa662e27f7
This commit is contained in:
John-David Dalton
2013-07-07 16:24:26 -07:00
parent b1b06a38af
commit 9b21656314
4 changed files with 74 additions and 36 deletions

View File

@@ -7,8 +7,8 @@
/** The Lo-Dash build to load */
var build = (/build=([^&]+)/.exec(location.search) || [])[1];
/** A flag to determine if RequireJS should be loaded */
var norequire = /[?&]norequire=true(?:&|$)/.test(location.search);
/** The module loader to use */
var loader = (/loader=([^&]+)/.exec(location.search) || [])[1];
/** The `ui` object */
var ui = {};
@@ -23,6 +23,7 @@
case 'lodash-modern': return 'dist/lodash.min.js';
case 'lodash-legacy': return 'dist/lodash.legacy.min.js';
case 'lodash-mobile': return 'dist/lodash.mobile.min.js';
case 'lodash-modularize': return 'modularize/lodash.js';
case 'lodash-underscore': return 'dist/lodash.underscore.min.js';
case 'lodash-custom-dev': return 'lodash.custom.js';
case 'lodash-custom': return 'lodash.custom.min.js';
@@ -30,16 +31,25 @@
return 'lodash.js';
}());
// expose module loader file path
ui.loaderPath = (function() {
switch (loader) {
case 'curl': return 'vendor/curl/src/curl.js';
case 'dojo': return 'vendor/dojo/dojo.js';
}
return 'vendor/requirejs/require.js';
}());
// assign `QUnit.urlParams` properties
QUnit.extend(QUnit.urlParams, {
'build': build,
'norequire': norequire
'loader': loader
});
// initialize controls
addEvent(window, 'load', function() {
function eventHandler(event) {
var search = location.search.replace(/^\?|&?(?:build|norequire)=[^&]*&?/g, '');
var search = location.search.replace(/^\?|&?(?:build|loader)=[^&]*&?/g, '');
if (event.stopPropagation) {
event.stopPropagation();
} else {
@@ -48,8 +58,8 @@
location.href =
location.href.split('?')[0] + '?' +
(search ? search + '&' : '') +
'build=' + buildList[buildList.selectedIndex].value +
(checkbox.checked ? '&norequire=true' : '');
'build=' + buildList[buildList.selectedIndex].value + '&' +
'loader=' + loaderList[loaderList.selectedIndex].value;
}
function init() {
@@ -65,16 +75,25 @@
case 'lodash-modern': return 3;
case 'lodash-legacy': return 4;
case 'lodash-mobile': return 5;
case 'lodash-underscore': return 6;
case 'lodash-custom-dev': return 7;
case 'lodash-custom': return 8;
case 'lodash-modularize': return 6;
case 'lodash-underscore': return 7;
case 'lodash-custom-dev': return 8;
case 'lodash-custom': return 9;
}
return 0;
}());
checkbox.checked = norequire;
addEvent(checkbox, 'click', eventHandler);
loaderList.selectedIndex = (function() {
switch (loader) {
case 'none': return 0
case 'curl': return 1;
case 'dojo': return 2;
}
return 3;
}());
addEvent(buildList, 'change', eventHandler);
addEvent(loaderList, 'change', eventHandler);
}
else {
setTimeout(init, 15);
@@ -82,13 +101,8 @@
}
var span1 = document.createElement('span');
span1.style.cssText = 'float:right';
span1.innerHTML =
'<input id="qunit-norequire" type="checkbox">' +
'<label for="qunit-norequire">No RequireJS</label>';
var span2 = document.createElement('span');
span2.style.cssText = 'float:right';
span2.innerHTML =
'<label for="qunit-build">Build: </label>' +
'<select id="qunit-build">' +
'<option value="lodash-compat-dev">Lo-Dash (compat development)</option>' +
@@ -97,13 +111,25 @@
'<option value="lodash-modern">Lo-Dash (modern production)</option>' +
'<option value="lodash-legacy">Lo-Dash (legacy)</option>' +
'<option value="lodash-mobile">Lo-Dash (mobile)</option>' +
'<option value="lodash-modularize">Lo-Dash (modularize)</option>' +
'<option value="lodash-underscore">Lo-Dash (underscore)</option>' +
'<option value="lodash-custom-dev">Lo-Dash (custom development)</option>' +
'<option value="lodash-custom">Lo-Dash (custom production)</option>' +
'</select>';
var checkbox = span1.firstChild,
buildList = span2.lastChild;
var span2 = document.createElement('span');
span2.style.cssText = 'float:right';
span2.innerHTML =
'<label for="qunit-loader">Loader: </label>' +
'<select id="qunit-loader">' +
'<option value="none">None</option>' +
'<option value="curl">Curl</option>' +
'<option value="dojo">Dojo</option>' +
'<option value="requirejs">RequireJS</option>' +
'</select>';
var buildList = span1.lastChild,
loaderList = span2.lastChild;
init();
});