mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Allow amd builds to test for bizarro methods.
This commit is contained in:
259
test/index.html
259
test/index.html
@@ -18,83 +18,85 @@
|
|||||||
<div id="qunit"></div>
|
<div id="qunit"></div>
|
||||||
<div id="exports"></div>
|
<div id="exports"></div>
|
||||||
<script>
|
<script>
|
||||||
// add extensions
|
function addBizarroMethods() {
|
||||||
Function.prototype._method = function() {};
|
// add extensions
|
||||||
|
Function.prototype._method = function() {};
|
||||||
|
|
||||||
// set bad shims
|
// set bad shims
|
||||||
Array._isArray = Array.isArray;
|
Array._isArray = Array.isArray;
|
||||||
Array.isArray = function() {};
|
Array.isArray = function() {};
|
||||||
|
|
||||||
Date._now = Date.now;
|
Date._now = Date.now;
|
||||||
Date.now = function() {};
|
Date.now = function() {};
|
||||||
|
|
||||||
Function.prototype._bind = Function.prototype.bind;
|
Function.prototype._bind = Function.prototype.bind;
|
||||||
Function.prototype.bind = function() { return function() {}; };
|
Function.prototype.bind = function() { return function() {}; };
|
||||||
|
|
||||||
Object._create = Object.create;
|
Object._create = Object.create;
|
||||||
Object.create = function() {};
|
Object.create = function() {};
|
||||||
|
|
||||||
Object._defineProperty = Object.defineProperty;
|
Object._defineProperty = Object.defineProperty;
|
||||||
Object.defineProperty = function() {};
|
Object.defineProperty = function() {};
|
||||||
|
|
||||||
Object._getPrototypeOf = Object.getPrototypeOf;
|
Object._getPrototypeOf = Object.getPrototypeOf;
|
||||||
Object.getPrototypeOf = function() {};
|
Object.getPrototypeOf = function() {};
|
||||||
|
|
||||||
Object._keys = Object.keys;
|
Object._keys = Object.keys;
|
||||||
Object.keys = function() {};
|
Object.keys = function() {};
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeBizarroMethods() {
|
||||||
|
if (Array._isArray) {
|
||||||
|
Array.isArray = Array._isArray;
|
||||||
|
} else {
|
||||||
|
delete Array.isArray;
|
||||||
|
}
|
||||||
|
if (Date._now) {
|
||||||
|
Date.now = Date._now;
|
||||||
|
} else {
|
||||||
|
delete Date.now;
|
||||||
|
}
|
||||||
|
if (Function.prototype._bind) {
|
||||||
|
Function.prototype.bind = Function.prototype._bind;
|
||||||
|
} else {
|
||||||
|
delete Function.prototype.bind;
|
||||||
|
}
|
||||||
|
if (Object._create) {
|
||||||
|
Object.create = Object._create;
|
||||||
|
} else {
|
||||||
|
delete Object.create;
|
||||||
|
}
|
||||||
|
if (Object._defineProperty) {
|
||||||
|
Object.defineProperty = Object._defineProperty;
|
||||||
|
} else {
|
||||||
|
delete Object.defineProperty;
|
||||||
|
}
|
||||||
|
if (Object._getPrototypeOf) {
|
||||||
|
Object.getPrototypeOf = Object._getPrototypeOf;
|
||||||
|
} else {
|
||||||
|
delete Object.getPrototypeOf;
|
||||||
|
}
|
||||||
|
if (Object._keys) {
|
||||||
|
Object.keys = Object._keys;
|
||||||
|
} else {
|
||||||
|
delete Object.keys;
|
||||||
|
}
|
||||||
|
delete Array._isArray;
|
||||||
|
delete Date._now;
|
||||||
|
delete Function.prototype._bind;
|
||||||
|
delete Function.prototype._method;
|
||||||
|
delete Object._create;
|
||||||
|
delete Object._defineProperty;
|
||||||
|
delete Object._getPrototypeOf;
|
||||||
|
delete Object._keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
addBizarroMethods();
|
||||||
|
|
||||||
// load Lo-Dash and expose it to the bad extensions/shims
|
// load Lo-Dash and expose it to the bad extensions/shims
|
||||||
document.write('<script src="' + (ui.isModularize ? '../lodash.js' : ui.buildPath) + '"><\/script>');
|
document.write('<script src="' + (ui.isModularize ? '../lodash.js' : ui.buildPath) + '"><\/script>');
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
// store Lo-Dash to test for bad extensions/shims
|
|
||||||
var lodashBizarro = window._;
|
|
||||||
|
|
||||||
// restore native methods
|
|
||||||
if (Array._isArray) {
|
|
||||||
Array.isArray = Array._isArray;
|
|
||||||
} else {
|
|
||||||
delete Array.isArray;
|
|
||||||
}
|
|
||||||
if (Date._now) {
|
|
||||||
Date.now = Date._now;
|
|
||||||
} else {
|
|
||||||
delete Date.now;
|
|
||||||
}
|
|
||||||
if (Function.prototype._bind) {
|
|
||||||
Function.prototype.bind = Function.prototype._bind;
|
|
||||||
} else {
|
|
||||||
delete Function.prototype.bind;
|
|
||||||
}
|
|
||||||
if (Object._create) {
|
|
||||||
Object.create = Object._create;
|
|
||||||
} else {
|
|
||||||
delete Object.create;
|
|
||||||
}
|
|
||||||
if (Object._defineProperty) {
|
|
||||||
Object.defineProperty = Object._defineProperty;
|
|
||||||
} else {
|
|
||||||
delete Object.defineProperty;
|
|
||||||
}
|
|
||||||
if (Object._getPrototypeOf) {
|
|
||||||
Object.getPrototypeOf = Object._getPrototypeOf;
|
|
||||||
} else {
|
|
||||||
delete Object.getPrototypeOf;
|
|
||||||
}
|
|
||||||
if (Object._keys) {
|
|
||||||
Object.keys = Object._keys;
|
|
||||||
} else {
|
|
||||||
delete Object.keys;
|
|
||||||
}
|
|
||||||
delete Array._isArray;
|
|
||||||
delete Date._now;
|
|
||||||
delete Function.prototype._bind;
|
|
||||||
delete Function.prototype._method;
|
|
||||||
delete Object._create;
|
|
||||||
delete Object._defineProperty;
|
|
||||||
delete Object._getPrototypeOf;
|
|
||||||
delete Object._keys;
|
|
||||||
|
|
||||||
QUnit.config.hidepassed = true;
|
QUnit.config.hidepassed = true;
|
||||||
|
|
||||||
// assign results to `global_test_results` for Sauce Labs
|
// assign results to `global_test_results` for Sauce Labs
|
||||||
@@ -103,8 +105,10 @@
|
|||||||
global_test_results = results;
|
global_test_results = results;
|
||||||
});
|
});
|
||||||
|
|
||||||
// clear existing `_` value
|
// store Lo-Dash to test for bad extensions/shims
|
||||||
|
var lodashBizarro = window._;
|
||||||
window._ = undefined;
|
window._ = undefined;
|
||||||
|
removeBizarroMethods();
|
||||||
|
|
||||||
// load Lo-Dash and test scripts
|
// load Lo-Dash and test scripts
|
||||||
document.write(ui.urlParams.loader == 'none'
|
document.write(ui.urlParams.loader == 'none'
|
||||||
@@ -132,63 +136,80 @@
|
|||||||
|
|
||||||
QUnit.config.autostart = false;
|
QUnit.config.autostart = false;
|
||||||
|
|
||||||
// load Lo-Dash as a module
|
function getConfig() {
|
||||||
require({
|
return {
|
||||||
'baseUrl': './',
|
'baseUrl': './',
|
||||||
'urlArgs': 't=' + (+new Date),
|
'urlArgs': 't=' + (+new Date),
|
||||||
'packages': [
|
'packages': [
|
||||||
{
|
{
|
||||||
'name': 'lodash',
|
'name': 'lodash',
|
||||||
'location': locationPath,
|
'location': locationPath,
|
||||||
'main': moduleMain
|
'main': moduleMain
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'shimmed',
|
'name': 'shimmed',
|
||||||
'location': './abc/../' + locationPath,
|
'location': './abc/../' + locationPath,
|
||||||
'main': moduleMain
|
'main': moduleMain
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'underscore',
|
'name': 'underscore',
|
||||||
'location': './xyz/../' + locationPath,
|
'location': './xyz/../' + locationPath,
|
||||||
'main': moduleMain
|
'main': moduleMain
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
'name': 'test',
|
'name': 'test',
|
||||||
'location': basePath + '/test',
|
'location': basePath + '/test',
|
||||||
'main': 'test',
|
'main': 'test',
|
||||||
'config': {
|
'config': {
|
||||||
// work around no global being exported
|
// work around no global being exported
|
||||||
'exports': 'QUnit',
|
'exports': 'QUnit',
|
||||||
'loader': 'curl/loader/legacy'
|
'loader': 'curl/loader/legacy'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
'shim': {
|
||||||
|
'shimmed': {
|
||||||
|
'exports': '_'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
};
|
||||||
'shim': {
|
}
|
||||||
'shimmed': {
|
|
||||||
'exports': '_'
|
function loadModulesAndTests() {
|
||||||
|
require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
||||||
|
if (shimmed && shimmed.noConflict) {
|
||||||
|
shimmedModule = shimmed.noConflict();
|
||||||
|
shimmedModule.moduleName = 'shimmed';
|
||||||
}
|
}
|
||||||
}
|
if (underscore && underscore.noConflict) {
|
||||||
},
|
underscoreModule = underscore.noConflict();
|
||||||
['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
underscoreModule.moduleName = 'underscore';
|
||||||
if (shimmed && shimmed.noConflict) {
|
}
|
||||||
shimmedModule = shimmed.noConflict();
|
if (lodash) {
|
||||||
shimmedModule.moduleName = 'shimmed';
|
lodashModule = lodash;
|
||||||
}
|
lodashModule.moduleName = 'lodash';
|
||||||
if (underscore && underscore.noConflict) {
|
}
|
||||||
underscoreModule = underscore.noConflict();
|
if (ui.isModularize) {
|
||||||
underscoreModule.moduleName = 'underscore';
|
window._ = lodash;
|
||||||
}
|
}
|
||||||
if (lodash) {
|
require(['test'], function() {
|
||||||
lodashModule = lodash;
|
QUnit.start();
|
||||||
lodashModule.moduleName = 'lodash';
|
});
|
||||||
}
|
|
||||||
if (ui.isModularize) {
|
|
||||||
window._ = lodash;
|
|
||||||
}
|
|
||||||
require(['test'], function() {
|
|
||||||
QUnit.start();
|
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
if (window.requirejs) {
|
||||||
|
addBizarroMethods();
|
||||||
|
|
||||||
|
require(getConfig(), ['lodash'], function(lodash) {
|
||||||
|
lodashBizarro = lodash;
|
||||||
|
delete requirejs.s.contexts._;
|
||||||
|
|
||||||
|
removeBizarroMethods();
|
||||||
|
loadModulesAndTests();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
loadModulesAndTests();
|
||||||
|
}
|
||||||
}());
|
}());
|
||||||
|
|
||||||
// set a more readable browser name
|
// set a more readable browser name
|
||||||
|
|||||||
Reference in New Issue
Block a user