mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 07:17:50 +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
|
||||
source = source.replace(/(?:\s*\/\/.*)*\n( +)if *\(value.length *=== *0[\s\S]+?\n\1}/, '');
|
||||
|
||||
source = removeVar(source, 'extendIteratorOptions');
|
||||
source = removeVar(source, 'hasDontEnumBug');
|
||||
source = removeVar(source, 'iteratorTemplate');
|
||||
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/qunit.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/test/noconflict.js"></script>
|
||||
<script src="../vendor/backbone/test/events.js"></script>
|
||||
|
||||
@@ -8,46 +8,57 @@
|
||||
<body>
|
||||
<div id="qunit"></div>
|
||||
<script src="../vendor/qunit/qunit/qunit.js"></script>
|
||||
<script src="ui.js"></script>
|
||||
<script>
|
||||
var _2,
|
||||
_3 = Object.keys;
|
||||
|
||||
// set a bad shim
|
||||
Object._keys = Object.keys;
|
||||
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 src="../lodash.js"></script>
|
||||
<script>
|
||||
var lodashBadKeys = _,
|
||||
_ = 1;
|
||||
// store Lo-Dash to test for bad shim detection
|
||||
var lodashBadShim = _;
|
||||
|
||||
Object.keys = _3;
|
||||
_3 = void 0;
|
||||
// restore nativeKeys
|
||||
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 src="../lodash.js"></script>
|
||||
<script src="../vendor/requirejs/require.js"></script>
|
||||
<script>
|
||||
if (/[?&]norequire=true(?:&|$)/.test(location.search)) {
|
||||
require = define = null;
|
||||
document.write('<script src="test.js"><\/script>');
|
||||
}
|
||||
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';
|
||||
// load Lo-Dash as a module
|
||||
var lodashModule,
|
||||
underscoreModule;
|
||||
|
||||
_3 = lodashAsUnderscore.noConflict();
|
||||
_3.moduleName = 'underscore';
|
||||
window.require && require({
|
||||
'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>
|
||||
</body>
|
||||
</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 */
|
||||
var load = typeof require == 'function' ? require : window.load;
|
||||
@@ -71,7 +72,7 @@
|
||||
(function() {
|
||||
test('supports loading lodash.js as the "lodash" module', function() {
|
||||
if (window.document && window.require) {
|
||||
equal((_2 || {}).moduleName, 'lodash');
|
||||
equal((lodashModule || {}).moduleName, 'lodash');
|
||||
} else {
|
||||
skipTest(1)
|
||||
}
|
||||
@@ -79,15 +80,15 @@
|
||||
|
||||
test('supports loading lodash.js as the "underscore" module', function() {
|
||||
if (window.document && window.require) {
|
||||
equal((_3 || {}).moduleName, 'underscore');
|
||||
equal((underscoreModule || {}).moduleName, 'underscore');
|
||||
} else {
|
||||
skipTest(1)
|
||||
}
|
||||
});
|
||||
|
||||
test('avoids overwritten native methods', function() {
|
||||
if (window.lodashBadKeys) {
|
||||
notDeepEqual(lodashBadKeys.keys({ 'a': 1 }), []);
|
||||
if (window.document) {
|
||||
notDeepEqual(lodashBadShim.keys({ 'a': 1 }), []);
|
||||
} else {
|
||||
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/qunit.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/arrays.js"></script>
|
||||
<script src="../vendor/underscore/test/functions.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user