mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 19:07:49 +00:00
Update vendor/qunit-clib and tests to work with Ringo 0.9 and PhantomJS.
Former-commit-id: e6906e4b9f6afdee598902d6939356bf33302909
This commit is contained in:
43
perf/perf.js
43
perf/perf.js
@@ -1,8 +1,28 @@
|
|||||||
(function(window) {
|
(function(window) {
|
||||||
|
|
||||||
/** Use a single load function */
|
/** Use a single "load" function */
|
||||||
var load = typeof require == 'function' ? require : window.load;
|
var load = typeof require == 'function' ? require : window.load;
|
||||||
|
|
||||||
|
/** The file path of the Lo-Dash file to test */
|
||||||
|
var filePath = (function() {
|
||||||
|
var min = 0;
|
||||||
|
var result = window.phantom
|
||||||
|
? phantom.args
|
||||||
|
: (window.system
|
||||||
|
? (min = 1, system.args)
|
||||||
|
: (window.process ? (min = 2, process.argv) : (window.arguments || []))
|
||||||
|
);
|
||||||
|
|
||||||
|
var last = result[result.length - 1];
|
||||||
|
result = (result.length > min && last != 'test.js') ? last : '../lodash.js';
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = require('fs').realpathSync(result);
|
||||||
|
} catch(e) { }
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}());
|
||||||
|
|
||||||
/** Load Benchmark.js */
|
/** Load Benchmark.js */
|
||||||
var Benchmark =
|
var Benchmark =
|
||||||
window.Benchmark || (
|
window.Benchmark || (
|
||||||
@@ -13,7 +33,7 @@
|
|||||||
/** Load Lo-Dash */
|
/** Load Lo-Dash */
|
||||||
var lodash =
|
var lodash =
|
||||||
window.lodash || (
|
window.lodash || (
|
||||||
lodash = load('../dist/lodash.js') || window._,
|
lodash = load(filePath) || window._,
|
||||||
lodash = lodash._ || lodash,
|
lodash = lodash._ || lodash,
|
||||||
lodash.noConflict()
|
lodash.noConflict()
|
||||||
);
|
);
|
||||||
@@ -35,22 +55,27 @@
|
|||||||
var suites = [];
|
var suites = [];
|
||||||
|
|
||||||
/** The `ui` object */
|
/** The `ui` object */
|
||||||
var ui = window.ui || {};
|
var ui = window.ui || {
|
||||||
|
'buildPath': basename(filePath, '.js'),
|
||||||
|
'otherPath': 'underscore'
|
||||||
|
};
|
||||||
|
|
||||||
/** The Lo-Dash build basename */
|
/** The Lo-Dash build basename */
|
||||||
var buildName = basename(ui.buildPath || 'lodash', '.js');
|
var buildName = basename(ui.buildPath, '.js');
|
||||||
|
|
||||||
/** The other library basename */
|
/** The other library basename */
|
||||||
var otherName = basename(ui.otherPath || 'underscore', '.js');
|
var otherName = basename(ui.otherPath, '.js');
|
||||||
|
|
||||||
/** Add `console.log()` support for Narwhal and RingoJS */
|
|
||||||
window.console || (window.console = { 'log': window.print });
|
|
||||||
|
|
||||||
/** Expose functions to the global object */
|
/** Expose functions to the global object */
|
||||||
window._ = _;
|
window._ = _;
|
||||||
window.Benchmark = Benchmark;
|
window.Benchmark = Benchmark;
|
||||||
window.lodash = lodash;
|
window.lodash = lodash;
|
||||||
|
|
||||||
|
/** Add `console.log()` support for Narwhal and RingoJS */
|
||||||
|
if (!window.console && window.print) {
|
||||||
|
window.console = { 'log': window.print };
|
||||||
|
}
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1691,7 +1716,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// in the browser, expose `run` to be called later
|
// in the browser, expose `run` to be called later
|
||||||
if (window.document) {
|
if (window.document && !window.phantom) {
|
||||||
window.run = run;
|
window.run = run;
|
||||||
} else {
|
} else {
|
||||||
run();
|
run();
|
||||||
|
|||||||
@@ -1,9 +1,14 @@
|
|||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
for cmd in node narwhal ringo rhino; do
|
|
||||||
echo ""
|
echo "Running performance suite in node..."
|
||||||
echo "Running performance suite in $cmd..."
|
node perf.js ../dist/lodash.js && node perf.js ../dist/lodash.min.js
|
||||||
$cmd perf.js
|
|
||||||
|
for cmd in rhino narwhal ringo phantomjs; do
|
||||||
|
echo ""
|
||||||
|
echo "Running performance suite in $cmd..."
|
||||||
|
$cmd perf.js ../dist/lodash.compat.js && $cmd perf.js ../dist/lodash.compat.min.js
|
||||||
done
|
done
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "Running performance suite in a browser..."
|
echo "Running performance suite in a browser..."
|
||||||
open index.html
|
open index.html
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
cd "$(dirname "$0")"
|
cd "$(dirname "$0")"
|
||||||
for cmd in rhino ringo narwhal; do
|
|
||||||
echo ""
|
for cmd in rhino narwhal ringo phantomjs; do
|
||||||
echo "Testing in $cmd..."
|
echo "Testing in $cmd..."
|
||||||
$cmd test.js ../dist/lodash.compat.js && $cmd test.js ../dist/lodash.compat.min.js
|
$cmd test.js ../dist/lodash.compat.js && $cmd test.js ../dist/lodash.compat.min.js
|
||||||
|
echo ""
|
||||||
done
|
done
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "Testing in node..."
|
echo "Testing in node..."
|
||||||
node test.js ../dist/lodash.js && node test.js ../dist/lodash.min.js
|
node test.js ../dist/lodash.js && node test.js ../dist/lodash.min.js
|
||||||
|
|
||||||
|
echo ""
|
||||||
echo "Testing build..."
|
echo "Testing build..."
|
||||||
node test-build.js
|
node test-build.js
|
||||||
|
|
||||||
|
|||||||
43
test/test.js
43
test/test.js
@@ -1,19 +1,21 @@
|
|||||||
;(function(window, undefined) {
|
;(function(window, undefined) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/** Use a single load function */
|
/** Use a single "load" function */
|
||||||
var load = typeof require == 'function' ? require : window.load;
|
var load = typeof require == 'function' ? require : window.load;
|
||||||
|
|
||||||
/** The file path of the Lo-Dash file to test */
|
/** The file path of the Lo-Dash file to test */
|
||||||
var filePath = (function() {
|
var filePath = (function() {
|
||||||
var min = 0;
|
var min = 0;
|
||||||
var result = window.system
|
var result = window.phantom
|
||||||
? (min = 1, system.args)
|
? phantom.args
|
||||||
: (window.process ? (min = 2, process.argv) : (window.arguments || []));
|
: (window.system
|
||||||
|
? (min = 1, system.args)
|
||||||
|
: (window.process ? (min = 2, process.argv) : (window.arguments || []))
|
||||||
|
);
|
||||||
|
|
||||||
result = result.length > min
|
var last = result[result.length - 1];
|
||||||
? result[result.length - 1]
|
result = (result.length > min && last != 'test.js') ? last : '../lodash.js';
|
||||||
: '../lodash.js';
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
result = require('fs').realpathSync(result);
|
result = require('fs').realpathSync(result);
|
||||||
@@ -35,7 +37,7 @@
|
|||||||
var QUnit =
|
var QUnit =
|
||||||
window.QUnit || (
|
window.QUnit || (
|
||||||
window.addEventListener || (window.addEventListener = Function.prototype),
|
window.addEventListener || (window.addEventListener = Function.prototype),
|
||||||
window.setTimeout || (window.setTimeout = / /),
|
window.setTimeout || (window.setTimeout = Function.prototype),
|
||||||
window.QUnit = load('../vendor/qunit/qunit/qunit.js') || window.QUnit,
|
window.QUnit = load('../vendor/qunit/qunit/qunit.js') || window.QUnit,
|
||||||
load('../vendor/qunit-clib/qunit-clib.js'),
|
load('../vendor/qunit-clib/qunit-clib.js'),
|
||||||
window.addEventListener === Function.prototype && delete window.addEventListener,
|
window.addEventListener === Function.prototype && delete window.addEventListener,
|
||||||
@@ -114,7 +116,7 @@
|
|||||||
|
|
||||||
// add object from iframe
|
// add object from iframe
|
||||||
(function() {
|
(function() {
|
||||||
if (!window.document) {
|
if (!window.document || window.phantom) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var body = document.body,
|
var body = document.body,
|
||||||
@@ -135,7 +137,7 @@
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
test('supports loading ' + basename + ' as the "lodash" module', function() {
|
test('supports loading ' + basename + ' as the "lodash" module', function() {
|
||||||
if (window.document && window.require) {
|
if (window.document && window.define && define.amd) {
|
||||||
equal((lodashModule || {}).moduleName, 'lodash');
|
equal((lodashModule || {}).moduleName, 'lodash');
|
||||||
} else {
|
} else {
|
||||||
skipTest();
|
skipTest();
|
||||||
@@ -143,7 +145,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('supports loading ' + basename + ' with the Require.js "shim" configuration option', function() {
|
test('supports loading ' + basename + ' with the Require.js "shim" configuration option', function() {
|
||||||
if (window.document && window.require) {
|
if (window.document && window.define && define.amd) {
|
||||||
equal((shimmedModule || {}).moduleName, 'shimmed');
|
equal((shimmedModule || {}).moduleName, 'shimmed');
|
||||||
} else {
|
} else {
|
||||||
skipTest();
|
skipTest();
|
||||||
@@ -151,7 +153,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('supports loading ' + basename + ' as the "underscore" module', function() {
|
test('supports loading ' + basename + ' as the "underscore" module', function() {
|
||||||
if (window.document && window.require) {
|
if (window.document && window.define && define.amd) {
|
||||||
equal((underscoreModule || {}).moduleName, 'underscore');
|
equal((underscoreModule || {}).moduleName, 'underscore');
|
||||||
} else {
|
} else {
|
||||||
skipTest();
|
skipTest();
|
||||||
@@ -159,7 +161,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('avoids overwritten native methods', function() {
|
test('avoids overwritten native methods', function() {
|
||||||
if (window.document) {
|
if (window.document && !window.phantom) {
|
||||||
notDeepEqual(lodashBadShim.keys({ 'a': 1 }), []);
|
notDeepEqual(lodashBadShim.keys({ 'a': 1 }), []);
|
||||||
} else {
|
} else {
|
||||||
skipTest();
|
skipTest();
|
||||||
@@ -2653,6 +2655,9 @@
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
test('should allow falsey arguments', function() {
|
test('should allow falsey arguments', function() {
|
||||||
|
var isExported = '_' in window,
|
||||||
|
oldDash = window._;
|
||||||
|
|
||||||
var returnArrays = [
|
var returnArrays = [
|
||||||
'filter',
|
'filter',
|
||||||
'invoke',
|
'invoke',
|
||||||
@@ -2699,6 +2704,13 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (methodName == 'noConflict') {
|
||||||
|
if (isExported) {
|
||||||
|
window._ = oldDash;
|
||||||
|
} else {
|
||||||
|
delete window._;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (_.indexOf(returnArrays, methodName) > -1) {
|
if (_.indexOf(returnArrays, methodName) > -1) {
|
||||||
deepEqual(actual, expected, '_.' + methodName + ' returns an array');
|
deepEqual(actual, expected, '_.' + methodName + ' returns an array');
|
||||||
}
|
}
|
||||||
@@ -2763,8 +2775,9 @@
|
|||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
// explicitly call `QUnit.start()` for Narwhal, Node.js, Rhino, and RingoJS
|
// configure QUnit and call `QUnit.start()` for Narwhal, Node.js, PhantomJS, Rhino, and RingoJS
|
||||||
if (!window.document) {
|
if (!window.document || window.phantom) {
|
||||||
|
QUnit.config.noglobals = true;
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
}
|
}
|
||||||
}(typeof global == 'object' && global || this));
|
}(typeof global == 'object' && global || this));
|
||||||
|
|||||||
2
vendor/qunit-clib/LICENSE.txt
vendored
2
vendor/qunit-clib/LICENSE.txt
vendored
@@ -1,4 +1,4 @@
|
|||||||
Copyright 2011-2012 John-David Dalton <http://allyoucanleet.com/>
|
Copyright 2011-2013 John-David Dalton <http://allyoucanleet.com/>
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|||||||
13
vendor/qunit-clib/README.md
vendored
13
vendor/qunit-clib/README.md
vendored
@@ -1,4 +1,4 @@
|
|||||||
# QUnit CLIB <sup>v1.0.0</sup>
|
# QUnit CLIB <sup>v1.2.0</sup>
|
||||||
## command-line interface boilerplate
|
## command-line interface boilerplate
|
||||||
|
|
||||||
QUnit CLIB helps extend QUnit's CLI support to many common CLI environments.
|
QUnit CLIB helps extend QUnit's CLI support to many common CLI environments.
|
||||||
@@ -9,23 +9,24 @@ QUnit CLIB helps extend QUnit's CLI support to many common CLI environments.
|
|||||||
|
|
||||||
## Support
|
## Support
|
||||||
|
|
||||||
QUnit CLIB has been tested in at least Node.js 0.4.8-0.8.6, Narwhal v0.3.2, RingoJS v0.8.0, and Rhino v1.7RC3-RC5.
|
QUnit CLIB has been tested in at least Node.js 0.4.8-0.8.19, Narwhal v0.3.2, PhantomJS 1.8.1, RingoJS v0.9, and Rhino v1.7RC5.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```js
|
```js
|
||||||
(function(window) {
|
(function(window) {
|
||||||
|
|
||||||
// use a single load function
|
// use a single "load" function
|
||||||
var load = typeof require == 'function' ? require : window.load;
|
var load = typeof require == 'function' ? require : window.load;
|
||||||
|
|
||||||
// load QUnit and CLIB if needed
|
// load QUnit and CLIB if needed
|
||||||
var QUnit =
|
var QUnit =
|
||||||
window.QUnit || (
|
window.QUnit || (
|
||||||
window.setTimeout || (window.addEventListener = window.setTimeout = / /),
|
window.addEventListener || (window.addEventListener = Function.prototype),
|
||||||
|
window.setTimeout || (window.setTimeout = Function.prototype),
|
||||||
window.QUnit = load('path/to/qunit.js') || window.QUnit,
|
window.QUnit = load('path/to/qunit.js') || window.QUnit,
|
||||||
load('path/to/qunit-clib.js'),
|
load('path/to/qunit-clib.js'),
|
||||||
(window.addEventListener || 0).test && delete window.addEventListener,
|
window.addEventListener === Function.prototype && delete window.addEventListener,
|
||||||
window.QUnit
|
window.QUnit
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -38,7 +39,7 @@ QUnit CLIB has been tested in at least Node.js 0.4.8-0.8.6, Narwhal v0.3.2, Ring
|
|||||||
});
|
});
|
||||||
|
|
||||||
// must call `QUnit.start()` if using QUnit < 1.3.0 with Node.js or any
|
// must call `QUnit.start()` if using QUnit < 1.3.0 with Node.js or any
|
||||||
// version of QUnit with Narwhal, Rhino, or RingoJS
|
// version of QUnit with Narwhal, PhantomJS, Rhino, or RingoJS
|
||||||
if (!window.document) {
|
if (!window.document) {
|
||||||
QUnit.start();
|
QUnit.start();
|
||||||
}
|
}
|
||||||
|
|||||||
513
vendor/qunit-clib/qunit-clib.js
vendored
513
vendor/qunit-clib/qunit-clib.js
vendored
@@ -1,324 +1,269 @@
|
|||||||
/*!
|
/*!
|
||||||
* QUnit CLI Boilerplate v1.0.0
|
* QUnit CLI Boilerplate v1.2.0
|
||||||
* Copyright 2011-2012 John-David Dalton <http://allyoucanleet.com/>
|
* Copyright 2011-2012 John-David Dalton <http://allyoucanleet.com/>
|
||||||
* Based on a gist by Jörn Zaefferer <https://gist.github.com/722381>
|
* Based on a gist by Jörn Zaefferer <https://gist.github.com/722381>
|
||||||
* Available under MIT license <http://mths.be/mit>
|
* Available under MIT license <http://mths.be/mit>
|
||||||
*/
|
*/
|
||||||
;(function(global) {
|
;(function(window) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/** Add `console.log()` support for Narwhal, Rhino, and RingoJS */
|
|
||||||
global.console || (global.console = { 'log': global.print });
|
|
||||||
|
|
||||||
/** Reduce global.QUnit.QUnit -> global.QUnit */
|
|
||||||
global.QUnit && (QUnit = QUnit.QUnit || QUnit);
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/** Used as a horizontal rule in console output */
|
|
||||||
var hr = '----------------------------------------';
|
|
||||||
|
|
||||||
/** Shortcut used to convert array-like objects to arrays */
|
|
||||||
var slice = [].slice;
|
|
||||||
|
|
||||||
/** Used to resolve a value's internal [[Class]] */
|
|
||||||
var toString = {}.toString;
|
|
||||||
|
|
||||||
/** Used by timer methods */
|
|
||||||
var doneCalled,
|
|
||||||
timer,
|
|
||||||
counter = 0,
|
|
||||||
ids = {};
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An iteration utility for arrays.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Array} array The array to iterate over.
|
|
||||||
* @param {Function} callback The function called per iteration.
|
|
||||||
*/
|
|
||||||
function each(array, callback) {
|
|
||||||
var index = -1,
|
|
||||||
length = array.length;
|
|
||||||
|
|
||||||
while (++index < length) {
|
|
||||||
callback(array[index], index, array);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if the specified `value` is a function.
|
|
||||||
*
|
|
||||||
* @private
|
|
||||||
* @param {Mixed} value The value to check.
|
|
||||||
* @returns {Boolean} Returns `true` if `value` is a function, else `false`.
|
|
||||||
*/
|
|
||||||
function isFunction(value) {
|
|
||||||
return toString.call(value) == '[object Function]';
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timeout fallbacks based on the work of Andrea Giammarchi and Weston C.
|
* Timeout fallbacks based on the work of Andrea Giammarchi and Weston C.
|
||||||
* https://github.com/WebReflection/wru/blob/master/src/rhinoTimers.js
|
* https://github.com/WebReflection/wru/blob/master/src/rhinoTimers.js
|
||||||
* http://stackoverflow.com/questions/2261705/how-to-run-a-javascript-function-asynchronously-without-using-settimeout
|
* http://stackoverflow.com/questions/2261705/how-to-run-a-javascript-function-asynchronously-without-using-settimeout
|
||||||
*/
|
*/
|
||||||
|
(function() {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the delay set by `setInterval` or `setTimeout`.
|
* Schedules timer-based callbacks.
|
||||||
*
|
*
|
||||||
* @memberOf global
|
* @private
|
||||||
* @param {Number} id The ID of the timeout to be cleared.
|
* @param {Function|String} fn The function to call.
|
||||||
*/
|
* @oaram {Number} delay The number of milliseconds to delay the `fn` call.
|
||||||
function clearTimer(id) {
|
* @param [arg1, arg2, ...] Arguments to invoke `fn` with.
|
||||||
if (ids[id]) {
|
* @param {Boolean} repeated A flag to specify whether `fn` is called repeatedly.
|
||||||
ids[id].cancel();
|
* @returns {Number} The the ID of the timeout.
|
||||||
timer.purge();
|
*/
|
||||||
delete ids[id];
|
function schedule(fn, delay, args, repeated) {
|
||||||
}
|
// Rhino 1.7RC4 will error assigning `task` below
|
||||||
}
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=775566
|
||||||
|
var task = ids[++counter] = new JavaAdapter(java.util.TimerTask, {
|
||||||
/**
|
'run': function() {
|
||||||
* Schedules timer-based callbacks.
|
fn.apply(window, args);
|
||||||
*
|
}
|
||||||
* @private
|
});
|
||||||
* @param {Function} fn The function to call.
|
// support non-functions
|
||||||
* @oaram {Number} delay The number of milliseconds to delay the `fn` call.
|
if (typeof fn != 'function') {
|
||||||
* @param [arg1, arg2, ...] Arguments to invoke `fn` with.
|
fn = (function(code) {
|
||||||
* @param {Boolean} repeated A flag to specify whether `fn` is called repeatedly.
|
code = String(code);
|
||||||
* @returns {Number} The the ID of the timeout.
|
return function() { eval(code); };
|
||||||
*/
|
}(fn));
|
||||||
function schedule(fn, delay, args, repeated) {
|
|
||||||
// Rhino 1.7RC4 will error assigning `task` below
|
|
||||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=775566
|
|
||||||
var task = ids[++counter] = new JavaAdapter(java.util.TimerTask, {
|
|
||||||
'run': function() {
|
|
||||||
fn.apply(global, args);
|
|
||||||
}
|
}
|
||||||
});
|
// used by setInterval
|
||||||
// support non-functions
|
if (repeated) {
|
||||||
if (!isFunction(fn)) {
|
timer.schedule(task, delay, delay);
|
||||||
fn = (function(code) {
|
}
|
||||||
code = String(code);
|
// used by setTimeout
|
||||||
return function() { eval(code); };
|
else {
|
||||||
}(fn));
|
timer.schedule(task, delay);
|
||||||
|
}
|
||||||
|
return counter;
|
||||||
}
|
}
|
||||||
// used by setInterval
|
|
||||||
if (repeated) {
|
|
||||||
timer.schedule(task, delay, delay);
|
|
||||||
}
|
|
||||||
// used by setTimeout
|
|
||||||
else {
|
|
||||||
timer.schedule(task, delay);
|
|
||||||
}
|
|
||||||
return counter;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a code snippet or function repeatedly, with a delay between each call.
|
* Clears the delay set by `setInterval` or `setTimeout`.
|
||||||
*
|
*
|
||||||
* @memberOf global
|
* @memberOf window
|
||||||
* @param {Function|String} fn The function to call or string to evaluate.
|
* @param {Number} id The ID of the timeout to be cleared.
|
||||||
* @oaram {Number} delay The number of milliseconds to delay each `fn` call.
|
*/
|
||||||
* @param [arg1, arg2, ...] Arguments to invoke `fn` with.
|
function clearTimer(id) {
|
||||||
* @returns {Number} The the ID of the timeout.
|
if (ids[id]) {
|
||||||
*/
|
ids[id].cancel();
|
||||||
function setInterval(fn, delay) {
|
timer.purge();
|
||||||
return schedule(fn, delay, slice.call(arguments, 2), true);
|
delete ids[id];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes a code snippet or a function after specified delay.
|
* Executes a code snippet or function repeatedly, with a delay between each call.
|
||||||
*
|
*
|
||||||
* @memberOf global
|
* @memberOf window
|
||||||
* @param {Function|String} fn The function to call or string to evaluate.
|
* @param {Function|String} fn The function to call or string to evaluate.
|
||||||
* @oaram {Number} delay The number of milliseconds to delay the `fn` call.
|
* @oaram {Number} delay The number of milliseconds to delay each `fn` call.
|
||||||
* @param [arg1, arg2, ...] Arguments to invoke `fn` with.
|
* @param [arg1, arg2, ...] Arguments to invoke `fn` with.
|
||||||
* @returns {Number} The the ID of the timeout.
|
* @returns {Number} The the ID of the timeout.
|
||||||
*/
|
*/
|
||||||
function setTimeout(fn, delay) {
|
function setInterval(fn, delay) {
|
||||||
return schedule(fn, delay, slice.call(arguments, 2));
|
return schedule(fn, delay, slice.call(arguments, 2), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a code snippet or a function after specified delay.
|
||||||
|
*
|
||||||
|
* @memberOf window
|
||||||
|
* @param {Function|String} fn The function to call or string to evaluate.
|
||||||
|
* @oaram {Number} delay The number of milliseconds to delay the `fn` call.
|
||||||
|
* @param [arg1, arg2, ...] Arguments to invoke `fn` with.
|
||||||
|
* @returns {Number} The the ID of the timeout.
|
||||||
|
*/
|
||||||
|
function setTimeout(fn, delay) {
|
||||||
|
return schedule(fn, delay, slice.call(arguments, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
var counter = 0,
|
||||||
|
ids = {},
|
||||||
|
slice = Array.prototype.slice,
|
||||||
|
timer = new java.util.Timer;
|
||||||
|
|
||||||
|
window.clearInterval =
|
||||||
|
window.clearTimeout = clearTimer;
|
||||||
|
window.setInterval = setInterval;
|
||||||
|
window.setTimeout = setTimeout;
|
||||||
|
} catch(e) { }
|
||||||
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
(function() {
|
||||||
* A logging callback triggered when all testing is completed.
|
|
||||||
*
|
|
||||||
* @memberOf QUnit
|
|
||||||
* @param {Object} details An object with properties `failed`, `passed`,
|
|
||||||
* `runtime`, and `total`.
|
|
||||||
*/
|
|
||||||
function done(details) {
|
|
||||||
// stop `asyncTest()` from erroneously calling `done()` twice in
|
|
||||||
// environments w/o timeouts
|
|
||||||
if (doneCalled) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
doneCalled = true;
|
|
||||||
console.log(hr);
|
|
||||||
console.log(' PASS: ' + details.passed + ' FAIL: ' + details.failed + ' TOTAL: ' + details.total);
|
|
||||||
console.log(' Finished in ' + details.runtime + ' milliseconds.');
|
|
||||||
console.log(hr);
|
|
||||||
|
|
||||||
// exit out of Rhino
|
/** Used as a horizontal rule in console output */
|
||||||
try {
|
var hr = '----------------------------------------';
|
||||||
quit();
|
|
||||||
} catch(e) { }
|
|
||||||
|
|
||||||
// exit out of Node.js
|
/** Shorten `window.QUnit.QUnit` to `window.QUnit` */
|
||||||
try {
|
window.QUnit && (QUnit = QUnit.QUnit || QUnit);
|
||||||
if (details.failed) {
|
|
||||||
console.error('Error: ' + details.failed + ' of ' + details.total + ' tests failed.');
|
/**
|
||||||
process.exit(1);
|
* A logging callback triggered when all testing is completed.
|
||||||
} else {
|
*
|
||||||
process.exit(0);
|
* @memberOf QUnit
|
||||||
|
* @param {Object} details An object with properties `failed`, `passed`, `runtime`, and `total`.
|
||||||
|
*/
|
||||||
|
QUnit.done(function() {
|
||||||
|
var ran;
|
||||||
|
return function(details) {
|
||||||
|
// stop `asyncTest()` from erroneously calling `done()` twice in
|
||||||
|
// environments w/o timeouts
|
||||||
|
if (ran) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ran = true;
|
||||||
|
|
||||||
|
console.log(hr);
|
||||||
|
console.log(' PASS: ' + details.passed + ' FAIL: ' + details.failed + ' TOTAL: ' + details.total);
|
||||||
|
console.log(' Finished in ' + details.runtime + ' milliseconds.');
|
||||||
|
console.log(hr);
|
||||||
|
|
||||||
|
// exit out of Rhino
|
||||||
|
try {
|
||||||
|
quit();
|
||||||
|
} catch(e) { }
|
||||||
|
|
||||||
|
// exit out of Node.js or PhantomJS
|
||||||
|
try {
|
||||||
|
var process = window.process || window.phantom;
|
||||||
|
if (details.failed) {
|
||||||
|
console.error('Error: ' + details.failed + ' of ' + details.total + ' tests failed.');
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
process.exit(0);
|
||||||
|
}
|
||||||
|
} catch(e) { }
|
||||||
|
};
|
||||||
|
}());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A logging callback triggered after every assertion.
|
||||||
|
*
|
||||||
|
* @memberOf QUnit
|
||||||
|
* @param {Object} details An object with properties `actual`, `expected`, `message`, and `result`.
|
||||||
|
*/
|
||||||
|
QUnit.log(function(details) {
|
||||||
|
var expected = details.expected,
|
||||||
|
result = details.result,
|
||||||
|
type = typeof expected != 'undefined' ? 'EQ' : 'OK';
|
||||||
|
|
||||||
|
var assertion = [
|
||||||
|
result ? 'PASS' : 'FAIL',
|
||||||
|
type,
|
||||||
|
details.message || 'ok'
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!result && type == 'EQ') {
|
||||||
|
assertion.push('Expected: ' + expected + ', Actual: ' + details.actual);
|
||||||
}
|
}
|
||||||
} catch(e) { }
|
QUnit.config.testStats.assertions.push(assertion.join(' | '));
|
||||||
}
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A logging callback triggered after every assertion.
|
* A logging callback triggered at the start of every test module.
|
||||||
*
|
*
|
||||||
* @memberOf QUnit
|
* @memberOf QUnit
|
||||||
* @param {Object} details An object with properties `actual`, `expected`,
|
* @param {Object} details An object with property `name`.
|
||||||
* `message`, and `result`.
|
*/
|
||||||
*/
|
QUnit.moduleStart(function(details) {
|
||||||
function log(details) {
|
console.log(hr);
|
||||||
var expected = details.expected,
|
console.log(details.name);
|
||||||
result = details.result,
|
console.log(hr);
|
||||||
type = typeof expected != 'undefined' ? 'EQ' : 'OK';
|
});
|
||||||
|
|
||||||
var assertion = [
|
/**
|
||||||
result ? 'PASS' : 'FAIL',
|
* Converts an object into a string representation.
|
||||||
type,
|
*
|
||||||
details.message || 'ok'
|
* @memberOf QUnit
|
||||||
];
|
* @type Function
|
||||||
|
* @param {Object} object The object to stringify.
|
||||||
|
* @returns {String} The result string.
|
||||||
|
*/
|
||||||
|
QUnit.jsDump.parsers.object = (function() {
|
||||||
|
var func = QUnit.jsDump.parsers.object;
|
||||||
|
return function(object) {
|
||||||
|
// fork to support Rhino's error objects
|
||||||
|
if (typeof object.rhinoException == 'object') {
|
||||||
|
return object.name +
|
||||||
|
' { message: "' + object.message +
|
||||||
|
'", fileName: "' + object.fileName +
|
||||||
|
'", lineNumber: ' + object.lineNumber + ' }';
|
||||||
|
}
|
||||||
|
return func(object);
|
||||||
|
};
|
||||||
|
}());
|
||||||
|
|
||||||
if (!result && type == 'EQ') {
|
/**
|
||||||
assertion.push('Expected: ' + expected + ', Actual: ' + details.actual);
|
* A logging callback triggered after a test is completed.
|
||||||
}
|
*
|
||||||
QUnit.config.testStats.assertions.push(assertion.join(' | '));
|
* @memberOf QUnit
|
||||||
}
|
* @param {Object} details An object with properties `failed`, `name`, `passed`, and `total`.
|
||||||
|
*/
|
||||||
|
QUnit.testDone(function(details) {
|
||||||
|
var assertions = QUnit.config.testStats.assertions,
|
||||||
|
testName = details.name;
|
||||||
|
|
||||||
/**
|
if (details.failed > 0) {
|
||||||
* A logging callback triggered at the start of every test module.
|
console.log(' FAIL - '+ testName);
|
||||||
*
|
assertions.forEach(function(value) {
|
||||||
* @memberOf QUnit
|
console.log(' ' + value);
|
||||||
* @param {Object} details An object with property `name`.
|
});
|
||||||
*/
|
|
||||||
function moduleStart(details) {
|
|
||||||
console.log(hr);
|
|
||||||
console.log(details.name);
|
|
||||||
console.log(hr);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts an object into a string representation.
|
|
||||||
*
|
|
||||||
* @memberOf QUnit
|
|
||||||
* @type Function
|
|
||||||
* @param {Object} object The object to stringify.
|
|
||||||
* @returns {String} The result string.
|
|
||||||
*/
|
|
||||||
var parseObject = (function() {
|
|
||||||
var func = QUnit.jsDump.parsers.object;
|
|
||||||
return function(object) {
|
|
||||||
// fork to support Rhino's error objects
|
|
||||||
if (typeof object.rhinoException == 'object') {
|
|
||||||
return object.name +
|
|
||||||
' { message: "' + object.message +
|
|
||||||
'", fileName: "' + object.fileName +
|
|
||||||
'", lineNumber: ' + object.lineNumber + ' }';
|
|
||||||
}
|
}
|
||||||
return func(object);
|
else {
|
||||||
|
console.log(' PASS - ' + testName);
|
||||||
|
}
|
||||||
|
assertions.length = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An object used to hold information about the current running test.
|
||||||
|
*
|
||||||
|
* @memberOf QUnit.config
|
||||||
|
* @type Object
|
||||||
|
*/
|
||||||
|
QUnit.config.testStats = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An array of test summaries (pipe separated).
|
||||||
|
*
|
||||||
|
* @memberOf QUnit.config.testStats
|
||||||
|
* @type Array
|
||||||
|
*/
|
||||||
|
'assertions': []
|
||||||
};
|
};
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/**
|
|
||||||
* A logging callback triggered after a test is completed.
|
|
||||||
*
|
|
||||||
* @memberOf QUnit
|
|
||||||
* @param {Object} details An object with properties `failed`, `name`,
|
|
||||||
* `passed`, and `total`.
|
|
||||||
*/
|
|
||||||
function testDone(details) {
|
|
||||||
var assertions = QUnit.config.testStats.assertions,
|
|
||||||
testName = details.name;
|
|
||||||
|
|
||||||
if (details.failed > 0) {
|
|
||||||
console.log(' FAIL - '+ testName);
|
|
||||||
each(assertions, function(value) {
|
|
||||||
console.log(' ' + value);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
console.log(' PASS - ' + testName);
|
|
||||||
}
|
|
||||||
assertions.length = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
/**
|
// expose shortcuts
|
||||||
* An object used to hold information about the current running test.
|
|
||||||
*
|
|
||||||
* @memberOf QUnit.config
|
|
||||||
* @type Object
|
|
||||||
*/
|
|
||||||
QUnit.config.testStats = {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An array of test summaries (pipe separated).
|
|
||||||
*
|
|
||||||
* @memberOf QUnit.config.testStats
|
|
||||||
* @type Array
|
|
||||||
*/
|
|
||||||
'assertions': []
|
|
||||||
};
|
|
||||||
|
|
||||||
// add shortcuts to the global
|
|
||||||
// exclude `module` because some environments have it as a built-in object
|
// exclude `module` because some environments have it as a built-in object
|
||||||
each(['asyncTest', 'deepEqual', 'equal', 'equals', 'expect', 'notDeepEqual',
|
('asyncTest deepEqual equal equals expect notDeepEqual notEqual notStrictEqual ' +
|
||||||
'notEqual', 'notStrictEqual', 'ok', 'raises', 'same', 'start', 'stop',
|
'ok raises same start stop strictEqual test throws').replace(/\S+/g, function(methodName) {
|
||||||
'strictEqual', 'test', 'throws'], function(funcName) {
|
window[methodName] = QUnit[methodName];
|
||||||
var func = QUnit[funcName];
|
|
||||||
if (func) {
|
|
||||||
global[funcName] = func;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// expose timer methods to global
|
// add `console.log()` support for Narwhal, Rhino, and RingoJS
|
||||||
try {
|
if (!window.console && window.print) {
|
||||||
timer = new java.util.Timer;
|
window.console = { 'log': window.print };
|
||||||
if (!isFunction(global.clearInterval)) {
|
}
|
||||||
global.clearInterval = clearTimer;
|
|
||||||
}
|
|
||||||
if (!isFunction(global.clearTimeout)) {
|
|
||||||
global.clearTimeout = clearTimer;
|
|
||||||
}
|
|
||||||
if (!isFunction(global.setInterval)) {
|
|
||||||
global.setInterval = setInterval;
|
|
||||||
}
|
|
||||||
if (!isFunction(global.setTimeout)) {
|
|
||||||
global.setTimeout = setTimeout;
|
|
||||||
}
|
|
||||||
} catch(e) { }
|
|
||||||
|
|
||||||
// add callbacks
|
|
||||||
QUnit.done(done);
|
|
||||||
QUnit.log(log);
|
|
||||||
QUnit.moduleStart(moduleStart);
|
|
||||||
QUnit.testDone(testDone);
|
|
||||||
|
|
||||||
// add wrapped function
|
|
||||||
QUnit.jsDump.parsers.object = parseObject;
|
|
||||||
|
|
||||||
// must call `QUnit.start()` in the test file if using QUnit < 1.3.0 with
|
// must call `QUnit.start()` in the test file if using QUnit < 1.3.0 with
|
||||||
// Node.js or any version of QUnit with Narwhal, Rhino, or RingoJS
|
// Node.js or any version of QUnit with Narwhal, PhantomJS, Rhino, or RingoJS
|
||||||
QUnit.init();
|
QUnit.init();
|
||||||
|
|
||||||
}(typeof global == 'object' && global || this));
|
}(typeof global == 'object' && global || this));
|
||||||
|
|||||||
Reference in New Issue
Block a user