mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
405 lines
12 KiB
HTML
405 lines
12 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Lo-Dash Test Suite</title>
|
|
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
|
|
<style>
|
|
#exports {
|
|
display: none;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<script>
|
|
// avoid reporting tests to Sauce Labs when script errors occur
|
|
if (location.port == '9001') {
|
|
window.onerror = function(message) {
|
|
if (window.QUnit) {
|
|
QUnit.config.done.length = 0;
|
|
}
|
|
global_test_results = { 'message': message };
|
|
};
|
|
}
|
|
</script>
|
|
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
|
|
<script src="../node_modules/qunit-extras/qunit-extras.js"></script>
|
|
<script src="../node_modules/platform/platform.js"></script>
|
|
<script src="./asset/set.js"></script>
|
|
<script src="./asset/weakmap.js"></script>
|
|
<script src="./asset/test-ui.js"></script>
|
|
<div id="qunit"></div>
|
|
<div id="exports"></div>
|
|
<script>
|
|
var setProperty = (function() {
|
|
var _defineProperty = Object.defineProperty;
|
|
return function(object, key, value) {
|
|
try {
|
|
_defineProperty(object, key, {
|
|
'configurable': true,
|
|
'enumerable': false,
|
|
'writable': true,
|
|
'value': value
|
|
});
|
|
} catch(e) {
|
|
object[key] = value;
|
|
}
|
|
};
|
|
}());
|
|
|
|
function addBizarroMethods() {
|
|
var funcProto = Function.prototype,
|
|
objectProto = Object.prototype,
|
|
stringProto = String.prototype;
|
|
|
|
var hasOwnProperty = objectProto.hasOwnProperty,
|
|
fnToString = funcProto.toString,
|
|
nativeString = fnToString.call(objectProto.toString),
|
|
noop = function() {},
|
|
propertyIsEnumerable = objectProto.propertyIsEnumerable,
|
|
reToString = /toString/g,
|
|
whitespace = ' \t\x0B\f\xA0\ufeff\n\r\u2028\u2029\u1680\u180E\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000';
|
|
|
|
function constant(value) {
|
|
return function() {
|
|
return value;
|
|
};
|
|
}
|
|
function createToString(funcName) {
|
|
return constant(nativeString.replace(reToString, funcName));
|
|
}
|
|
// allow bypassing native checks
|
|
setProperty(funcProto, 'toString', (function() {
|
|
function wrapper() {
|
|
setProperty(funcProto, 'toString', fnToString);
|
|
var result = hasOwnProperty.call(this, 'toString') ? this.toString() : fnToString.call(this);
|
|
setProperty(funcProto, 'toString', wrapper);
|
|
return result;
|
|
}
|
|
return wrapper;
|
|
}()));
|
|
|
|
// add extensions
|
|
funcProto._method = noop;
|
|
|
|
// set bad shims
|
|
setProperty(Array, '_isArray', Array.isArray);
|
|
setProperty(Array, 'isArray', noop);
|
|
|
|
setProperty(Date, '_now', Date.now);
|
|
setProperty(Date, 'now', noop);
|
|
|
|
setProperty(Object, '_getPrototypeOf', Object.getPrototypeOf);
|
|
setProperty(Object, 'getPrototypeOf', noop);
|
|
|
|
setProperty(Object, '_keys', Object.keys);
|
|
setProperty(Object, 'keys', noop);
|
|
|
|
setProperty(objectProto, '_propertyIsEnumerable', propertyIsEnumerable);
|
|
setProperty(objectProto, 'propertyIsEnumerable', function(key) {
|
|
if (key == '1' && this && typeof this == 'object' && this.length === 2 &&
|
|
hasOwnProperty.call(this, 'callee') &&
|
|
!propertyIsEnumerable.call(this, 'callee') &&
|
|
this[0] === 0 && this[1] === 0) {
|
|
throw new Error;
|
|
}
|
|
return propertyIsEnumerable.call(this, key);
|
|
});
|
|
|
|
setProperty(Number, '_isFinite', Number.isFinite);
|
|
setProperty(Number, 'isFinite', noop);
|
|
|
|
setProperty(window, '_ArrayBuffer', window.ArrayBuffer);
|
|
if (window.ArrayBuffer && window.Uint8Array) {
|
|
ArrayBuffer = (function(_ArrayBuffer) {
|
|
function ArrayBuffer(byteLength) {
|
|
var buffer = new _ArrayBuffer(byteLength);
|
|
if (!byteLength) {
|
|
setProperty(buffer, 'slice', buffer.slice ? null : bufferSlice);
|
|
}
|
|
return buffer;
|
|
}
|
|
function bufferSlice() {
|
|
var newBuffer = new _ArrayBuffer(this.byteLength),
|
|
view = new Uint8Array(newBuffer);
|
|
|
|
view.set(new Uint8Array(this));
|
|
return newBuffer;
|
|
}
|
|
setProperty(ArrayBuffer, 'toString', createToString('ArrayBuffer'));
|
|
setProperty(bufferSlice, 'toString', createToString('slice'));
|
|
return ArrayBuffer;
|
|
}(_ArrayBuffer));
|
|
}
|
|
if (!window.Float64Array && window.Uint8Array) {
|
|
Float64Array = (function() {
|
|
function Float64Array(buffer, byteOffset, length) {
|
|
return arguments.length == 1
|
|
? new Uint8Array(buffer)
|
|
: new Uint8Array(buffer, byteOffset || 0, length || buffer.byteLength);
|
|
}
|
|
setProperty(Float64Array, 'BYTES_PER_ELEMENT', 8);
|
|
setProperty(Float64Array, 'toString', createToString('Float64Array'));
|
|
return Float64Array;
|
|
}());
|
|
}
|
|
setProperty(window, '_Set', window.Set);
|
|
setProperty(window, 'Set', noop);
|
|
|
|
setProperty(window, '_WeakMap', window.WeakMap);
|
|
setProperty(window, 'WeakMap', noop);
|
|
|
|
setProperty(window, '_parseInt', parseInt);
|
|
setProperty(window, 'parseInt', (function(_parseInt) {
|
|
var checkStr = whitespace + '08',
|
|
isFaked = _parseInt(checkStr) != 8,
|
|
reHexPrefix = /^0[xX]/,
|
|
reTrim = RegExp('^[' + whitespace + ']+|[' + whitespace + ']+$');
|
|
|
|
return function(value, radix) {
|
|
if (value == checkStr && !isFaked) {
|
|
isFaked = true;
|
|
return 0;
|
|
}
|
|
value = String(value == null ? '' : value).replace(reTrim, '');
|
|
return _parseInt(value, +radix || (reHexPrefix.test(value) ? 16 : 10));
|
|
};
|
|
}(_parseInt)));
|
|
|
|
// fake lack of DOM support
|
|
setProperty(document, '_createDocumentFragment', document.createDocumentFragment);
|
|
document.createDocumentFragment = noop;
|
|
|
|
// fake `WinRTError`
|
|
setProperty(window, 'WinRTError', Error);
|
|
|
|
// fake free variable `global`
|
|
setProperty(window, 'exports', window);
|
|
setProperty(window, 'global', window);
|
|
setProperty(window, 'module', {});
|
|
}
|
|
|
|
function removeBizarroMethods() {
|
|
var funcProto = Function.prototype,
|
|
objectProto = Object.prototype,
|
|
stringProto = String.prototype;
|
|
|
|
if (Array._isArray) {
|
|
setProperty(Array, 'isArray', Array._isArray);
|
|
} else {
|
|
delete Array.isArray;
|
|
}
|
|
if (Date._now) {
|
|
setProperty(Date, 'now', Date._now);
|
|
} else {
|
|
delete Date.now;
|
|
}
|
|
if (Object._getPrototypeOf) {
|
|
setProperty(Object, 'getPrototypeOf', Object._getPrototypeOf);
|
|
} else {
|
|
delete Object.getPrototypeOf;
|
|
}
|
|
if (Object._keys) {
|
|
setProperty(Object, 'keys', Object._keys);
|
|
} else {
|
|
delete Object.keys;
|
|
}
|
|
if (Number._isFinite) {
|
|
setProperty(Number, 'isFinite', Number._isFinite);
|
|
} else {
|
|
delete Number.isFinite;
|
|
}
|
|
if (window._ArrayBuffer) {
|
|
ArrayBuffer = _ArrayBuffer;
|
|
}
|
|
setProperty(window, '_ArrayBuffer', undefined);
|
|
|
|
if (window._Set) {
|
|
Set = _Set;
|
|
}
|
|
setProperty(window, '_Set', undefined);
|
|
|
|
if (window._WeakMap) {
|
|
WeakMap = _WeakMap;
|
|
}
|
|
setProperty(window, '_WeakMap', undefined);
|
|
|
|
setProperty(window, 'parseInt', window._parseInt);
|
|
setProperty(window, '_parseInt', undefined);
|
|
|
|
document.createDocumentFragment = document._createDocumentFragment;
|
|
setProperty(document, '_createDocumentFragment', undefined);
|
|
|
|
setProperty(window, 'WinRTError', undefined);
|
|
|
|
setProperty(window, 'exports', undefined);
|
|
setProperty(window, 'global', undefined);
|
|
setProperty(window, 'module', undefined);
|
|
|
|
setProperty(objectProto, 'propertyIsEnumerable', objectProto._propertyIsEnumerable);
|
|
|
|
delete Array._isArray;
|
|
delete Date._now;
|
|
delete funcProto._method;
|
|
delete Object._create;
|
|
delete Object._getPrototypeOf;
|
|
delete Object._keys;
|
|
delete objectProto._propertyIsEnumerable;
|
|
}
|
|
|
|
// load Lo-Dash and expose it to the bad extensions/shims
|
|
if (!ui.isModularize) {
|
|
addBizarroMethods();
|
|
document.write('<script src="' + ui.buildPath + '"><\/script>');
|
|
}
|
|
</script>
|
|
<script>
|
|
// store Lo-Dash to test for bad extensions/shims
|
|
if (!ui.isModularize) {
|
|
var lodashBizarro = window._;
|
|
window._ = undefined;
|
|
removeBizarroMethods();
|
|
}
|
|
// load test scripts
|
|
document.write((ui.isForeign || ui.urlParams.loader == 'none')
|
|
? '<script src="' + ui.buildPath + '"><\/script><script src="test.js"><\/script>'
|
|
: '<script data-dojo-config="async:1" src="' + ui.loaderPath + '"><\/script>'
|
|
);
|
|
</script>
|
|
<script>
|
|
var lodashModule,
|
|
shimmedModule,
|
|
underscoreModule;
|
|
|
|
(function() {
|
|
if (window.curl) {
|
|
curl.config({ 'apiName': 'require' });
|
|
}
|
|
if (ui.isForeign || !window.require) {
|
|
return;
|
|
}
|
|
var reBasename = /[\w.-]+$/,
|
|
basePath = ('//' + location.host + location.pathname.replace(reBasename, '')).replace(/\btest\/$/, ''),
|
|
modulePath = ui.buildPath.replace(/\.js$/, ''),
|
|
moduleMain = modulePath.match(reBasename)[0],
|
|
locationPath = modulePath.replace(reBasename, '').replace(/^\/|\/$/g, ''),
|
|
shimmedLocationPath = './abc/../' + locationPath,
|
|
underscoreLocationPath = './xyz/../' + locationPath,
|
|
uid = +new Date;
|
|
|
|
function getConfig() {
|
|
var result = {
|
|
'baseUrl': './',
|
|
'urlArgs': 't=' + uid++,
|
|
'waitSeconds': 0,
|
|
'paths': {},
|
|
'packages': [{
|
|
'name': 'test',
|
|
'location': basePath + 'test',
|
|
'main': 'test',
|
|
'config': {
|
|
// work around no global being exported
|
|
'exports': 'QUnit',
|
|
'loader': 'curl/loader/legacy'
|
|
}
|
|
}],
|
|
'shim': {
|
|
'shimmed': {
|
|
'exports': '_'
|
|
}
|
|
}
|
|
};
|
|
|
|
if (ui.isModularize) {
|
|
result.packages.push({
|
|
'name': 'lodash',
|
|
'location': locationPath,
|
|
'main': moduleMain
|
|
}, {
|
|
'name': 'shimmed',
|
|
'location': shimmedLocationPath,
|
|
'main': moduleMain
|
|
}, {
|
|
'name': 'underscore',
|
|
'location': underscoreLocationPath,
|
|
'main': moduleMain
|
|
});
|
|
} else {
|
|
result.paths.lodash = modulePath;
|
|
result.paths.shimmed = shimmedLocationPath + '/' + moduleMain;
|
|
result.paths.underscore = underscoreLocationPath + '/' + moduleMain;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function loadTests() {
|
|
require(getConfig(), ['test'], function() {
|
|
QUnit.start();
|
|
});
|
|
}
|
|
|
|
function loadModulesAndTests() {
|
|
require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
|
lodashModule = lodash;
|
|
lodashModule.moduleName = 'lodash';
|
|
|
|
if (shimmed) {
|
|
shimmedModule = shimmed.result(shimmed, 'noConflict') || shimmed;
|
|
shimmedModule.moduleName = 'shimmed';
|
|
}
|
|
if (underscore) {
|
|
underscoreModule = underscore.result(underscore, 'noConflict') || underscore;
|
|
underscoreModule.moduleName = 'underscore';
|
|
}
|
|
if (ui.isModularize) {
|
|
window._ = lodash;
|
|
}
|
|
if (ui.isModularize) {
|
|
require(getConfig(), [
|
|
'lodash/internal/baseEach',
|
|
'lodash/internal/isIndex',
|
|
'lodash/internal/isIterateeCall',
|
|
'lodash/internal/isLength'
|
|
], function(baseEach, isIndex, isIterateeCall, isLength) {
|
|
lodash._baseEach = baseEach;
|
|
lodash._isIndex = isIndex;
|
|
lodash._isIterateeCall = isIterateeCall;
|
|
lodash._isLength = isLength;
|
|
loadTests();
|
|
});
|
|
} else {
|
|
loadTests();
|
|
}
|
|
});
|
|
}
|
|
|
|
QUnit.config.autostart = false;
|
|
|
|
if (window.requirejs) {
|
|
addBizarroMethods();
|
|
require(getConfig(), ['lodash'], function(lodash) {
|
|
lodashBizarro = lodash.result(lodash, 'noConflict') || lodash;
|
|
delete requirejs.s.contexts._;
|
|
|
|
removeBizarroMethods();
|
|
loadModulesAndTests();
|
|
});
|
|
} else {
|
|
loadModulesAndTests();
|
|
}
|
|
}());
|
|
|
|
// set a more readable browser name
|
|
window.onload = function() {
|
|
var timeoutId = setInterval(function() {
|
|
var ua = document.getElementById('qunit-userAgent');
|
|
if (ua) {
|
|
ua.innerHTML = platform;
|
|
clearInterval(timeoutId);
|
|
}
|
|
}, 16);
|
|
};
|
|
</script>
|
|
</body>
|
|
</html>
|