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