code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
function loadShould () {
// explicitly define this method as function as to have it's name to include as `ssfi`
function shouldGetter() {
if (this instanceof String || this instanceof Number) {
return new Assertion(this.constructor(this), null, shouldGetter);
} else if (this instanceof Boolean) {
return new Assertion(this == true, null, shouldGetter);
}
return new Assertion(this, null, shouldGetter);
}
function shouldSetter(value) {
// See https://github.com/chaijs/chai/issues/86: this makes
// `whatever.should = someValue` actually set `someValue`, which is
// especially useful for `global.should = require('chai').should()`.
//
// Note that we have to use [[DefineProperty]] instead of [[Put]]
// since otherwise we would trigger this very setter!
Object.defineProperty(this, 'should', {
value: value,
enumerable: true,
configurable: true,
writable: true
});
}
// modify Object.prototype to have `should`
Object.defineProperty(Object.prototype, 'should', {
set: shouldSetter
, get: shouldGetter
, configurable: true
});
var should = {};
/**
* ### .fail(actual, expected, [message], [operator])
*
* Throw a failure.
*
* @name fail
* @param {Mixed} actual
* @param {Mixed} expected
* @param {String} message
* @param {String} operator
* @api public
*/
should.fail = function (actual, expected, message, operator) {
message = message || 'should.fail()';
throw new chai.AssertionError(message, {
actual: actual
, expected: expected
, operator: operator
}, should.fail);
};
should.equal = function (val1, val2, msg) {
new Assertion(val1, msg).to.equal(val2);
};
should.Throw = function (fn, errt, errs, msg) {
new Assertion(fn, msg).to.Throw(errt, errs);
};
should.exist = function (val, msg) {
new Assertion(val, msg).to.exist;
}
// negation
should.not = {}
should.not.equal = function (val1, val2, msg) {
new Assertion(val1, msg).to.not.equal(val2);
};
should.not.Throw = function (fn, errt, errs, msg) {
new Assertion(fn, msg).to.not.Throw(errt, errs);
};
should.not.exist = function (val, msg) {
new Assertion(val, msg).to.not.exist;
}
should['throw'] = should['Throw'];
should.not['throw'] = should.not['Throw'];
return should;
}
|
### .fail(actual, expected, [message], [operator])
Throw a failure.
@name fail
@param {Mixed} actual
@param {Mixed} expected
@param {String} message
@param {String} operator
@api public
|
loadShould
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function shouldGetter() {
if (this instanceof String || this instanceof Number) {
return new Assertion(this.constructor(this), null, shouldGetter);
} else if (this instanceof Boolean) {
return new Assertion(this == true, null, shouldGetter);
}
return new Assertion(this, null, shouldGetter);
}
|
### .fail(actual, expected, [message], [operator])
Throw a failure.
@name fail
@param {Mixed} actual
@param {Mixed} expected
@param {String} message
@param {String} operator
@api public
|
shouldGetter
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function shouldSetter(value) {
// See https://github.com/chaijs/chai/issues/86: this makes
// `whatever.should = someValue` actually set `someValue`, which is
// especially useful for `global.should = require('chai').should()`.
//
// Note that we have to use [[DefineProperty]] instead of [[Put]]
// since otherwise we would trigger this very setter!
Object.defineProperty(this, 'should', {
value: value,
enumerable: true,
configurable: true,
writable: true
});
}
|
### .fail(actual, expected, [message], [operator])
Throw a failure.
@name fail
@param {Mixed} actual
@param {Mixed} expected
@param {String} message
@param {String} operator
@api public
|
shouldSetter
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
assert = function assert() {
var old_ssfi = flag(this, 'ssfi');
if (old_ssfi && config.includeStack === false)
flag(this, 'ssfi', assert);
var result = chainableBehavior.method.apply(this, arguments);
return result === undefined ? this : result;
}
|
### addChainableMethod (ctx, name, method, chainingBehavior)
Adds a method to an object, such that the method can also be chained.
utils.addChainableMethod(chai.Assertion.prototype, 'foo', function (str) {
var obj = utils.flag(this, 'object');
new chai.Assertion(obj).to.be.equal(str);
});
Can also be accessed directly from `chai.Assertion`.
chai.Assertion.addChainableMethod('foo', fn, chainingBehavior);
The result can then be used as both a method assertion, executing both `method` and
`chainingBehavior`, or as a language chain, which only executes `chainingBehavior`.
expect(fooStr).to.be.foo('bar');
expect(fooStr).to.be.foo.equal('foo');
@param {Object} ctx object to which the method is added
@param {String} name of method to add
@param {Function} method function to be used for `name`, when called
@param {Function} chainingBehavior function to be called every time the property is accessed
@name addChainableMethod
@api public
|
assert
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function parsePath (path) {
var str = path.replace(/\[/g, '.[')
, parts = str.match(/(\\\.|[^.]+?)+/g);
return parts.map(function (value) {
var re = /\[(\d+)\]$/
, mArr = re.exec(value);
if (mArr) return { i: parseFloat(mArr[1]) };
else return { p: value };
});
}
|
### .getPathInfo(path, object)
This allows the retrieval of property info in an
object given a string path.
The path info consists of an object with the
following properties:
* parent - The parent object of the property referenced by `path`
* name - The name of the final property, a number if it was an array indexer
* value - The value of the property, if it exists, otherwise `undefined`
* exists - Whether the property exists or not
@param {String} path
@param {Object} object
@returns {Object} info
@name getPathInfo
@api public
|
parsePath
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function _getPathValue (parsed, obj, index) {
var tmp = obj
, res;
index = (index === undefined ? parsed.length : index);
for (var i = 0, l = index; i < l; i++) {
var part = parsed[i];
if (tmp) {
if ('undefined' !== typeof part.p)
tmp = tmp[part.p];
else if ('undefined' !== typeof part.i)
tmp = tmp[part.i];
if (i == (l - 1)) res = tmp;
} else {
res = undefined;
}
}
return res;
}
|
### .getPathInfo(path, object)
This allows the retrieval of property info in an
object given a string path.
The path info consists of an object with the
following properties:
* parent - The parent object of the property referenced by `path`
* name - The name of the final property, a number if it was an array indexer
* value - The value of the property, if it exists, otherwise `undefined`
* exists - Whether the property exists or not
@param {String} path
@param {Object} object
@returns {Object} info
@name getPathInfo
@api public
|
_getPathValue
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function addProperty(property) {
if (result.indexOf(property) === -1) {
result.push(property);
}
}
|
### .getProperties(object)
This allows the retrieval of property names of an object, enumerable or not,
inherited or not.
@param {Object} object
@returns {Array}
@name getProperties
@api public
|
addProperty
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function inspect(obj, showHidden, depth, colors) {
var ctx = {
showHidden: showHidden,
seen: [],
stylize: function (str) { return str; }
};
return formatValue(ctx, obj, (typeof depth === 'undefined' ? 2 : depth));
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
inspect
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
isDOMElement = function (object) {
if (typeof HTMLElement === 'object') {
return object instanceof HTMLElement;
} else {
return object &&
typeof object === 'object' &&
object.nodeType === 1 &&
typeof object.nodeName === 'string';
}
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
isDOMElement
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function formatValue(ctx, value, recurseTimes) {
// Provide a hook for user-specified inspect functions.
// Check that value is an object with an inspect function on it
if (value && typeof value.inspect === 'function' &&
// Filter out the util module, it's inspect function is special
value.inspect !== exports.inspect &&
// Also filter out any prototype objects using the circular check.
!(value.constructor && value.constructor.prototype === value)) {
var ret = value.inspect(recurseTimes);
if (typeof ret !== 'string') {
ret = formatValue(ctx, ret, recurseTimes);
}
return ret;
}
// Primitive types cannot have properties
var primitive = formatPrimitive(ctx, value);
if (primitive) {
return primitive;
}
// If this is a DOM element, try to get the outer HTML.
if (isDOMElement(value)) {
if ('outerHTML' in value) {
return value.outerHTML;
// This value does not have an outerHTML attribute,
// it could still be an XML element
} else {
// Attempt to serialize it
try {
if (document.xmlVersion) {
var xmlSerializer = new XMLSerializer();
return xmlSerializer.serializeToString(value);
} else {
// Firefox 11- do not support outerHTML
// It does, however, support innerHTML
// Use the following to render the element
var ns = "http://www.w3.org/1999/xhtml";
var container = document.createElementNS(ns, '_');
container.appendChild(value.cloneNode(false));
html = container.innerHTML
.replace('><', '>' + value.innerHTML + '<');
container.innerHTML = '';
return html;
}
} catch (err) {
// This could be a non-native DOM implementation,
// continue with the normal flow:
// printing the element as if it is an object.
}
}
}
// Look up the keys of the object.
var visibleKeys = getEnumerableProperties(value);
var keys = ctx.showHidden ? getProperties(value) : visibleKeys;
// Some type of object without properties can be shortcutted.
// In IE, errors have a single `stack` property, or if they are vanilla `Error`,
// a `stack` plus `description` property; ignore those for consistency.
if (keys.length === 0 || (isError(value) && (
(keys.length === 1 && keys[0] === 'stack') ||
(keys.length === 2 && keys[0] === 'description' && keys[1] === 'stack')
))) {
if (typeof value === 'function') {
var name = getName(value);
var nameSuffix = name ? ': ' + name : '';
return ctx.stylize('[Function' + nameSuffix + ']', 'special');
}
if (isRegExp(value)) {
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
}
if (isDate(value)) {
return ctx.stylize(Date.prototype.toUTCString.call(value), 'date');
}
if (isError(value)) {
return formatError(value);
}
}
var base = '', array = false, braces = ['{', '}'];
// Make Array say that they are Array
if (isArray(value)) {
array = true;
braces = ['[', ']'];
}
// Make functions say that they are functions
if (typeof value === 'function') {
var name = getName(value);
var nameSuffix = name ? ': ' + name : '';
base = ' [Function' + nameSuffix + ']';
}
// Make RegExps say that they are RegExps
if (isRegExp(value)) {
base = ' ' + RegExp.prototype.toString.call(value);
}
// Make dates with properties first say the date
if (isDate(value)) {
base = ' ' + Date.prototype.toUTCString.call(value);
}
// Make error with message first say the error
if (isError(value)) {
return formatError(value);
}
if (keys.length === 0 && (!array || value.length == 0)) {
return braces[0] + base + braces[1];
}
if (recurseTimes < 0) {
if (isRegExp(value)) {
return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
} else {
return ctx.stylize('[Object]', 'special');
}
}
ctx.seen.push(value);
var output;
if (array) {
output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
} else {
output = keys.map(function(key) {
return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
});
}
ctx.seen.pop();
return reduceToSingleString(output, base, braces);
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
formatValue
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function formatPrimitive(ctx, value) {
switch (typeof value) {
case 'undefined':
return ctx.stylize('undefined', 'undefined');
case 'string':
var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
.replace(/'/g, "\\'")
.replace(/\\"/g, '"') + '\'';
return ctx.stylize(simple, 'string');
case 'number':
if (value === 0 && (1/value) === -Infinity) {
return ctx.stylize('-0', 'number');
}
return ctx.stylize('' + value, 'number');
case 'boolean':
return ctx.stylize('' + value, 'boolean');
}
// For some reason typeof null is "object", so special case here.
if (value === null) {
return ctx.stylize('null', 'null');
}
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
formatPrimitive
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function formatError(value) {
return '[' + Error.prototype.toString.call(value) + ']';
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
formatError
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
var output = [];
for (var i = 0, l = value.length; i < l; ++i) {
if (Object.prototype.hasOwnProperty.call(value, String(i))) {
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
String(i), true));
} else {
output.push('');
}
}
keys.forEach(function(key) {
if (!key.match(/^\d+$/)) {
output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
key, true));
}
});
return output;
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
formatArray
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
var name, str;
if (value.__lookupGetter__) {
if (value.__lookupGetter__(key)) {
if (value.__lookupSetter__(key)) {
str = ctx.stylize('[Getter/Setter]', 'special');
} else {
str = ctx.stylize('[Getter]', 'special');
}
} else {
if (value.__lookupSetter__(key)) {
str = ctx.stylize('[Setter]', 'special');
}
}
}
if (visibleKeys.indexOf(key) < 0) {
name = '[' + key + ']';
}
if (!str) {
if (ctx.seen.indexOf(value[key]) < 0) {
if (recurseTimes === null) {
str = formatValue(ctx, value[key], null);
} else {
str = formatValue(ctx, value[key], recurseTimes - 1);
}
if (str.indexOf('\n') > -1) {
if (array) {
str = str.split('\n').map(function(line) {
return ' ' + line;
}).join('\n').substr(2);
} else {
str = '\n' + str.split('\n').map(function(line) {
return ' ' + line;
}).join('\n');
}
}
} else {
str = ctx.stylize('[Circular]', 'special');
}
}
if (typeof name === 'undefined') {
if (array && key.match(/^\d+$/)) {
return str;
}
name = JSON.stringify('' + key);
if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
name = name.substr(1, name.length - 2);
name = ctx.stylize(name, 'name');
} else {
name = name.replace(/'/g, "\\'")
.replace(/\\"/g, '"')
.replace(/(^"|"$)/g, "'");
name = ctx.stylize(name, 'string');
}
}
return name + ': ' + str;
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
formatProperty
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function reduceToSingleString(output, base, braces) {
var numLinesEst = 0;
var length = output.reduce(function(prev, cur) {
numLinesEst++;
if (cur.indexOf('\n') >= 0) numLinesEst++;
return prev + cur.length + 1;
}, 0);
if (length > 60) {
return braces[0] +
(base === '' ? '' : base + '\n ') +
' ' +
output.join(',\n ') +
' ' +
braces[1];
}
return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
reduceToSingleString
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function isArray(ar) {
return Array.isArray(ar) ||
(typeof ar === 'object' && objectToString(ar) === '[object Array]');
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
isArray
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function isRegExp(re) {
return typeof re === 'object' && objectToString(re) === '[object RegExp]';
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
isRegExp
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function isDate(d) {
return typeof d === 'object' && objectToString(d) === '[object Date]';
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
isDate
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function isError(e) {
return typeof e === 'object' && objectToString(e) === '[object Error]';
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
isError
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function objectToString(o) {
return Object.prototype.toString.call(o);
}
|
Echos the value of a value. Trys to print the value out
in the best way possible given the different types.
@param {Object} obj The object to print out.
@param {Boolean} showHidden Flag that shows hidden (not enumerable)
properties of objects.
@param {Number} depth Depth in which to descend in object. Default is 2.
@param {Boolean} colors Flag to turn on ANSI escape codes to color the
output. Default is false (no coloring).
|
objectToString
|
javascript
|
louischatriot/nedb
|
browser-version/test/chai.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/chai.js
|
MIT
|
function all(promises) {
/*jshint validthis:true */
var Promise = this;
if (!isArray(promises)) {
throw new TypeError('You must pass an array to all.');
}
return new Promise(function(resolve, reject) {
var results = [], remaining = promises.length,
promise;
if (remaining === 0) {
resolve([]);
}
function resolver(index) {
return function(value) {
resolveAll(index, value);
};
}
function resolveAll(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(results);
}
}
for (var i = 0; i < promises.length; i++) {
promise = promises[i];
if (promise && isFunction(promise.then)) {
promise.then(resolver(i), reject);
} else {
resolveAll(i, promise);
}
}
});
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
all
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function resolver(index) {
return function(value) {
resolveAll(index, value);
};
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
resolver
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function resolveAll(index, value) {
results[index] = value;
if (--remaining === 0) {
resolve(results);
}
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
resolveAll
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function useNextTick() {
return function() {
process.nextTick(flush);
};
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
useNextTick
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function useMutationObserver() {
var iterations = 0;
var observer = new BrowserMutationObserver(flush);
var node = document.createTextNode('');
observer.observe(node, { characterData: true });
return function() {
node.data = (iterations = ++iterations % 2);
};
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
useMutationObserver
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function useSetTimeout() {
return function() {
local.setTimeout(flush, 1);
};
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
useSetTimeout
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function flush() {
for (var i = 0; i < queue.length; i++) {
var tuple = queue[i];
var callback = tuple[0], arg = tuple[1];
callback(arg);
}
queue = [];
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
flush
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function asap(callback, arg) {
var length = queue.push([callback, arg]);
if (length === 1) {
// If length is 1, that means that we need to schedule an async flush.
// If additional callbacks are queued before the queue is flushed, they
// will be processed by this flush that we are scheduling.
scheduleFlush();
}
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
asap
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function configure(name, value) {
if (arguments.length === 2) {
config[name] = value;
} else {
return config[name];
}
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
configure
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function polyfill() {
var local;
if (typeof global !== 'undefined') {
local = global;
} else if (typeof window !== 'undefined' && window.document) {
local = window;
} else {
local = self;
}
var es6PromiseSupport =
"Promise" in local &&
// Some of these methods are missing from
// Firefox/Chrome experimental implementations
"resolve" in local.Promise &&
"reject" in local.Promise &&
"all" in local.Promise &&
"race" in local.Promise &&
// Older version of the spec had a resolver object
// as the arg rather than a function
(function() {
var resolve;
new local.Promise(function(r) { resolve = r; });
return isFunction(resolve);
}());
if (!es6PromiseSupport) {
local.Promise = RSVPPromise;
}
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
polyfill
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function Promise(resolver) {
if (!isFunction(resolver)) {
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
}
if (!(this instanceof Promise)) {
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
}
this._subscribers = [];
invokeResolver(resolver, this);
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
Promise
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function invokeResolver(resolver, promise) {
function resolvePromise(value) {
resolve(promise, value);
}
function rejectPromise(reason) {
reject(promise, reason);
}
try {
resolver(resolvePromise, rejectPromise);
} catch(e) {
rejectPromise(e);
}
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
invokeResolver
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function resolvePromise(value) {
resolve(promise, value);
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
resolvePromise
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function rejectPromise(reason) {
reject(promise, reason);
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
rejectPromise
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function invokeCallback(settled, promise, callback, detail) {
var hasCallback = isFunction(callback),
value, error, succeeded, failed;
if (hasCallback) {
try {
value = callback(detail);
succeeded = true;
} catch(e) {
failed = true;
error = e;
}
} else {
value = detail;
succeeded = true;
}
if (handleThenable(promise, value)) {
return;
} else if (hasCallback && succeeded) {
resolve(promise, value);
} else if (failed) {
reject(promise, error);
} else if (settled === FULFILLED) {
resolve(promise, value);
} else if (settled === REJECTED) {
reject(promise, value);
}
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
invokeCallback
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function subscribe(parent, child, onFulfillment, onRejection) {
var subscribers = parent._subscribers;
var length = subscribers.length;
subscribers[length] = child;
subscribers[length + FULFILLED] = onFulfillment;
subscribers[length + REJECTED] = onRejection;
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
subscribe
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function publish(promise, settled) {
var child, callback, subscribers = promise._subscribers, detail = promise._detail;
for (var i = 0; i < subscribers.length; i += 3) {
child = subscribers[i];
callback = subscribers[i + settled];
invokeCallback(settled, child, callback, detail);
}
promise._subscribers = null;
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
publish
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function handleThenable(promise, value) {
var then = null,
resolved;
try {
if (promise === value) {
throw new TypeError("A promises callback cannot return that same promise.");
}
if (objectOrFunction(value)) {
then = value.then;
if (isFunction(then)) {
then.call(value, function(val) {
if (resolved) { return true; }
resolved = true;
if (value !== val) {
resolve(promise, val);
} else {
fulfill(promise, val);
}
}, function(val) {
if (resolved) { return true; }
resolved = true;
reject(promise, val);
});
return true;
}
}
} catch (error) {
if (resolved) { return true; }
reject(promise, error);
return true;
}
return false;
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
handleThenable
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function resolve(promise, value) {
if (promise === value) {
fulfill(promise, value);
} else if (!handleThenable(promise, value)) {
fulfill(promise, value);
}
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
resolve
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function fulfill(promise, value) {
if (promise._state !== PENDING) { return; }
promise._state = SEALED;
promise._detail = value;
config.async(publishFulfillment, promise);
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
fulfill
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function reject(promise, reason) {
if (promise._state !== PENDING) { return; }
promise._state = SEALED;
promise._detail = reason;
config.async(publishRejection, promise);
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
reject
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function publishFulfillment(promise) {
publish(promise, promise._state = FULFILLED);
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
publishFulfillment
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function publishRejection(promise) {
publish(promise, promise._state = REJECTED);
}
|
Returns a promise that is fulfilled when all the given promises have been
fulfilled, or rejected if any of them become rejected. The return promise
is fulfilled with an array that gives all the values in the order they were
passed in the `promises` array argument.
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.resolve(2);
var promise3 = RSVP.resolve(3);
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// The array here would be [ 1, 2, 3 ];
});
```
If any of the `promises` given to `RSVP.all` are rejected, the first promise
that is rejected will be given as an argument to the returned promises's
rejection handler. For example:
Example:
```javascript
var promise1 = RSVP.resolve(1);
var promise2 = RSVP.reject(new Error("2"));
var promise3 = RSVP.reject(new Error("3"));
var promises = [ promise1, promise2, promise3 ];
RSVP.all(promises).then(function(array){
// Code here never runs because there are rejected promises!
}, function(error) {
// error.message === "2"
});
```
@method all
@for RSVP
@param {Array} promises
@param {String} label
@return {Promise} promise that is fulfilled when all `promises` have been
fulfilled, or rejected if any of them become rejected.
|
publishRejection
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function race(promises) {
/*jshint validthis:true */
var Promise = this;
if (!isArray(promises)) {
throw new TypeError('You must pass an array to race.');
}
return new Promise(function(resolve, reject) {
var results = [], promise;
for (var i = 0; i < promises.length; i++) {
promise = promises[i];
if (promise && typeof promise.then === 'function') {
promise.then(resolve, reject);
} else {
resolve(promise);
}
}
});
}
|
`RSVP.race` allows you to watch a series of promises and act as soon as the
first promise given to the `promises` argument fulfills or rejects.
Example:
```javascript
var promise1 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve("promise 1");
}, 200);
});
var promise2 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve("promise 2");
}, 100);
});
RSVP.race([promise1, promise2]).then(function(result){
// result === "promise 2" because it was resolved before promise1
// was resolved.
});
```
`RSVP.race` is deterministic in that only the state of the first completed
promise matters. For example, even if other promises given to the `promises`
array argument are resolved, but the first completed promise has become
rejected before the other promises became fulfilled, the returned promise
will become rejected:
```javascript
var promise1 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
resolve("promise 1");
}, 200);
});
var promise2 = new RSVP.Promise(function(resolve, reject){
setTimeout(function(){
reject(new Error("promise 2"));
}, 100);
});
RSVP.race([promise1, promise2]).then(function(result){
// Code here never runs because there are rejected promises!
}, function(reason){
// reason.message === "promise2" because promise 2 became rejected before
// promise 1 became fulfilled
});
```
@method race
@for RSVP
@param {Array} promises array of promises to observe
@param {String} label optional string for describing the promise returned.
Useful for tooling.
@return {Promise} a promise that becomes fulfilled with the value the first
completed promises is resolved with if the first completed promise was
fulfilled, or rejected with the reason that the first completed promise
was rejected with.
|
race
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function reject(reason) {
/*jshint validthis:true */
var Promise = this;
return new Promise(function (resolve, reject) {
reject(reason);
});
}
|
`RSVP.reject` returns a promise that will become rejected with the passed
`reason`. `RSVP.reject` is essentially shorthand for the following:
```javascript
var promise = new RSVP.Promise(function(resolve, reject){
reject(new Error('WHOOPS'));
});
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
var promise = RSVP.reject(new Error('WHOOPS'));
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
@method reject
@for RSVP
@param {Any} reason value that the returned promise will be rejected with.
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise that will become rejected with the given
`reason`.
|
reject
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function resolve(value) {
/*jshint validthis:true */
if (value && typeof value === 'object' && value.constructor === this) {
return value;
}
var Promise = this;
return new Promise(function(resolve) {
resolve(value);
});
}
|
`RSVP.reject` returns a promise that will become rejected with the passed
`reason`. `RSVP.reject` is essentially shorthand for the following:
```javascript
var promise = new RSVP.Promise(function(resolve, reject){
reject(new Error('WHOOPS'));
});
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
var promise = RSVP.reject(new Error('WHOOPS'));
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
@method reject
@for RSVP
@param {Any} reason value that the returned promise will be rejected with.
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise that will become rejected with the given
`reason`.
|
resolve
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function objectOrFunction(x) {
return isFunction(x) || (typeof x === "object" && x !== null);
}
|
`RSVP.reject` returns a promise that will become rejected with the passed
`reason`. `RSVP.reject` is essentially shorthand for the following:
```javascript
var promise = new RSVP.Promise(function(resolve, reject){
reject(new Error('WHOOPS'));
});
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
var promise = RSVP.reject(new Error('WHOOPS'));
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
@method reject
@for RSVP
@param {Any} reason value that the returned promise will be rejected with.
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise that will become rejected with the given
`reason`.
|
objectOrFunction
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function isFunction(x) {
return typeof x === "function";
}
|
`RSVP.reject` returns a promise that will become rejected with the passed
`reason`. `RSVP.reject` is essentially shorthand for the following:
```javascript
var promise = new RSVP.Promise(function(resolve, reject){
reject(new Error('WHOOPS'));
});
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
var promise = RSVP.reject(new Error('WHOOPS'));
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
@method reject
@for RSVP
@param {Any} reason value that the returned promise will be rejected with.
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise that will become rejected with the given
`reason`.
|
isFunction
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function isArray(x) {
return Object.prototype.toString.call(x) === "[object Array]";
}
|
`RSVP.reject` returns a promise that will become rejected with the passed
`reason`. `RSVP.reject` is essentially shorthand for the following:
```javascript
var promise = new RSVP.Promise(function(resolve, reject){
reject(new Error('WHOOPS'));
});
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
Instead of writing the above, your code now simply becomes the following:
```javascript
var promise = RSVP.reject(new Error('WHOOPS'));
promise.then(function(value){
// Code here doesn't run because the promise is rejected!
}, function(reason){
// reason.message === 'WHOOPS'
});
```
@method reject
@for RSVP
@param {Any} reason value that the returned promise will be rejected with.
@param {String} label optional string for identifying the returned promise.
Useful for tooling.
@return {Promise} a promise that will become rejected with the given
`reason`.
|
isArray
|
javascript
|
louischatriot/nedb
|
browser-version/test/localforage.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/localforage.js
|
MIT
|
function isArray(obj) {
return '[object Array]' == {}.toString.call(obj);
}
|
Check if `obj` is an array.
|
isArray
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function Hook(title, fn) {
Runnable.call(this, title, fn);
this.type = 'hook';
}
|
Initialize a new `Hook` with the given `title` and callback `fn`.
@param {String} title
@param {Function} fn
@api private
|
Hook
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function visit(obj) {
var suite;
for (var key in obj) {
if ('function' == typeof obj[key]) {
var fn = obj[key];
switch (key) {
case 'before':
suites[0].beforeAll(fn);
break;
case 'after':
suites[0].afterAll(fn);
break;
case 'beforeEach':
suites[0].beforeEach(fn);
break;
case 'afterEach':
suites[0].afterEach(fn);
break;
default:
suites[0].addTest(new Test(key, fn));
}
} else {
var suite = Suite.create(suites[0], key);
suites.unshift(suite);
visit(obj[key]);
suites.shift();
}
}
}
|
TDD-style interface:
exports.Array = {
'#indexOf()': {
'should return -1 when the value is not present': function(){
},
'should return the correct index when the value is present': function(){
}
}
};
|
visit
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function image(name) {
return __dirname + '/../images/' + name + '.png';
}
|
Return image `name` path.
@param {String} name
@return {String}
@api private
|
image
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function Mocha(options) {
options = options || {};
this.files = [];
this.options = options;
this.grep(options.grep);
this.suite = new exports.Suite('', new exports.Context);
this.ui(options.ui);
this.reporter(options.reporter);
if (options.timeout) this.timeout(options.timeout);
if (options.slow) this.slow(options.slow);
}
|
Setup mocha with `options`.
Options:
- `ui` name "bdd", "tdd", "exports" etc
- `reporter` reporter instance, defaults to `mocha.reporters.Dot`
- `globals` array of accepted globals
- `timeout` timeout in milliseconds
- `slow` milliseconds to wait before considering a test slow
- `ignoreLeaks` ignore global leaks
- `grep` string or regexp to filter tests with
@param {Object} options
@api public
|
Mocha
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function parse(str) {
var m = /^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(str);
if (!m) return;
var n = parseFloat(m[1]);
var type = (m[2] || 'ms').toLowerCase();
switch (type) {
case 'years':
case 'year':
case 'y':
return n * 31557600000;
case 'days':
case 'day':
case 'd':
return n * 86400000;
case 'hours':
case 'hour':
case 'h':
return n * 3600000;
case 'minutes':
case 'minute':
case 'm':
return n * 60000;
case 'seconds':
case 'second':
case 's':
return n * 1000;
case 'ms':
return n;
}
}
|
Parse the given `str` and return milliseconds.
@param {String} str
@return {Number}
@api private
|
parse
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function format(ms) {
if (ms == d) return (ms / d) + ' day';
if (ms > d) return (ms / d) + ' days';
if (ms == h) return (ms / h) + ' hour';
if (ms > h) return (ms / h) + ' hours';
if (ms == m) return (ms / m) + ' minute';
if (ms > m) return (ms / m) + ' minutes';
if (ms == s) return (ms / s) + ' second';
if (ms > s) return (ms / s) + ' seconds';
return ms + ' ms';
}
|
Format the given `ms`.
@param {Number} ms
@return {String}
@api public
|
format
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function Base(runner) {
var self = this
, stats = this.stats = { suites: 0, tests: 0, passes: 0, pending: 0, failures: 0 }
, failures = this.failures = [];
if (!runner) return;
this.runner = runner;
runner.on('start', function(){
stats.start = new Date;
});
runner.on('suite', function(suite){
stats.suites = stats.suites || 0;
suite.root || stats.suites++;
});
runner.on('test end', function(test){
stats.tests = stats.tests || 0;
stats.tests++;
});
runner.on('pass', function(test){
stats.passes = stats.passes || 0;
var medium = test.slow() / 2;
test.speed = test.duration > test.slow()
? 'slow'
: test.duration > medium
? 'medium'
: 'fast';
stats.passes++;
});
runner.on('fail', function(test, err){
stats.failures = stats.failures || 0;
stats.failures++;
test.err = err;
failures.push(test);
});
runner.on('end', function(){
stats.end = new Date;
stats.duration = new Date - stats.start;
});
runner.on('pending', function(){
stats.pending++;
});
}
|
Initialize a new `Base` reporter.
All other reporters generally
inherit from this reporter, providing
stats such as test duration, number
of tests passed / failed etc.
@param {Runner} runner
@api public
|
Base
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function pluralize(n) {
return 1 == n ? 'test' : 'tests';
}
|
Output common epilogue used by many of
the bundled reporters.
@api public
|
pluralize
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function pad(str, len) {
str = String(str);
return Array(len - str.length + 1).join(' ') + str;
}
|
Pad the given `str` to `len`.
@param {String} str
@param {String} len
@return {String}
@api private
|
pad
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function errorDiff(err, type) {
return diff['diff' + type](err.actual, err.expected).map(function(str){
str.value = str.value
.replace(/\t/g, '<tab>')
.replace(/\r/g, '<CR>')
.replace(/\n/g, '<LF>\n');
if (str.added) return colorLines('diff added', str.value);
if (str.removed) return colorLines('diff removed', str.value);
return str.value;
}).join('');
}
|
Return a character diff for `err`.
@param {Error} err
@return {String}
@api private
|
errorDiff
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function colorLines(name, str) {
return str.split('\n').map(function(str){
return color(name, str);
}).join('\n');
}
|
Color lines for `str`, using the color `name`.
@param {String} name
@param {String} str
@return {String}
@api private
|
colorLines
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function Doc(runner) {
Base.call(this, runner);
var self = this
, stats = this.stats
, total = runner.total
, indents = 2;
function indent() {
return Array(indents).join(' ');
}
runner.on('suite', function(suite){
if (suite.root) return;
++indents;
console.log('%s<section class="suite">', indent());
++indents;
console.log('%s<h1>%s</h1>', indent(), suite.title);
console.log('%s<dl>', indent());
});
runner.on('suite end', function(suite){
if (suite.root) return;
console.log('%s</dl>', indent());
--indents;
console.log('%s</section>', indent());
--indents;
});
runner.on('pass', function(test){
console.log('%s <dt>%s</dt>', indent(), test.title);
var code = utils.escape(utils.clean(test.fn.toString()));
console.log('%s <dd><pre><code>%s</code></pre></dd>', indent(), code);
});
}
|
Initialize a new `Doc` reporter.
@param {Runner} runner
@api public
|
Doc
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function indent() {
return Array(indents).join(' ');
}
|
Initialize a new `Doc` reporter.
@param {Runner} runner
@api public
|
indent
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function HTMLCov(runner) {
var jade = require('jade')
, file = __dirname + '/templates/coverage.jade'
, str = fs.readFileSync(file, 'utf8')
, fn = jade.compile(str, { filename: file })
, self = this;
JSONCov.call(this, runner, false);
runner.on('end', function(){
process.stdout.write(fn({
cov: self.cov
, coverageClass: coverageClass
}));
});
}
|
Initialize a new `JsCoverage` reporter.
@param {Runner} runner
@api public
|
HTMLCov
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function coverageClass(n) {
if (n >= 75) return 'high';
if (n >= 50) return 'medium';
if (n >= 25) return 'low';
return 'terrible';
}
|
Return coverage class for `n`.
@return {String}
@api private
|
coverageClass
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function HTML(runner, root) {
Base.call(this, runner);
var self = this
, stats = this.stats
, total = runner.total
, stat = fragment(statsTemplate)
, items = stat.getElementsByTagName('li')
, passes = items[1].getElementsByTagName('em')[0]
, passesLink = items[1].getElementsByTagName('a')[0]
, failures = items[2].getElementsByTagName('em')[0]
, failuresLink = items[2].getElementsByTagName('a')[0]
, duration = items[3].getElementsByTagName('em')[0]
, canvas = stat.getElementsByTagName('canvas')[0]
, report = fragment('<ul id="report"></ul>')
, stack = [report]
, progress
, ctx
root = root || document.getElementById('mocha');
if (canvas.getContext) {
var ratio = window.devicePixelRatio || 1;
canvas.style.width = canvas.width;
canvas.style.height = canvas.height;
canvas.width *= ratio;
canvas.height *= ratio;
ctx = canvas.getContext('2d');
ctx.scale(ratio, ratio);
progress = new Progress;
}
if (!root) return error('#mocha div missing, add it to your document');
// pass toggle
on(passesLink, 'click', function () {
var className = /pass/.test(report.className) ? '' : ' pass';
report.className = report.className.replace(/fail|pass/g, '') + className;
});
// failure toggle
on(failuresLink, 'click', function () {
var className = /fail/.test(report.className) ? '' : ' fail';
report.className = report.className.replace(/fail|pass/g, '') + className;
});
root.appendChild(stat);
root.appendChild(report);
if (progress) progress.size(40);
runner.on('suite', function(suite){
if (suite.root) return;
// suite
var url = '?grep=' + encodeURIComponent(suite.fullTitle());
var el = fragment('<li class="suite"><h1><a href="%s">%s</a></h1></li>', url, escape(suite.title));
// container
stack[0].appendChild(el);
stack.unshift(document.createElement('ul'));
el.appendChild(stack[0]);
});
runner.on('suite end', function(suite){
if (suite.root) return;
stack.shift();
});
runner.on('fail', function(test, err){
if ('hook' == test.type || err.uncaught) runner.emit('test end', test);
});
runner.on('test end', function(test){
window.scrollTo(0, document.body.scrollHeight);
// TODO: add to stats
var percent = stats.tests / total * 100 | 0;
if (progress) progress.update(percent).draw(ctx);
// update stats
var ms = new Date - stats.start;
text(passes, stats.passes);
text(failures, stats.failures);
text(duration, (ms / 1000).toFixed(2));
// test
if ('passed' == test.state) {
var el = fragment('<li class="test pass %e"><h2>%e<span class="duration">%ems</span></h2></li>', test.speed, test.title, test.duration);
} else if (test.pending) {
var el = fragment('<li class="test pass pending"><h2>%e</h2></li>', test.title);
} else {
var el = fragment('<li class="test fail"><h2>%e</h2></li>', test.title);
var str = test.err.stack || test.err.toString();
// FF / Opera do not add the message
if (!~str.indexOf(test.err.message)) {
str = test.err.message + '\n' + str;
}
// <=IE7 stringifies to [Object Error]. Since it can be overloaded, we
// check for the result of the stringifying.
if ('[object Error]' == str) str = test.err.message;
// Safari doesn't give you a stack. Let's at least provide a source line.
if (!test.err.stack && test.err.sourceURL && test.err.line !== undefined) {
str += "\n(" + test.err.sourceURL + ":" + test.err.line + ")";
}
el.appendChild(fragment('<pre class="error">%e</pre>', str));
}
// toggle code
// TODO: defer
if (!test.pending) {
var h2 = el.getElementsByTagName('h2')[0];
on(h2, 'click', function(){
pre.style.display = 'none' == pre.style.display
? 'inline-block'
: 'none';
});
var pre = fragment('<pre><code>%e</code></pre>', utils.clean(test.fn.toString()));
el.appendChild(pre);
pre.style.display = 'none';
}
stack[0].appendChild(el);
});
}
|
Initialize a new `Doc` reporter.
@param {Runner} runner
@api public
|
HTML
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function on(el, event, fn) {
if (el.addEventListener) {
el.addEventListener(event, fn, false);
} else {
el.attachEvent('on' + event, fn);
}
}
|
Listen on `event` with callback `fn`.
|
on
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function JSONCov(runner, output) {
var self = this
, output = 1 == arguments.length ? true : output;
Base.call(this, runner);
var tests = []
, failures = []
, passes = [];
runner.on('test end', function(test){
tests.push(test);
});
runner.on('pass', function(test){
passes.push(test);
});
runner.on('fail', function(test){
failures.push(test);
});
runner.on('end', function(){
var cov = global._$jscoverage || {};
var result = self.cov = map(cov);
result.stats = self.stats;
result.tests = tests.map(clean);
result.failures = failures.map(clean);
result.passes = passes.map(clean);
if (!output) return;
process.stdout.write(JSON.stringify(result, null, 2 ));
});
}
|
Initialize a new `JsCoverage` reporter.
@param {Runner} runner
@param {Boolean} output
@api public
|
JSONCov
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function map(cov) {
var ret = {
instrumentation: 'node-jscoverage'
, sloc: 0
, hits: 0
, misses: 0
, coverage: 0
, files: []
};
for (var filename in cov) {
var data = coverage(filename, cov[filename]);
ret.files.push(data);
ret.hits += data.hits;
ret.misses += data.misses;
ret.sloc += data.sloc;
}
if (ret.sloc > 0) {
ret.coverage = (ret.hits / ret.sloc) * 100;
}
return ret;
}
|
Map jscoverage data to a JSON structure
suitable for reporting.
@param {Object} cov
@return {Object}
@api private
|
map
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function coverage(filename, data) {
var ret = {
filename: filename,
coverage: 0,
hits: 0,
misses: 0,
sloc: 0,
source: {}
};
data.source.forEach(function(line, num){
num++;
if (data[num] === 0) {
ret.misses++;
ret.sloc++;
} else if (data[num] !== undefined) {
ret.hits++;
ret.sloc++;
}
ret.source[num] = {
source: line
, coverage: data[num] === undefined
? ''
: data[num]
};
});
ret.coverage = ret.hits / ret.sloc * 100;
return ret;
}
|
Map jscoverage data for a single source file
to a JSON structure suitable for reporting.
@param {String} filename name of the source file
@param {Object} data jscoverage coverage data
@return {Object}
@api private
|
coverage
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function clean(test) {
return {
title: test.title
, fullTitle: test.fullTitle()
, duration: test.duration
}
}
|
Return a plain-object representation of `test`
free of cyclic properties etc.
@param {Object} test
@return {Object}
@api private
|
clean
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function List(runner) {
Base.call(this, runner);
var self = this
, stats = this.stats
, total = runner.total;
runner.on('start', function(){
console.log(JSON.stringify(['start', { total: total }]));
});
runner.on('pass', function(test){
console.log(JSON.stringify(['pass', clean(test)]));
});
runner.on('fail', function(test, err){
console.log(JSON.stringify(['fail', clean(test)]));
});
runner.on('end', function(){
process.stdout.write(JSON.stringify(['end', self.stats]));
});
}
|
Initialize a new `List` test reporter.
@param {Runner} runner
@api public
|
List
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function clean(test) {
return {
title: test.title
, fullTitle: test.fullTitle()
, duration: test.duration
}
}
|
Return a plain-object representation of `test`
free of cyclic properties etc.
@param {Object} test
@return {Object}
@api private
|
clean
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function JSONReporter(runner) {
var self = this;
Base.call(this, runner);
var tests = []
, failures = []
, passes = [];
runner.on('test end', function(test){
tests.push(test);
});
runner.on('pass', function(test){
passes.push(test);
});
runner.on('fail', function(test){
failures.push(test);
});
runner.on('end', function(){
var obj = {
stats: self.stats
, tests: tests.map(clean)
, failures: failures.map(clean)
, passes: passes.map(clean)
};
process.stdout.write(JSON.stringify(obj, null, 2));
});
}
|
Initialize a new `JSON` reporter.
@param {Runner} runner
@api public
|
JSONReporter
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function clean(test) {
return {
title: test.title
, fullTitle: test.fullTitle()
, duration: test.duration
}
}
|
Return a plain-object representation of `test`
free of cyclic properties etc.
@param {Object} test
@return {Object}
@api private
|
clean
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function runway() {
var buf = Array(width).join('-');
return ' ' + color('runway', buf);
}
|
Initialize a new `Landing` reporter.
@param {Runner} runner
@api public
|
runway
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function Markdown(runner) {
Base.call(this, runner);
var self = this
, stats = this.stats
, total = runner.total
, level = 0
, buf = '';
function title(str) {
return Array(level).join('#') + ' ' + str;
}
function indent() {
return Array(level).join(' ');
}
function mapTOC(suite, obj) {
var ret = obj;
obj = obj[suite.title] = obj[suite.title] || { suite: suite };
suite.suites.forEach(function(suite){
mapTOC(suite, obj);
});
return ret;
}
function stringifyTOC(obj, level) {
++level;
var buf = '';
var link;
for (var key in obj) {
if ('suite' == key) continue;
if (key) link = ' - [' + key + '](#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
if (key) buf += Array(level).join(' ') + link;
buf += stringifyTOC(obj[key], level);
}
--level;
return buf;
}
function generateTOC(suite) {
var obj = mapTOC(suite, {});
return stringifyTOC(obj, 0);
}
generateTOC(runner.suite);
runner.on('suite', function(suite){
++level;
var slug = utils.slug(suite.fullTitle());
buf += '<a name="' + slug + '" />' + '\n';
buf += title(suite.title) + '\n';
});
runner.on('suite end', function(suite){
--level;
});
runner.on('pass', function(test){
var code = utils.clean(test.fn.toString());
buf += test.title + '.\n';
buf += '\n```js\n';
buf += code + '\n';
buf += '```\n\n';
});
runner.on('end', function(){
process.stdout.write('# TOC\n');
process.stdout.write(generateTOC(runner.suite));
process.stdout.write(buf);
});
}
|
Initialize a new `Markdown` reporter.
@param {Runner} runner
@api public
|
Markdown
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function title(str) {
return Array(level).join('#') + ' ' + str;
}
|
Initialize a new `Markdown` reporter.
@param {Runner} runner
@api public
|
title
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function indent() {
return Array(level).join(' ');
}
|
Initialize a new `Markdown` reporter.
@param {Runner} runner
@api public
|
indent
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function mapTOC(suite, obj) {
var ret = obj;
obj = obj[suite.title] = obj[suite.title] || { suite: suite };
suite.suites.forEach(function(suite){
mapTOC(suite, obj);
});
return ret;
}
|
Initialize a new `Markdown` reporter.
@param {Runner} runner
@api public
|
mapTOC
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function stringifyTOC(obj, level) {
++level;
var buf = '';
var link;
for (var key in obj) {
if ('suite' == key) continue;
if (key) link = ' - [' + key + '](#' + utils.slug(obj[key].suite.fullTitle()) + ')\n';
if (key) buf += Array(level).join(' ') + link;
buf += stringifyTOC(obj[key], level);
}
--level;
return buf;
}
|
Initialize a new `Markdown` reporter.
@param {Runner} runner
@api public
|
stringifyTOC
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function generateTOC(suite) {
var obj = mapTOC(suite, {});
return stringifyTOC(obj, 0);
}
|
Initialize a new `Markdown` reporter.
@param {Runner} runner
@api public
|
generateTOC
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function Min(runner) {
Base.call(this, runner);
runner.on('start', function(){
// clear screen
process.stdout.write('\u001b[2J');
// set cursor position
process.stdout.write('\u001b[1;3H');
});
runner.on('end', this.epilogue.bind(this));
}
|
Initialize a new `Min` minimal test reporter (best used with --watch).
@param {Runner} runner
@api public
|
Min
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function NyanCat(runner) {
Base.call(this, runner);
var self = this
, stats = this.stats
, width = Base.window.width * .75 | 0
, rainbowColors = this.rainbowColors = self.generateColors()
, colorIndex = this.colorIndex = 0
, numerOfLines = this.numberOfLines = 4
, trajectories = this.trajectories = [[], [], [], []]
, nyanCatWidth = this.nyanCatWidth = 11
, trajectoryWidthMax = this.trajectoryWidthMax = (width - nyanCatWidth)
, scoreboardWidth = this.scoreboardWidth = 5
, tick = this.tick = 0
, n = 0;
runner.on('start', function(){
Base.cursor.hide();
self.draw('start');
});
runner.on('pending', function(test){
self.draw('pending');
});
runner.on('pass', function(test){
self.draw('pass');
});
runner.on('fail', function(test, err){
self.draw('fail');
});
runner.on('end', function(){
Base.cursor.show();
for (var i = 0; i < self.numberOfLines; i++) write('\n');
self.epilogue();
});
}
|
Initialize a new `Dot` matrix test reporter.
@param {Runner} runner
@api public
|
NyanCat
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function draw(color, n) {
write(' ');
write('\u001b[' + color + 'm' + n + '\u001b[0m');
write('\n');
}
|
Draw the "scoreboard" showing the number
of passes, failures and pending tests.
@api private
|
draw
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function indent() {
return Array(indents).join(' ')
}
|
Initialize a new `Spec` test reporter.
@param {Runner} runner
@api public
|
indent
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function TAP(runner) {
Base.call(this, runner);
var self = this
, stats = this.stats
, n = 1;
runner.on('start', function(){
var total = runner.grepTotal(runner.suite);
console.log('%d..%d', 1, total);
});
runner.on('test end', function(){
++n;
});
runner.on('pending', function(test){
console.log('ok %d %s # SKIP -', n, title(test));
});
runner.on('pass', function(test){
console.log('ok %d %s', n, title(test));
});
runner.on('fail', function(test, err){
console.log('not ok %d %s', n, title(test));
console.log(err.stack.replace(/^/gm, ' '));
});
}
|
Initialize a new `TAP` reporter.
@param {Runner} runner
@api public
|
TAP
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function title(test) {
return test.fullTitle().replace(/#/g, '');
}
|
Return a TAP-safe title of `test`
@param {Object} test
@return {String}
@api private
|
title
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function Teamcity(runner) {
Base.call(this, runner);
var stats = this.stats;
runner.on('start', function() {
console.log("##teamcity[testSuiteStarted name='mocha.suite']");
});
runner.on('test', function(test) {
console.log("##teamcity[testStarted name='" + escape(test.fullTitle()) + "']");
});
runner.on('fail', function(test, err) {
console.log("##teamcity[testFailed name='" + escape(test.fullTitle()) + "' message='" + escape(err.message) + "']");
});
runner.on('pending', function(test) {
console.log("##teamcity[testIgnored name='" + escape(test.fullTitle()) + "' message='pending']");
});
runner.on('test end', function(test) {
console.log("##teamcity[testFinished name='" + escape(test.fullTitle()) + "' duration='" + test.duration + "']");
});
runner.on('end', function() {
console.log("##teamcity[testSuiteFinished name='mocha.suite' duration='" + stats.duration + "']");
});
}
|
Initialize a new `Teamcity` reporter.
@param {Runner} runner
@api public
|
Teamcity
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function XUnit(runner) {
Base.call(this, runner);
var stats = this.stats
, tests = []
, self = this;
runner.on('pass', function(test){
tests.push(test);
});
runner.on('fail', function(test){
tests.push(test);
});
runner.on('end', function(){
console.log(tag('testsuite', {
name: 'Mocha Tests'
, tests: stats.tests
, failures: stats.failures
, errors: stats.failures
, skip: stats.tests - stats.failures - stats.passes
, timestamp: (new Date).toUTCString()
, time: stats.duration / 1000
}, false));
tests.forEach(test);
console.log('</testsuite>');
});
}
|
Initialize a new `XUnit` reporter.
@param {Runner} runner
@api public
|
XUnit
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function test(test) {
var attrs = {
classname: test.parent.fullTitle()
, name: test.title
, time: test.duration / 1000
};
if ('failed' == test.state) {
var err = test.err;
attrs.message = escape(err.message);
console.log(tag('testcase', attrs, false, tag('failure', attrs, false, cdata(err.stack))));
} else if (test.pending) {
console.log(tag('testcase', attrs, false, tag('skipped', {}, true)));
} else {
console.log(tag('testcase', attrs, true) );
}
}
|
Output tag for the given `test.`
|
test
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function Runnable(title, fn) {
this.title = title;
this.fn = fn;
this.async = fn && fn.length;
this.sync = ! this.async;
this._timeout = 2000;
this._slow = 75;
this.timedOut = false;
}
|
Initialize a new `Runnable` with the given `title` and callback `fn`.
@param {String} title
@param {Function} fn
@api private
|
Runnable
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function multiple(err) {
if (emitted) return;
emitted = true;
self.emit('error', err || new Error('done() called multiple times'));
}
|
Run the test and invoke `fn(err)`.
@param {Function} fn
@api private
|
multiple
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function done(err) {
if (self.timedOut) return;
if (finished) return multiple(err);
self.clearTimeout();
self.duration = new Date - start;
finished = true;
fn(err);
}
|
Run the test and invoke `fn(err)`.
@param {Function} fn
@api private
|
done
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function Runner(suite) {
var self = this;
this._globals = [];
this.suite = suite;
this.total = suite.total();
this.failures = 0;
this.on('test end', function(test){ self.checkGlobals(test); });
this.on('hook end', function(hook){ self.checkGlobals(hook); });
this.grep(/.*/);
this.globals(utils.keys(global).concat(['errno']));
}
|
Initialize a `Runner` for the given `suite`.
Events:
- `start` execution started
- `end` execution complete
- `suite` (suite) test suite execution started
- `suite end` (suite) all tests (and sub-suites) have finished
- `test` (test) test execution started
- `test end` (test) test completed
- `hook` (hook) hook execution started
- `hook end` (hook) hook complete
- `pass` (test) test passed
- `fail` (test, err) test failed
@api public
|
Runner
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function next(i) {
var hook = hooks[i];
if (!hook) return fn();
self.currentRunnable = hook;
self.emit('hook', hook);
hook.on('error', function(err){
self.failHook(hook, err);
});
hook.run(function(err){
hook.removeAllListeners('error');
var testError = hook.error();
if (testError) self.fail(self.test, testError);
if (err) return self.failHook(hook, err);
self.emit('hook end', hook);
next(++i);
});
}
|
Run hook `name` callbacks and then invoke `fn()`.
@param {String} name
@param {Function} function
@api private
|
next
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function next(suite) {
self.suite = suite;
if (!suite) {
self.suite = orig;
return fn();
}
self.hook(name, function(err){
if (err) {
self.suite = orig;
return fn(err);
}
next(suites.pop());
});
}
|
Run hook `name` for the given array of `suites`
in order, and callback `fn(err)`.
@param {String} name
@param {Array} suites
@param {Function} fn
@api private
|
next
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function next(err) {
// if we bail after first err
if (self.failures && suite._bail) return fn();
// next test
test = tests.shift();
// all done
if (!test) return fn();
// grep
var match = self._grep.test(test.fullTitle());
if (self._invert) match = !match;
if (!match) return next();
// pending
if (test.pending) {
self.emit('pending', test);
self.emit('test end', test);
return next();
}
// execute test and hook(s)
self.emit('test', self.test = test);
self.hookDown('beforeEach', function(){
self.currentRunnable = self.test;
self.runTest(function(err){
test = self.test;
if (err) {
self.fail(test, err);
self.emit('test end', test);
return self.hookUp('afterEach', next);
}
test.state = 'passed';
self.emit('pass', test);
self.emit('test end', test);
self.hookUp('afterEach', next);
});
});
}
|
Run tests in the given `suite` and invoke
the callback `fn()` when complete.
@param {Suite} suite
@param {Function} fn
@api private
|
next
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function next() {
var curr = suite.suites[i++];
if (!curr) return done();
self.runSuite(curr, next);
}
|
Run the given `suite` and invoke the
callback `fn()` when complete.
@param {Suite} suite
@param {Function} fn
@api private
|
next
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
function done() {
self.suite = suite;
self.hook('afterAll', function(){
self.emit('suite end', suite);
fn();
});
}
|
Run the given `suite` and invoke the
callback `fn()` when complete.
@param {Suite} suite
@param {Function} fn
@api private
|
done
|
javascript
|
louischatriot/nedb
|
browser-version/test/mocha.js
|
https://github.com/louischatriot/nedb/blob/master/browser-version/test/mocha.js
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.