Fix tests for rhino -require.

This commit is contained in:
John-David Dalton
2014-08-26 21:36:04 -07:00
parent c01623ba56
commit c4a7f899db
4 changed files with 191 additions and 165 deletions

View File

@@ -12,6 +12,9 @@
/** Used as a reference to the global object */ /** Used as a reference to the global object */
var root = (objectTypes[typeof window] && window) || this; 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` */ /** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
var freeGlobal = objectTypes[typeof global] && global; var freeGlobal = objectTypes[typeof global] && global;
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) { 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. * Creates a `Set` object.
*/ */
@@ -27,8 +38,6 @@
this.__cache__ = {}; this.__cache__ = {};
} }
/*--------------------------------------------------------------------------*/
/** /**
* Gets the index at which the first occurrence of `value` is found using * Gets the index at which the first occurrence of `value` is found using
* strict equality for comparisons, i.e. `===`. * strict equality for comparisons, i.e. `===`.
@@ -50,8 +59,6 @@
return -1; return -1;
} }
/*--------------------------------------------------------------------------*/
/** /**
* Checks if `value` is in the set. * Checks if `value` is in the set.
* *
@@ -120,14 +127,20 @@
return nativeString; return nativeString;
} }
/*--------------------------------------------------------------------------*/
Set.toString = toString; Set.toString = toString;
Set.prototype.add = add; Set.prototype.add = add;
Set.prototype.has = has; Set.prototype.has = has;
// expose `Set`
if (!root.Set) { if (!root.Set) {
root.Set = Set; context.Set = Set;
}
}
/*--------------------------------------------------------------------------*/
if (freeExports) {
freeExports.runInContext = runInContext;
} else {
runInContext(root);
} }
}.call(this)); }.call(this));

View File

@@ -12,6 +12,9 @@
/** Used as a reference to the global object */ /** Used as a reference to the global object */
var root = (objectTypes[typeof window] && window) || this; 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` */ /** Detect free variable `global` from Node.js or Browserified code and use it as `root` */
var freeGlobal = objectTypes[typeof global] && global; var freeGlobal = objectTypes[typeof global] && global;
if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) { 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. * Creates a `WeakMap` object.
*/ */
@@ -27,8 +38,6 @@
// no-op // no-op
} }
/*--------------------------------------------------------------------------*/
/** /**
* Gets the value associated with the given key. * Gets the value associated with the given key.
* *
@@ -63,14 +72,20 @@
return nativeString; return nativeString;
} }
/*--------------------------------------------------------------------------*/
WeakMap.toString = toString; WeakMap.toString = toString;
WeakMap.prototype.get = get; WeakMap.prototype.get = get;
WeakMap.prototype.set = set; WeakMap.prototype.set = set;
// expose `WeakMap`
if (!root.WeakMap) { if (!root.WeakMap) {
root.WeakMap = WeakMap; context.WeakMap = WeakMap;
}
}
/*--------------------------------------------------------------------------*/
if (freeExports) {
freeExports.runInContext = runInContext;
} else {
runInContext(root);
} }
}.call(this)); }.call(this));

View File

@@ -117,10 +117,6 @@
? require ? require
: (isJava && root.load) || noop; : (isJava && root.load) || noop;
/** Load ES6 Set and WeakMap shims */
load('./asset/set.js');
load('./asset/weakmap.js');
/** The unit testing framework */ /** The unit testing framework */
var QUnit = (function() { var QUnit = (function() {
return root.QUnit || ( return root.QUnit || (
@@ -132,11 +128,24 @@
); );
}()); }());
/** Load and install QUnit Extras */ /** Load and install QUnit Extras and ES6 Set/WeakMap shims */
var qe = load('../vendor/qunit-extras/qunit-extras.js'); (function() {
if (qe) { var paths = [
qe.runInContext(root); './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 Foo() {}
function message(lodashMethod, nativeMethod) { function message(lodashMethod, nativeMethod) {
@@ -647,13 +656,6 @@
ok(actual[0] instanceof Foo, message('_.create', 'Object.create')); ok(actual[0] instanceof Foo, message('_.create', 'Object.create'));
deepEqual(actual[1], {}, 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 { try {
actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])]; actual = [lodashBizarro.isPlainObject({}), lodashBizarro.isPlainObject([])];
} catch(e) { } catch(e) {
@@ -722,7 +724,7 @@
} }
} }
else { else {
skipTest(15); skipTest(14);
} }
}); });
}()); }());
@@ -2210,19 +2212,19 @@
var object = {}; var object = {};
if ((defineProperty && !WeakMap) && _.support.funcDecomp) { if (lodashBizarro && lodashBizarro.support.funcDecomp) {
_.callback(a, object); lodashBizarro.callback(a, object);
ok(EXPANDO in a); ok(EXPANDO in a);
_.callback(b, object); lodashBizarro.callback(b, object);
ok(!(EXPANDO in b)); ok(!(EXPANDO in b));
if (_.support.funcNames) { if (lodashBizarro.support.funcNames) {
_.support.funcNames = false; lodashBizarro.support.funcNames = false;
_.callback(c, object); lodashBizarro.callback(c, object);
ok(EXPANDO in c); ok(EXPANDO in c);
_.support.funcNames = true; lodashBizarro.support.funcNames = true;
} }
else { else {
skipTest(); skipTest();
@@ -2236,7 +2238,7 @@
test('should not write metadata when `_.support.funcDecomp` is `false`', 1, function() { test('should not write metadata when `_.support.funcDecomp` is `false`', 1, function() {
function a() {}; function a() {};
if ((defineProperty && !WeakMap) && lodashBizarro) { if (lodashBizarro) {
lodashBizarro.callback(a, {}); lodashBizarro.callback(a, {});
ok(!(EXPANDO in a)); ok(!(EXPANDO in a));
} }

View File

@@ -177,10 +177,6 @@
* @param {Object} context The context object. * @param {Object} context The context object.
*/ */
function runInContext(context) { 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 */ /** Used to report the test module for failing tests */
var moduleName, var moduleName,