mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 10:57:49 +00:00
Add interopRequire test helper.
This commit is contained in:
34
test/test.js
34
test/test.js
@@ -209,7 +209,7 @@
|
|||||||
'buildPath': filePath,
|
'buildPath': filePath,
|
||||||
'loaderPath': '',
|
'loaderPath': '',
|
||||||
'isModularize': /\b(?:amd|commonjs|es|node|npm|(index|main)\.js)\b/.test(filePath),
|
'isModularize': /\b(?:amd|commonjs|es|node|npm|(index|main)\.js)\b/.test(filePath),
|
||||||
'isStrict': /\bes\b/.test(filePath),
|
'isStrict': /\bes\b/.test(filePath) || 'default' in require(filePath),
|
||||||
'urlParams': {}
|
'urlParams': {}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -295,19 +295,14 @@
|
|||||||
});
|
});
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
/** Use a single "load" function. */
|
|
||||||
var load = (!amd && typeof require == 'function')
|
|
||||||
? require
|
|
||||||
: noop;
|
|
||||||
|
|
||||||
/** Load QUnit and extras. */
|
/** Load QUnit and extras. */
|
||||||
var QUnit = root.QUnit || load('qunit-extras');
|
var QUnit = root.QUnit || require('qunit-extras');
|
||||||
|
|
||||||
/** Load stable Lodash. */
|
/** Load stable Lodash. */
|
||||||
var lodashStable = root.lodashStable;
|
var lodashStable = root.lodashStable;
|
||||||
if (!lodashStable) {
|
if (!lodashStable) {
|
||||||
try {
|
try {
|
||||||
lodashStable = load('../node_modules/lodash/lodash.js');
|
lodashStable = interopRequire('../node_modules/lodash/lodash.js');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Error: The stable lodash dev dependency should be at least a version behind master branch.');
|
console.log('Error: The stable lodash dev dependency should be at least a version behind master branch.');
|
||||||
return;
|
return;
|
||||||
@@ -318,8 +313,7 @@
|
|||||||
|
|
||||||
/** The `lodash` function to test. */
|
/** The `lodash` function to test. */
|
||||||
var _ = root._ || (root._ = (
|
var _ = root._ || (root._ = (
|
||||||
_ = load(filePath),
|
_ = interopRequire(filePath),
|
||||||
_ = _._ || (isStrict = ui.isStrict = isStrict || 'default' in _, _['default']) || _,
|
|
||||||
(_.runInContext ? _.runInContext(root) : _)
|
(_.runInContext ? _.runInContext(root) : _)
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -420,6 +414,19 @@
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads the module of `id`. If the module has an `exports.default`, the
|
||||||
|
* exported default value is returned as the resolved module.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {string} id The identifier of the module to resolve.
|
||||||
|
* @returns {*} Returns the resolved module.
|
||||||
|
*/
|
||||||
|
function interopRequire(id) {
|
||||||
|
var result = require(id);
|
||||||
|
return 'default' in result ? result['default'] : result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a non-enumerable property value on `object`.
|
* Sets a non-enumerable property value on `object`.
|
||||||
*
|
*
|
||||||
@@ -545,7 +552,7 @@
|
|||||||
emptyObject(require.cache);
|
emptyObject(require.cache);
|
||||||
|
|
||||||
// Load lodash and expose it to the bad extensions/shims.
|
// Load lodash and expose it to the bad extensions/shims.
|
||||||
lodashBizarro = (lodashBizarro = require(filePath))._ || lodashBizarro['default'] || lodashBizarro;
|
lodashBizarro = interopRequire(filePath);
|
||||||
root._ = oldDash;
|
root._ = oldDash;
|
||||||
|
|
||||||
// Restore built-in methods.
|
// Restore built-in methods.
|
||||||
@@ -704,8 +711,7 @@
|
|||||||
'isIndex',
|
'isIndex',
|
||||||
'isIterateeCall'
|
'isIterateeCall'
|
||||||
], function(funcName) {
|
], function(funcName) {
|
||||||
var func = require(path.join(basePath, '_' + funcName));
|
_['_' + funcName] = interopRequire(path.join(basePath, '_' + funcName));
|
||||||
_['_' + funcName] = func[funcName] || func['default'] || func;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -11043,7 +11049,7 @@
|
|||||||
root[coreKey] = { 'keys': { 'IE_PROTO': 'Symbol(IE_PROTO)_3.' + uid } };
|
root[coreKey] = { 'keys': { 'IE_PROTO': 'Symbol(IE_PROTO)_3.' + uid } };
|
||||||
emptyObject(require.cache);
|
emptyObject(require.cache);
|
||||||
|
|
||||||
var baseIsNative = require(path.join(basePath, '_baseIsNative'));
|
var baseIsNative = interopRequire(path.join(basePath, '_baseIsNative'));
|
||||||
assert.strictEqual(baseIsNative(slice), true);
|
assert.strictEqual(baseIsNative(slice), true);
|
||||||
|
|
||||||
slice[fakeSrcKey] = slice + '';
|
slice[fakeSrcKey] = slice + '';
|
||||||
|
|||||||
Reference in New Issue
Block a user