mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-06 01:47:48 +00:00
Allow different builds to be tested more easily with a dropdown menu.
Former-commit-id: a692bda9708523aa0443acb35dd8fcc5a342ef3f
This commit is contained in:
1
build.js
1
build.js
@@ -810,6 +810,7 @@
|
|||||||
// remove IE `shift` and `splice` fix
|
// remove IE `shift` and `splice` fix
|
||||||
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(value.length *=== *0[\s\S]+?\n\1}/, '');
|
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(value.length *=== *0[\s\S]+?\n\1}/, '');
|
||||||
|
|
||||||
|
source = removeVar(source, 'extendIteratorOptions');
|
||||||
source = removeVar(source, 'hasDontEnumBug');
|
source = removeVar(source, 'hasDontEnumBug');
|
||||||
source = removeVar(source, 'iteratorTemplate');
|
source = removeVar(source, 'iteratorTemplate');
|
||||||
source = removeIsArgumentsFallback(source);
|
source = removeIsArgumentsFallback(source);
|
||||||
|
|||||||
@@ -25,7 +25,10 @@
|
|||||||
<script src="../vendor/backbone/test/vendor/jquery-1.7.1.js"></script>
|
<script src="../vendor/backbone/test/vendor/jquery-1.7.1.js"></script>
|
||||||
<script src="../vendor/backbone/test/vendor/qunit.js"></script>
|
<script src="../vendor/backbone/test/vendor/qunit.js"></script>
|
||||||
<script src="../vendor/backbone/test/vendor/jslitmus.js"></script>
|
<script src="../vendor/backbone/test/vendor/jslitmus.js"></script>
|
||||||
<script src="../lodash.js"></script>
|
<script src="ui.js"></script>
|
||||||
|
<script>
|
||||||
|
document.write('<script src="../' + QUnit.config.lodashFilename + '.js"><\/script>');
|
||||||
|
</script>
|
||||||
<script src="../vendor/backbone/backbone.js"></script>
|
<script src="../vendor/backbone/backbone.js"></script>
|
||||||
<script src="../vendor/backbone/test/noconflict.js"></script>
|
<script src="../vendor/backbone/test/noconflict.js"></script>
|
||||||
<script src="../vendor/backbone/test/events.js"></script>
|
<script src="../vendor/backbone/test/events.js"></script>
|
||||||
|
|||||||
@@ -8,46 +8,57 @@
|
|||||||
<body>
|
<body>
|
||||||
<div id="qunit"></div>
|
<div id="qunit"></div>
|
||||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||||
|
<script src="ui.js"></script>
|
||||||
<script>
|
<script>
|
||||||
var _2,
|
// set a bad shim
|
||||||
_3 = Object.keys;
|
Object._keys = Object.keys;
|
||||||
|
|
||||||
Object.keys = function() { return []; };
|
Object.keys = function() { return []; };
|
||||||
|
|
||||||
|
// load Lo-Dash and expose it to the bad `Object.keys` shim
|
||||||
|
document.write('<script src="../' + QUnit.config.lodashFilename + '.js"><\/script>');
|
||||||
</script>
|
</script>
|
||||||
<script src="../lodash.js"></script>
|
|
||||||
<script>
|
<script>
|
||||||
var lodashBadKeys = _,
|
// store Lo-Dash to test for bad shim detection
|
||||||
_ = 1;
|
var lodashBadShim = _;
|
||||||
|
|
||||||
Object.keys = _3;
|
// restore nativeKeys
|
||||||
_3 = void 0;
|
Object.keys = Object._keys;
|
||||||
|
delete Object._keys;
|
||||||
|
|
||||||
|
// set to test `_.noConflict`
|
||||||
|
_ = 1;
|
||||||
|
|
||||||
|
// load Lo-Dash again to overwrite the existing `_` value
|
||||||
|
document.write('<script src="../' + QUnit.config.lodashFilename + '.js"><\/script>');
|
||||||
|
|
||||||
|
// load test.js if not using require.js
|
||||||
|
document.write(QUnit.urlParams.norequire
|
||||||
|
? '<script src="test.js"><\/script>'
|
||||||
|
: '<script src="../vendor/requirejs/require.js"><\/script>'
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
<script src="../lodash.js"></script>
|
|
||||||
<script src="../vendor/requirejs/require.js"></script>
|
|
||||||
<script>
|
<script>
|
||||||
if (/[?&]norequire=true(?:&|$)/.test(location.search)) {
|
// load Lo-Dash as a module
|
||||||
require = define = null;
|
var lodashModule,
|
||||||
document.write('<script src="test.js"><\/script>');
|
underscoreModule;
|
||||||
}
|
|
||||||
else {
|
|
||||||
require({
|
|
||||||
'baseUrl': '../vendor/requirejs/',
|
|
||||||
'urlArgs': 't=' + (+new Date),
|
|
||||||
'paths': {
|
|
||||||
'lodash': '../../lodash',
|
|
||||||
'underscore': './../../lodash'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
['lodash', 'underscore'], function(lodash, lodashAsUnderscore) {
|
|
||||||
_2 = lodash.noConflict();
|
|
||||||
_2.moduleName = 'lodash';
|
|
||||||
|
|
||||||
_3 = lodashAsUnderscore.noConflict();
|
window.require && require({
|
||||||
_3.moduleName = 'underscore';
|
'baseUrl': '../vendor/requirejs/',
|
||||||
|
'urlArgs': 't=' + (+new Date),
|
||||||
|
'paths': {
|
||||||
|
'lodash': '../../' + QUnit.config.lodashFilename,
|
||||||
|
'underscore': './../../' + QUnit.config.lodashFilename
|
||||||
|
}
|
||||||
|
},
|
||||||
|
['lodash', 'underscore'], function(lodash, underscore) {
|
||||||
|
lodashModule = lodash.noConflict();
|
||||||
|
lodashModule.moduleName = 'lodash';
|
||||||
|
|
||||||
require(['test.js']);
|
underscoreModule = underscore.noConflict();
|
||||||
});
|
underscoreModule.moduleName = 'underscore';
|
||||||
}
|
|
||||||
|
require(['test.js']);
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
11
test/test.js
11
test/test.js
@@ -1,4 +1,5 @@
|
|||||||
(function(window, undefined) {
|
;(function(window, undefined) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
/** Use a single load function */
|
/** Use a single load function */
|
||||||
var load = typeof require == 'function' ? require : window.load;
|
var load = typeof require == 'function' ? require : window.load;
|
||||||
@@ -71,7 +72,7 @@
|
|||||||
(function() {
|
(function() {
|
||||||
test('supports loading lodash.js as the "lodash" module', function() {
|
test('supports loading lodash.js as the "lodash" module', function() {
|
||||||
if (window.document && window.require) {
|
if (window.document && window.require) {
|
||||||
equal((_2 || {}).moduleName, 'lodash');
|
equal((lodashModule || {}).moduleName, 'lodash');
|
||||||
} else {
|
} else {
|
||||||
skipTest(1)
|
skipTest(1)
|
||||||
}
|
}
|
||||||
@@ -79,15 +80,15 @@
|
|||||||
|
|
||||||
test('supports loading lodash.js as the "underscore" module', function() {
|
test('supports loading lodash.js as the "underscore" module', function() {
|
||||||
if (window.document && window.require) {
|
if (window.document && window.require) {
|
||||||
equal((_3 || {}).moduleName, 'underscore');
|
equal((underscoreModule || {}).moduleName, 'underscore');
|
||||||
} else {
|
} else {
|
||||||
skipTest(1)
|
skipTest(1)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('avoids overwritten native methods', function() {
|
test('avoids overwritten native methods', function() {
|
||||||
if (window.lodashBadKeys) {
|
if (window.document) {
|
||||||
notDeepEqual(lodashBadKeys.keys({ 'a': 1 }), []);
|
notDeepEqual(lodashBadShim.keys({ 'a': 1 }), []);
|
||||||
} else {
|
} else {
|
||||||
skipTest(1);
|
skipTest(1);
|
||||||
}
|
}
|
||||||
|
|||||||
80
test/ui.js
Normal file
80
test/ui.js
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
;(function(window) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/** `QUnit.addEvent` shortcut */
|
||||||
|
var addEvent = QUnit.addEvent;
|
||||||
|
|
||||||
|
/** 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);
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// assign `QUnit.config` properties
|
||||||
|
QUnit.config.lodashFilename = build == 'prod'
|
||||||
|
? 'lodash.min'
|
||||||
|
: (build == 'custom' ? 'lodash.custom.min' : 'lodash');
|
||||||
|
|
||||||
|
// assign `QUnit.urlParams` properties
|
||||||
|
QUnit.extend(QUnit.urlParams, {
|
||||||
|
'build': build,
|
||||||
|
'norequire': norequire
|
||||||
|
});
|
||||||
|
|
||||||
|
// initialize the build dropdown
|
||||||
|
addEvent(window, 'load', function() {
|
||||||
|
function eventHandler(event) {
|
||||||
|
var search = location.search.replace(/^\?|&?(?:build|norequire)=[^&]*&?/g, '');
|
||||||
|
if (event.stopPropagation) {
|
||||||
|
event.stopPropagation();
|
||||||
|
} else {
|
||||||
|
event.cancelBubble = true;
|
||||||
|
}
|
||||||
|
location.href =
|
||||||
|
location.href.split('?')[0] + '?' +
|
||||||
|
(search ? search + '&' : '') + 'build=' +
|
||||||
|
dropdown[dropdown.selectedIndex].value +
|
||||||
|
(checkbox.checked ? '&norequire=true' : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
function init() {
|
||||||
|
var header = document.getElementById('qunit-header');
|
||||||
|
if (header) {
|
||||||
|
header.appendChild(label1);
|
||||||
|
header.appendChild(label2);
|
||||||
|
|
||||||
|
if (build == 'prod') {
|
||||||
|
dropdown.selectedIndex = 1;
|
||||||
|
} else if (build == 'custom') {
|
||||||
|
dropdown.selectedIndex = 2;
|
||||||
|
}
|
||||||
|
checkbox.checked = norequire;
|
||||||
|
addEvent(checkbox, 'click', eventHandler);
|
||||||
|
addEvent(dropdown, 'change', eventHandler);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setTimeout(init, 15);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var label1 = document.createElement('label');
|
||||||
|
label1.innerHTML =
|
||||||
|
'<input name="norequire" type="checkbox">norequire</label>';
|
||||||
|
|
||||||
|
var label2 = document.createElement('label');
|
||||||
|
label2.innerHTML =
|
||||||
|
'<select name="build">' +
|
||||||
|
'<option value="dev">developement</option>' +
|
||||||
|
'<option value="prod">production</option>' +
|
||||||
|
'<option value="custom">custom</option>' +
|
||||||
|
'</select>build';
|
||||||
|
|
||||||
|
var checkbox = label1.firstChild,
|
||||||
|
dropdown = label2.firstChild;
|
||||||
|
|
||||||
|
init();
|
||||||
|
});
|
||||||
|
|
||||||
|
}(this));
|
||||||
@@ -22,7 +22,10 @@
|
|||||||
<script src="../vendor/underscore/test/vendor/jquery.js"></script>
|
<script src="../vendor/underscore/test/vendor/jquery.js"></script>
|
||||||
<script src="../vendor/underscore/test/vendor/qunit.js"></script>
|
<script src="../vendor/underscore/test/vendor/qunit.js"></script>
|
||||||
<script src="../vendor/underscore/test/vendor/jslitmus.js"></script>
|
<script src="../vendor/underscore/test/vendor/jslitmus.js"></script>
|
||||||
<script src="../lodash.js"></script>
|
<script src="ui.js"></script>
|
||||||
|
<script>
|
||||||
|
document.write('<script src="../' + QUnit.config.lodashFilename + '.js"><\/script>');
|
||||||
|
</script>
|
||||||
<script src="../vendor/underscore/test/collections.js"></script>
|
<script src="../vendor/underscore/test/collections.js"></script>
|
||||||
<script src="../vendor/underscore/test/arrays.js"></script>
|
<script src="../vendor/underscore/test/arrays.js"></script>
|
||||||
<script src="../vendor/underscore/test/functions.js"></script>
|
<script src="../vendor/underscore/test/functions.js"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user