mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-13 20:37:48 +00:00
Load QUnit extras for cli tests too.
This commit is contained in:
@@ -21,6 +21,15 @@
|
|||||||
''': "'"
|
''': "'"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Detect free variable `exports` */
|
||||||
|
var freeExports = typeof exports == 'object' && exports;
|
||||||
|
|
||||||
|
/** Detect free variable `global`, from Node.js or Browserified code, and use it as `root` */
|
||||||
|
var freeGlobal = typeof global == 'object' && global;
|
||||||
|
if (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal) {
|
||||||
|
root = freeGlobal;
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,6 +91,21 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Installs the QUnit additions on the given `context` object.
|
||||||
|
*
|
||||||
|
* @memberOf exports
|
||||||
|
* @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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Shorten `context.QUnit.QUnit` to `context.QUnit` */
|
||||||
|
var QUnit = context.QUnit = context.QUnit.QUnit || context.QUnit;
|
||||||
|
|
||||||
/** The number of retries async tests have to succeed */
|
/** The number of retries async tests have to succeed */
|
||||||
QUnit.config.asyncRetries = 0;
|
QUnit.config.asyncRetries = 0;
|
||||||
|
|
||||||
@@ -161,4 +185,14 @@
|
|||||||
finish.call(this);
|
finish.call(this);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// expose QUnit extras
|
||||||
|
if (freeExports && !freeExports.nodeType) {
|
||||||
|
freeExports.runInContext = runInContext;
|
||||||
|
} else {
|
||||||
|
runInContext(root);
|
||||||
|
}
|
||||||
}(this));
|
}(this));
|
||||||
|
|||||||
38
test/test.js
38
test/test.js
@@ -8,6 +8,7 @@
|
|||||||
body = document && document.body,
|
body = document && document.body,
|
||||||
create = Object.create,
|
create = Object.create,
|
||||||
freeze = Object.freeze,
|
freeze = Object.freeze,
|
||||||
|
noop = function() {},
|
||||||
params = root.arguments,
|
params = root.arguments,
|
||||||
process = root.process,
|
process = root.process,
|
||||||
push = Array.prototype.push,
|
push = Array.prototype.push,
|
||||||
@@ -59,18 +60,22 @@
|
|||||||
/** 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]);
|
||||||
|
|
||||||
|
/** Detect if running in Java */
|
||||||
|
var isJava = !document && !!root.java;
|
||||||
|
|
||||||
/** Detects if running in a PhantomJS web page */
|
/** Detects if running in a PhantomJS web page */
|
||||||
var isPhantomPage = typeof callPhantom == 'function';
|
var isPhantomPage = typeof callPhantom == 'function';
|
||||||
|
|
||||||
/** Detect if running in Rhino */
|
/** Detect if running in Rhino */
|
||||||
var isRhino = root.java && typeof global == 'function' && global().Array === root.Array;
|
var isRhino = isJava && typeof global == 'function' && global().Array === root.Array;
|
||||||
|
|
||||||
/** Use a single "load" function */
|
/** Use a single "load" function */
|
||||||
var load = !amd && typeof require == 'function' ? require : root.load;
|
var load = (typeof require == 'function' && !amd)
|
||||||
|
? require
|
||||||
|
: (isJava && root.load);
|
||||||
|
|
||||||
/** The unit testing framework */
|
/** The unit testing framework */
|
||||||
var QUnit = (function() {
|
var QUnit = (function() {
|
||||||
var noop = Function.prototype;
|
|
||||||
return root.QUnit || (
|
return root.QUnit || (
|
||||||
root.addEventListener || (root.addEventListener = noop),
|
root.addEventListener || (root.addEventListener = noop),
|
||||||
root.setTimeout || (root.setTimeout = noop),
|
root.setTimeout || (root.setTimeout = noop),
|
||||||
@@ -83,6 +88,10 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
// load QUnit extras
|
||||||
|
if (load) {
|
||||||
|
(load('./asset/qunit-extras.js') || { 'runInContext': noop }).runInContext(root);
|
||||||
|
}
|
||||||
// log params passed to `test.js`
|
// log params passed to `test.js`
|
||||||
if (params) {
|
if (params) {
|
||||||
console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
|
console.log('test.js invoked with arguments: ' + JSON.stringify(slice.call(params)));
|
||||||
@@ -586,10 +595,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('ensure `new bound` is an instance of `func`', 1, function() {
|
test('ensure `new bound` is an instance of `func`', 1, function() {
|
||||||
var func = function() {},
|
var bound = _.bind(noop, {});
|
||||||
bound = _.bind(func, {});
|
|
||||||
|
|
||||||
ok(new bound instanceof func);
|
ok(new bound instanceof noop);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should append array arguments to partially applied arguments (test in IE < 9)', 1, function() {
|
test('should append array arguments to partially applied arguments (test in IE < 9)', 1, function() {
|
||||||
@@ -2660,7 +2668,7 @@
|
|||||||
this.b = 'b'
|
this.b = 'b'
|
||||||
}
|
}
|
||||||
|
|
||||||
Foo.prototype.c = function() {};
|
Foo.prototype.c = noop;
|
||||||
deepEqual(_.functions(new Foo), ['a', 'c']);
|
deepEqual(_.functions(new Foo), ['a', 'c']);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -3144,7 +3152,7 @@
|
|||||||
strictEqual(_.isArguments(true), false);
|
strictEqual(_.isArguments(true), false);
|
||||||
strictEqual(_.isArguments(new Date), false);
|
strictEqual(_.isArguments(new Date), false);
|
||||||
strictEqual(_.isArguments(_), false);
|
strictEqual(_.isArguments(_), false);
|
||||||
strictEqual(_.isArguments({ '0': 1, 'callee': _.noop, 'length': 1 }), false);
|
strictEqual(_.isArguments({ '0': 1, 'callee': noop, 'length': 1 }), false);
|
||||||
strictEqual(_.isArguments(0), false);
|
strictEqual(_.isArguments(0), false);
|
||||||
strictEqual(_.isArguments(/x/), false);
|
strictEqual(_.isArguments(/x/), false);
|
||||||
strictEqual(_.isArguments('a'), false);
|
strictEqual(_.isArguments('a'), false);
|
||||||
@@ -3540,7 +3548,7 @@
|
|||||||
'f': ['a', new String('b'), 'c'],
|
'f': ['a', new String('b'), 'c'],
|
||||||
'g': new Boolean(false),
|
'g': new Boolean(false),
|
||||||
'h': new Date(2012, 4, 23),
|
'h': new Date(2012, 4, 23),
|
||||||
'i': _.noop,
|
'i': noop,
|
||||||
'j': 'a'
|
'j': 'a'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -3554,7 +3562,7 @@
|
|||||||
'f': ['a', 'b', 'c'],
|
'f': ['a', 'b', 'c'],
|
||||||
'g': false,
|
'g': false,
|
||||||
'h': new Date(2012, 4, 23),
|
'h': new Date(2012, 4, 23),
|
||||||
'i': _.noop,
|
'i': noop,
|
||||||
'j': 'a'
|
'j': 'a'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -5837,7 +5845,7 @@
|
|||||||
|
|
||||||
_.forEach(empties, function(value) {
|
_.forEach(empties, function(value) {
|
||||||
try {
|
try {
|
||||||
actual.push(func(value, _.noop));
|
actual.push(func(value, noop));
|
||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -5849,7 +5857,7 @@
|
|||||||
|
|
||||||
var actual = _.map(empties, function(value) {
|
var actual = _.map(empties, function(value) {
|
||||||
try {
|
try {
|
||||||
return func(value, _.noop, 'x');
|
return func(value, noop, 'x');
|
||||||
} catch(e) { }
|
} catch(e) { }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -5857,7 +5865,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('`_.' + methodName + '` should handle an initial `accumulator` value of `undefined`', 1, function() {
|
test('`_.' + methodName + '` should handle an initial `accumulator` value of `undefined`', 1, function() {
|
||||||
var actual = func([], _.noop, undefined);
|
var actual = func([], noop, undefined);
|
||||||
strictEqual(actual, undefined);
|
strictEqual(actual, undefined);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -7605,12 +7613,12 @@
|
|||||||
test('should pass the correct `wrapper` arguments', 1, function() {
|
test('should pass the correct `wrapper` arguments', 1, function() {
|
||||||
var args;
|
var args;
|
||||||
|
|
||||||
var wrapped = _.wrap(_.noop, function() {
|
var wrapped = _.wrap(noop, function() {
|
||||||
args || (args = slice.call(arguments));
|
args || (args = slice.call(arguments));
|
||||||
});
|
});
|
||||||
|
|
||||||
wrapped(1, 2, 3);
|
wrapped(1, 2, 3);
|
||||||
deepEqual(args, [_.noop, 1, 2, 3]);
|
deepEqual(args, [noop, 1, 2, 3]);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not set a `this` binding', 1, function() {
|
test('should not set a `this` binding', 1, function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user