mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Fix tests for rhino -require.
This commit is contained in:
@@ -12,6 +12,9 @@
|
||||
/** Used as a reference to the global object */
|
||||
var root = (objectTypes[typeof window] && window) || this;
|
||||
|
||||
/** Detect free variable `exports` */
|
||||
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
|
||||
|
||||
/** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
|
||||
var freeGlobal = objectTypes[typeof global] && global;
|
||||
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
|
||||
@@ -20,6 +23,14 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Installs `Set` on the given `context` object.
|
||||
*
|
||||
* @memberOf exports
|
||||
* @param {Object} context The context object.
|
||||
*/
|
||||
function runInContext(context) {
|
||||
|
||||
/**
|
||||
* Creates a `Set` object.
|
||||
*/
|
||||
@@ -27,8 +38,6 @@
|
||||
this.__cache__ = {};
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Gets the index at which the first occurrence of `value` is found using
|
||||
* strict equality for comparisons, i.e. `===`.
|
||||
@@ -50,8 +59,6 @@
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Checks if `value` is in the set.
|
||||
*
|
||||
@@ -120,14 +127,20 @@
|
||||
return nativeString;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
Set.toString = toString;
|
||||
Set.prototype.add = add;
|
||||
Set.prototype.has = has;
|
||||
|
||||
// expose `Set`
|
||||
if (!root.Set) {
|
||||
root.Set = Set;
|
||||
context.Set = Set;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
if (freeExports) {
|
||||
freeExports.runInContext = runInContext;
|
||||
} else {
|
||||
runInContext(root);
|
||||
}
|
||||
}.call(this));
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
/** Used as a reference to the global object */
|
||||
var root = (objectTypes[typeof window] && window) || this;
|
||||
|
||||
/** Detect free variable `exports` */
|
||||
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
|
||||
|
||||
/** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
|
||||
var freeGlobal = objectTypes[typeof global] && global;
|
||||
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) {
|
||||
@@ -20,6 +23,14 @@
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Installs `WeakMap` on the given `context` object.
|
||||
*
|
||||
* @memberOf exports
|
||||
* @param {Object} context The context object.
|
||||
*/
|
||||
function runInContext(context) {
|
||||
|
||||
/**
|
||||
* Creates a `WeakMap` object.
|
||||
*/
|
||||
@@ -27,8 +38,6 @@
|
||||
// no-op
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
/**
|
||||
* Gets the value associated with the given key.
|
||||
*
|
||||
@@ -63,14 +72,20 @@
|
||||
return nativeString;
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
WeakMap.toString = toString;
|
||||
WeakMap.prototype.get = get;
|
||||
WeakMap.prototype.set = set;
|
||||
|
||||
// expose `WeakMap`
|
||||
if (!root.WeakMap) {
|
||||
root.WeakMap = WeakMap;
|
||||
context.WeakMap = WeakMap;
|
||||
}
|
||||
}
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
if (freeExports) {
|
||||
freeExports.runInContext = runInContext;
|
||||
} else {
|
||||
runInContext(root);
|
||||
}
|
||||
}.call(this));
|
||||
|
||||
52
test/test.js
52
test/test.js
@@ -117,10 +117,6 @@
|
||||
? require
|
||||
: (isJava && root.load) || noop;
|
||||
|
||||
/** Load ES6 Set and WeakMap shims */
|
||||
load('./asset/set.js');
|
||||
load('./asset/weakmap.js');
|
||||
|
||||
/** The unit testing framework */
|
||||
var QUnit = (function() {
|
||||
return root.QUnit || (
|
||||
@@ -132,11 +128,24 @@
|
||||
);
|
||||
}());
|
||||
|
||||
/** Load and install QUnit Extras */
|
||||
var qe = load('../vendor/qunit-extras/qunit-extras.js');
|
||||
if (qe) {
|
||||
qe.runInContext(root);
|
||||
/** Load and install QUnit Extras and ES6 Set/WeakMap shims */
|
||||
(function() {
|
||||
var paths = [
|
||||
'./asset/set.js',
|
||||
'./asset/weakmap.js',
|
||||
'../vendor/qunit-extras/qunit-extras.js'
|
||||
];
|
||||
|
||||
var index = -1,
|
||||
length = paths.length;
|
||||
|
||||
while (++index < length) {
|
||||
var object = load(paths[index]);
|
||||
if (object) {
|
||||
object.runInContext(root);
|
||||
}
|
||||
}
|
||||
}());
|
||||
|
||||
/*--------------------------------------------------------------------------*/
|
||||
|
||||
@@ -613,7 +622,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
test('should avoid overwritten native methods', 15, function() {
|
||||
test('should avoid overwritten native methods', 14, function() {
|
||||
function Foo() {}
|
||||
|
||||
function message(lodashMethod, nativeMethod) {
|
||||
@@ -647,13 +656,6 @@
|
||||
ok(actual[0] instanceof Foo, message('_.create', 'Object.create'));
|
||||
deepEqual(actual[1], {}, message('_.create', 'Object.create'));
|
||||
|
||||
try {
|
||||
actual = lodashBizarro.curry(function(a, b) { return [a, b]; })(1)(2);
|
||||
} catch(e) {
|
||||
actual = null;
|
||||
}
|
||||
deepEqual(actual, [1, 2], message('_.curry', 'Object.defineProperty'));
|
||||
|
||||
try {
|
||||
actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])];
|
||||
} catch(e) {
|
||||
@@ -722,7 +724,7 @@
|
||||
}
|
||||
}
|
||||
else {
|
||||
skipTest(15);
|
||||
skipTest(14);
|
||||
}
|
||||
});
|
||||
}());
|
||||
@@ -2210,19 +2212,19 @@
|
||||
|
||||
var object = {};
|
||||
|
||||
if ((defineProperty && !WeakMap) && _.support.funcDecomp) {
|
||||
_.callback(a, object);
|
||||
if (lodashBizarro && lodashBizarro.support.funcDecomp) {
|
||||
lodashBizarro.callback(a, object);
|
||||
ok(EXPANDO in a);
|
||||
|
||||
_.callback(b, object);
|
||||
lodashBizarro.callback(b, object);
|
||||
ok(!(EXPANDO in b));
|
||||
|
||||
if (_.support.funcNames) {
|
||||
_.support.funcNames = false;
|
||||
_.callback(c, object);
|
||||
if (lodashBizarro.support.funcNames) {
|
||||
lodashBizarro.support.funcNames = false;
|
||||
lodashBizarro.callback(c, object);
|
||||
|
||||
ok(EXPANDO in c);
|
||||
_.support.funcNames = true;
|
||||
lodashBizarro.support.funcNames = true;
|
||||
}
|
||||
else {
|
||||
skipTest();
|
||||
@@ -2236,7 +2238,7 @@
|
||||
test('should not write metadata when `_.support.funcDecomp` is `false`', 1, function() {
|
||||
function a() {};
|
||||
|
||||
if ((defineProperty && !WeakMap) && lodashBizarro) {
|
||||
if (lodashBizarro) {
|
||||
lodashBizarro.callback(a, {});
|
||||
ok(!(EXPANDO in a));
|
||||
}
|
||||
|
||||
4
vendor/qunit-extras/qunit-extras.js
vendored
4
vendor/qunit-extras/qunit-extras.js
vendored
@@ -177,10 +177,6 @@
|
||||
* @param {Object} context The context object.
|
||||
*/
|
||||
function runInContext(context) {
|
||||
// exit early if no `context` is provided or if `QUnit` does not exist
|
||||
if (!context || !context.QUnit) {
|
||||
return;
|
||||
}
|
||||
|
||||
/** Used to report the test module for failing tests */
|
||||
var moduleName,
|
||||
|
||||
Reference in New Issue
Block a user