mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-05 09:27:49 +00:00
Make tests work with es6 transpiled code.
This commit is contained in:
@@ -128,11 +128,14 @@
|
|||||||
init();
|
init();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// used to indicate that Lo-Dash is in strict mode
|
||||||
|
ui.isStrict = /\b(?:lodash-es6|transpiled)\b/.test([location.pathname, location.search]);
|
||||||
|
|
||||||
// used to indicate testing a foreign file
|
// used to indicate testing a foreign file
|
||||||
ui.isForeign = RegExp('^(\\w+:)?//').test(build);
|
ui.isForeign = RegExp('^(\\w+:)?//').test(build);
|
||||||
|
|
||||||
// used to indicate testing a modularized build
|
// used to indicate testing a modularized build
|
||||||
ui.isModularize = /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|es6|node)|modularize|npm)\b/.test([location.pathname, location.search]);
|
ui.isModularize = /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|es6|node)|modularize|npm|transpiled)\b/.test([location.pathname, location.search]);
|
||||||
|
|
||||||
// used to indicate testing in Sauce Labs' automated test cloud
|
// used to indicate testing in Sauce Labs' automated test cloud
|
||||||
ui.isSauceLabs = location.port == '9001';
|
ui.isSauceLabs = location.port == '9001';
|
||||||
|
|||||||
@@ -126,6 +126,9 @@
|
|||||||
QUnit.config.autostart = false;
|
QUnit.config.autostart = false;
|
||||||
|
|
||||||
require(getConfig(), ['underscore', 'backbone'], function(lodash) {
|
require(getConfig(), ['underscore', 'backbone'], function(lodash) {
|
||||||
|
ui.isStrict || (ui.isStrict = 'default' in lodash);
|
||||||
|
lodash = (lodash['default'] || lodash);
|
||||||
|
|
||||||
mixinPrereqs(lodash);
|
mixinPrereqs(lodash);
|
||||||
|
|
||||||
if (ui.isModularize) {
|
if (ui.isModularize) {
|
||||||
|
|||||||
@@ -258,6 +258,15 @@
|
|||||||
|
|
||||||
function loadModulesAndTests() {
|
function loadModulesAndTests() {
|
||||||
require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
require(getConfig(), ['lodash', 'shimmed', 'underscore'], function(lodash, shimmed, underscore) {
|
||||||
|
ui.isStrict || (ui.isStrict = 'default' in lodash);
|
||||||
|
lodash = lodash['default'] || lodash;
|
||||||
|
|
||||||
|
lodashModule = lodash;
|
||||||
|
lodashModule.moduleName = 'lodash';
|
||||||
|
|
||||||
|
shimmed = shimmed && (shimmed['default'] || shimmmed);
|
||||||
|
underscore = underscore && (underscore['default'] || underscore);
|
||||||
|
|
||||||
if (shimmed && shimmed.noConflict) {
|
if (shimmed && shimmed.noConflict) {
|
||||||
shimmedModule = shimmed.noConflict();
|
shimmedModule = shimmed.noConflict();
|
||||||
shimmedModule.moduleName = 'shimmed';
|
shimmedModule.moduleName = 'shimmed';
|
||||||
@@ -266,16 +275,12 @@
|
|||||||
underscoreModule = underscore.noConflict();
|
underscoreModule = underscore.noConflict();
|
||||||
underscoreModule.moduleName = 'underscore';
|
underscoreModule.moduleName = 'underscore';
|
||||||
}
|
}
|
||||||
if (lodash) {
|
|
||||||
lodashModule = lodash;
|
|
||||||
lodashModule.moduleName = 'lodash';
|
|
||||||
}
|
|
||||||
if (ui.isModularize) {
|
if (ui.isModularize) {
|
||||||
window._ = lodash;
|
window._ = lodash;
|
||||||
}
|
}
|
||||||
if (ui.isModularize) {
|
if (ui.isModularize) {
|
||||||
require(getConfig(), ['lodash/internals/baseEach'], function(baseEach) {
|
require(getConfig(), ['lodash/internals/baseEach'], function(baseEach) {
|
||||||
lodash._baseEach = baseEach;
|
lodash._baseEach = baseEach['default'] || baseEach;
|
||||||
loadTests();
|
loadTests();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -289,7 +294,7 @@
|
|||||||
if (window.requirejs) {
|
if (window.requirejs) {
|
||||||
addBizarroMethods();
|
addBizarroMethods();
|
||||||
require(getConfig(), ['lodash'], function(lodash) {
|
require(getConfig(), ['lodash'], function(lodash) {
|
||||||
lodashBizarro = lodash.noConflict();
|
lodashBizarro = (lodash['default'] || lodash).noConflict();
|
||||||
delete requirejs.s.contexts._;
|
delete requirejs.s.contexts._;
|
||||||
|
|
||||||
removeBizarroMethods();
|
removeBizarroMethods();
|
||||||
|
|||||||
26
test/test.js
26
test/test.js
@@ -67,7 +67,8 @@
|
|||||||
var ui = root.ui || (root.ui = {
|
var ui = root.ui || (root.ui = {
|
||||||
'buildPath': filePath,
|
'buildPath': filePath,
|
||||||
'loaderPath': '',
|
'loaderPath': '',
|
||||||
'isModularize': /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|es6|node)|modularize|npm)\b/.test(filePath),
|
'isModularize': /\b(?:commonjs|(index|main)\.js|lodash-(?:amd|es6|node)|modularize|npm|transpiled)\b/.test(filePath),
|
||||||
|
'isStrict': /\b(?:lodash-es6|transpiled)\b/.test(filePath),
|
||||||
'urlParams': {}
|
'urlParams': {}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -83,12 +84,15 @@
|
|||||||
/** Detect if testing `npm` modules */
|
/** Detect if testing `npm` modules */
|
||||||
var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]);
|
var isNpm = isModularize && /\bnpm\b/.test([ui.buildPath, ui.urlParams.build]);
|
||||||
|
|
||||||
/** Detects if running in PhantomJS */
|
/** Detect if running in PhantomJS */
|
||||||
var isPhantom = phantom || typeof callPhantom == 'function';
|
var isPhantom = phantom || typeof callPhantom == 'function';
|
||||||
|
|
||||||
/** Detect if running in Rhino */
|
/** Detect if running in Rhino */
|
||||||
var isRhino = isJava && typeof global == 'function' && global().Array === root.Array;
|
var isRhino = isJava && typeof global == 'function' && global().Array === root.Array;
|
||||||
|
|
||||||
|
/** Detect if Lo-Dash is in strict mode */
|
||||||
|
var isStrict = ui.isStrict;
|
||||||
|
|
||||||
/** Used to test Web Workers */
|
/** Used to test Web Workers */
|
||||||
var Worker = !(ui.isForeign || isModularize) && document && root.Worker;
|
var Worker = !(ui.isForeign || isModularize) && document && root.Worker;
|
||||||
|
|
||||||
@@ -170,7 +174,7 @@
|
|||||||
/** The `lodash` function to test */
|
/** The `lodash` function to test */
|
||||||
var _ = root._ || (root._ = (
|
var _ = root._ || (root._ = (
|
||||||
_ = load(filePath) || root._,
|
_ = load(filePath) || root._,
|
||||||
_ = _._ || _,
|
_ = _._ || (isStrict = ui.isStrict = isStrict || 'default' in _, _['default']) || _,
|
||||||
(_.runInContext ? _.runInContext(root) : _)
|
(_.runInContext ? _.runInContext(root) : _)
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -322,7 +326,7 @@
|
|||||||
var path = require('path'),
|
var path = require('path'),
|
||||||
baseEach = require(path.join(path.dirname(filePath), 'internals', 'baseEach.js'));
|
baseEach = require(path.join(path.dirname(filePath), 'internals', 'baseEach.js'));
|
||||||
|
|
||||||
_._baseEach = baseEach.baseEach || baseEach;
|
_._baseEach = baseEach.baseEach || baseEach['default'] || baseEach;
|
||||||
}
|
}
|
||||||
// allow bypassing native checks
|
// allow bypassing native checks
|
||||||
var _fnToString = Function.prototype.toString;
|
var _fnToString = Function.prototype.toString;
|
||||||
@@ -380,7 +384,7 @@
|
|||||||
emptyObject(require.cache);
|
emptyObject(require.cache);
|
||||||
|
|
||||||
// load Lo-Dash and expose it to the bad extensions/shims
|
// load Lo-Dash and expose it to the bad extensions/shims
|
||||||
lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro;
|
lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro['default'] || lodashBizarro;
|
||||||
|
|
||||||
// restore native methods
|
// restore native methods
|
||||||
setProperty(Array, 'isArray', _isArray);
|
setProperty(Array, 'isArray', _isArray);
|
||||||
@@ -2645,9 +2649,9 @@
|
|||||||
_.each(['assign', 'bindAll', 'defaults'], function(methodName) {
|
_.each(['assign', 'bindAll', 'defaults'], function(methodName) {
|
||||||
var func = _[methodName];
|
var func = _[methodName];
|
||||||
|
|
||||||
test('`_.' + methodName + '` should not throw strict mode errors', 1, function() {
|
test('`_.' + methodName + '` should ' + (isStrict ? '' : 'not ') + 'throw strict mode errors', 1, function() {
|
||||||
var object = { 'a': null, 'b': function(){} },
|
var object = { 'a': null, 'b': function(){} },
|
||||||
pass = true;
|
pass = !isStrict;
|
||||||
|
|
||||||
if (freeze) {
|
if (freeze) {
|
||||||
freeze(object);
|
freeze(object);
|
||||||
@@ -2658,7 +2662,7 @@
|
|||||||
func(object, { 'a': 1 });
|
func(object, { 'a': 1 });
|
||||||
}
|
}
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
pass = false;
|
pass = !pass;
|
||||||
}
|
}
|
||||||
ok(pass);
|
ok(pass);
|
||||||
}
|
}
|
||||||
@@ -5726,7 +5730,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should work with `arguments` objects (test in IE < 9)', 1, function() {
|
test('`_.' + methodName + '` should work with `arguments` objects (test in IE < 9)', 1, function() {
|
||||||
if (!isPhantom) {
|
if (!(isPhantom || isStrict)) {
|
||||||
var actual = func(args);
|
var actual = func(args);
|
||||||
deepEqual(actual.sort(), ['0', '1', '2']);
|
deepEqual(actual.sort(), ['0', '1', '2']);
|
||||||
} else {
|
} else {
|
||||||
@@ -5735,7 +5739,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should custom properties on `arguments` objects', 1, function() {
|
test('`_.' + methodName + '` should custom properties on `arguments` objects', 1, function() {
|
||||||
if (!isPhantom) {
|
if (!(isPhantom || isStrict)) {
|
||||||
args.a = 1;
|
args.a = 1;
|
||||||
var actual = func(args);
|
var actual = func(args);
|
||||||
|
|
||||||
@@ -5747,7 +5751,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should ' + (isKeys ? 'not' : '') + ' include inherited properties of `arguments` objects', 1, function() {
|
test('`_.' + methodName + '` should ' + (isKeys ? 'not' : '') + ' include inherited properties of `arguments` objects', 1, function() {
|
||||||
if (!isPhantom) {
|
if (!(isPhantom || isStrict)) {
|
||||||
Object.prototype.a = 1;
|
Object.prototype.a = 1;
|
||||||
var expected = isKeys ? ['0', '1', '2'] : ['0', '1', '2', 'a'],
|
var expected = isKeys ? ['0', '1', '2'] : ['0', '1', '2', 'a'],
|
||||||
actual = func(args);
|
actual = func(args);
|
||||||
|
|||||||
@@ -234,6 +234,9 @@
|
|||||||
QUnit.config.autostart = false;
|
QUnit.config.autostart = false;
|
||||||
|
|
||||||
require(getConfig(), [moduleId], function(lodash) {
|
require(getConfig(), [moduleId], function(lodash) {
|
||||||
|
ui.isStrict || (ui.isStrict = 'default' in lodash);
|
||||||
|
lodash = (lodash['default'] || lodash);
|
||||||
|
|
||||||
if (ui.isModularize) {
|
if (ui.isModularize) {
|
||||||
window._ = lodash;
|
window._ = lodash;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user