mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Allow switching the module loader in the unit tests.
Former-commit-id: 8521e92925cbca8ff73adf3f1a350caa662e27f7
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
* @param {Function} handler The event handler.
|
||||
* @returns {Element} The element.
|
||||
*/
|
||||
function addListener(element, eventName, handler) {
|
||||
function addEvent(element, eventName, handler) {
|
||||
if (typeof element.addEventListener != 'undefined') {
|
||||
element.addEventListener(eventName, handler, false);
|
||||
} else if (typeof element.attachEvent != 'undefined') {
|
||||
@@ -71,7 +71,7 @@
|
||||
}());
|
||||
|
||||
// initialize controls
|
||||
addListener(window, 'load', function() {
|
||||
addEvent(window, 'load', function() {
|
||||
function eventHandler(event) {
|
||||
var search = location.search.replace(/^\?|&?(?:build|other)=[^&]*&?/g, '');
|
||||
if (event.stopPropagation) {
|
||||
|
||||
@@ -36,9 +36,9 @@
|
||||
document.write('<script src="../' + ui.buildPath + '"><\/script>');
|
||||
|
||||
// load test.js if not using require.js
|
||||
document.write(QUnit.urlParams.norequire
|
||||
document.write(QUnit.urlParams.loader == 'none'
|
||||
? '<script src="test.js"><\/script>'
|
||||
: '<script src="../vendor/requirejs/require.js"><\/script>'
|
||||
: '<script data-dojo-config="async:1,parseOnLoad:false" src="../' + ui.loaderPath + '"><\/script>'
|
||||
);
|
||||
</script>
|
||||
<script>
|
||||
@@ -47,30 +47,33 @@
|
||||
shimmedModule,
|
||||
underscoreModule;
|
||||
|
||||
if (window.curl) {
|
||||
var require = curl;
|
||||
}
|
||||
window.require && require(
|
||||
(function() {
|
||||
var modulePath = ui.buildPath.replace(/\.js$/, '');
|
||||
return {
|
||||
'baseUrl': '../vendor/requirejs/',
|
||||
'baseUrl': './',
|
||||
'urlArgs': 't=' + (+new Date),
|
||||
'paths': {
|
||||
'lodash': '../../' + modulePath,
|
||||
'shimmed': './../../' + modulePath,
|
||||
'underscore': '../underscore/../../' + modulePath
|
||||
'lodash': '../' + modulePath,
|
||||
'shimmed': '../abc/../' + modulePath,
|
||||
'underscore': '../xyz/../' + modulePath
|
||||
},
|
||||
'aliases': [
|
||||
['shimmed', 'lodash'],
|
||||
['underscore', 'lodash']
|
||||
],
|
||||
'shim': {
|
||||
'shimmed': {
|
||||
'exports': '_'
|
||||
'exports': '_'
|
||||
}
|
||||
}
|
||||
};
|
||||
}()),
|
||||
['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
||||
if (lodash && lodash.noConflict) {
|
||||
lodashModule = lodash.noConflict();
|
||||
lodashModule.moduleName = 'lodash';
|
||||
}
|
||||
if (shimmed.noConflict) {
|
||||
if (shimmed && shimmed.noConflict) {
|
||||
shimmedModule = shimmed.noConflict();
|
||||
shimmedModule.moduleName = 'shimmed';
|
||||
}
|
||||
@@ -78,6 +81,10 @@
|
||||
underscoreModule = underscore.noConflict();
|
||||
underscoreModule.moduleName = 'underscore';
|
||||
}
|
||||
if (lodash && lodash.noConflict) {
|
||||
lodashModule = lodash.noConflict();
|
||||
lodashModule.moduleName = 'lodash';
|
||||
}
|
||||
require(['test.js']);
|
||||
});
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
11
test/test.js
11
test/test.js
@@ -32,7 +32,7 @@
|
||||
: '../lodash.js';
|
||||
|
||||
try {
|
||||
return require('fs').realpathSync(result);
|
||||
return global.require('fs').realpathSync(result);
|
||||
} catch(e) {
|
||||
return result;
|
||||
}
|
||||
@@ -99,6 +99,11 @@
|
||||
/** Used to check problem JScript properties too */
|
||||
var shadowedObject = _.invert(shadowedProps);
|
||||
|
||||
/** The `ui` object */
|
||||
var ui = window.ui || (window.ui = {
|
||||
'loaderPath': ''
|
||||
});
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
@@ -146,7 +151,7 @@
|
||||
});
|
||||
|
||||
test('supports loading ' + basename + ' with the Require.js "shim" configuration option', function() {
|
||||
if (amd) {
|
||||
if (amd && /requirejs/.test(ui.loaderPath)) {
|
||||
equal((shimmedModule || {}).moduleName, 'shimmed');
|
||||
} else {
|
||||
skipTest();
|
||||
@@ -154,7 +159,7 @@
|
||||
});
|
||||
|
||||
test('supports loading ' + basename + ' as the "underscore" module', function() {
|
||||
if (amd) {
|
||||
if (amd && !/dojo/.test(ui.loaderPath)) {
|
||||
equal((underscoreModule || {}).moduleName, 'underscore');
|
||||
} else {
|
||||
skipTest();
|
||||
|
||||
Reference in New Issue
Block a user