mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-15 13:17:50 +00:00
Add baseEach tests.
This commit is contained in:
@@ -240,6 +240,12 @@
|
||||
};
|
||||
}
|
||||
|
||||
function loadTests() {
|
||||
require(['test'], function() {
|
||||
QUnit.start();
|
||||
});
|
||||
}
|
||||
|
||||
function loadModulesAndTests() {
|
||||
require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
||||
var oldDash = window._;
|
||||
@@ -259,9 +265,14 @@
|
||||
if (oldDash || ui.isModularize) {
|
||||
window._ = lodash;
|
||||
}
|
||||
require(['test'], function() {
|
||||
QUnit.start();
|
||||
if (ui.isModularize) {
|
||||
require(['lodash/internals/baseEach'], function(baseEach) {
|
||||
lodash._baseEach = baseEach;
|
||||
loadTests();
|
||||
});
|
||||
} else {
|
||||
loadTests();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (window.requirejs) {
|
||||
|
||||
52
test/test.js
52
test/test.js
@@ -243,9 +243,11 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
// add values from other realms
|
||||
// setup values for Node.js
|
||||
(function() {
|
||||
if (!amd) {
|
||||
if (amd) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// add values from a different realm
|
||||
_.extend(_, require('vm').runInNewContext([
|
||||
@@ -264,20 +266,18 @@
|
||||
"'_undefined': undefined,",
|
||||
'})'
|
||||
].join('\n')));
|
||||
|
||||
}
|
||||
catch(e) {
|
||||
return;
|
||||
}
|
||||
// load ES6 Set shim
|
||||
require('./asset/set');
|
||||
|
||||
// fake `WinRTError`
|
||||
setProperty(global, 'WinRTError', Error);
|
||||
|
||||
// fake DOM
|
||||
setProperty(global, 'window', {});
|
||||
setProperty(global.window, 'document', {});
|
||||
setProperty(global.window.document, 'createDocumentFragment', function() {
|
||||
return { 'nodeType': 11 };
|
||||
});
|
||||
|
||||
// expose `baseEach`
|
||||
if (isModularize && !isNpm) {
|
||||
var path = require('path');
|
||||
_._baseEach = require(path.join(path.dirname(filePath), 'internals', 'baseEach.js'));
|
||||
}
|
||||
// allow bypassing native checks
|
||||
var _fnToString = Function.prototype.toString;
|
||||
setProperty(Function.prototype, 'toString', (function() {
|
||||
@@ -290,6 +290,16 @@
|
||||
return fnToString;
|
||||
}()));
|
||||
|
||||
// fake DOM
|
||||
setProperty(global, 'window', {});
|
||||
setProperty(global.window, 'document', {});
|
||||
setProperty(global.window.document, 'createDocumentFragment', function() {
|
||||
return { 'nodeType': 11 };
|
||||
});
|
||||
|
||||
// fake `WinRTError`
|
||||
setProperty(global, 'WinRTError', Error);
|
||||
|
||||
// add extensions
|
||||
Function.prototype._method = function() {};
|
||||
|
||||
@@ -337,7 +347,6 @@
|
||||
setProperty(Object, 'defineProperty', _defineProperty);
|
||||
setProperty(Object, 'getPrototypeOf', _getPrototypeOf);
|
||||
setProperty(Object, 'keys', _keys);
|
||||
|
||||
setProperty(Function.prototype, 'toString', _fnToString);
|
||||
|
||||
_.forOwn({
|
||||
@@ -357,9 +366,13 @@
|
||||
delete global.window;
|
||||
delete global.WinRTError;
|
||||
delete Function.prototype._method;
|
||||
} catch(e) { }
|
||||
}());
|
||||
|
||||
// add values from an iframe
|
||||
(function() {
|
||||
if (_._object || !document) {
|
||||
return;
|
||||
}
|
||||
if (!_._object && document) {
|
||||
var iframe = document.createElement('iframe');
|
||||
iframe.frameBorder = iframe.height = iframe.width = 0;
|
||||
body.appendChild(iframe);
|
||||
@@ -383,7 +396,6 @@
|
||||
'<\/script>'
|
||||
].join('\n'));
|
||||
idoc.close();
|
||||
}
|
||||
}());
|
||||
|
||||
// add web worker
|
||||
@@ -2972,9 +2984,11 @@
|
||||
|
||||
QUnit.module('exit early');
|
||||
|
||||
_.forEach(['forEach', 'forEachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight'], function(methodName) {
|
||||
_.forEach(['_baseEach', 'forEach', 'forEachRight', 'forIn', 'forInRight', 'forOwn', 'forOwnRight'], function(methodName) {
|
||||
var func = _[methodName];
|
||||
|
||||
if (!func) {
|
||||
return;
|
||||
}
|
||||
test('`_.' + methodName + '` can exit early when iterating arrays', 1, function() {
|
||||
var array = [1, 2, 3],
|
||||
values = [];
|
||||
|
||||
Reference in New Issue
Block a user