Commit faf4c406 authored by Daniel Shumway's avatar Daniel Shumway

refactor: rename `Group` to `Suite`

- closes issue #5

fix: bad reference to `console` in fallback method
parent 512dffe3
Pipeline #5190799 passed with stage
in 52 seconds
......@@ -20,30 +20,30 @@ const REPORTERS = Object.freeze({
console.clear();
console.log(buffer);
} else {
consoe.log(message);
console.log(message);
}
};
var failPath = function(group) {
if (group.parent == null) { return '()'; }
return failPath(group.parent) + '(' + group.label + ')';
var failPath = function(suite) {
if (suite.parent == null) { return '()'; }
return failPath(suite.parent) + '(' + suite.label + ')';
};
return function (group) {
if (group.parent == null) { return; }
if (group.status === STATUS.PASSED) {
return function (suite) {
if (suite.parent == null) { return; }
if (suite.status === STATUS.PASSED) {
log('.');
} else {
log('X');
log('\n\n' + failPath(group) + ' failed!');
log('\n\n' + failPath(suite) + ' failed!');
if(group.error) {
if (typeof group.error.expected !== 'undefined') {
log('\nExpected: ' + group.error.expected);
log('\nActual: ' + group.error.actual);
if(suite.error) {
if (typeof suite.error.expected !== 'undefined') {
log('\nExpected: ' + suite.error.expected);
log('\nActual: ' + suite.error.actual);
}
log('\n' + group.error.stack);
log('\n' + suite.error.stack);
}
log('\n\n');
......@@ -71,9 +71,9 @@ var uniqueId = (function (i) {
return function () { return Math.random() + '' + (++i); };
}(0));
var Group = (function () {
var Suite = (function () {
var PRIVATE = uniqueId();
function Group(options) {
function Suite(options) {
options = options || {};
var that = this;
var _that = this[PRIVATE] = {
......@@ -122,18 +122,18 @@ var Group = (function () {
});
}
Group._prototype = {
Suite._prototype = {
//Wrap functions in promises to catch any runtime exceptions
wrap : function (assertion) {
var _that = this[PRIVATE];
return function (group) {
return function (suite) {
return new Promise(function (res, rej) {
_that.promisify(assertion, group).then(res, rej);
_that.promisify(assertion, suite).then(res, rej);
});
};
},
promisify : function (result, group) {
promisify : function (result, suite) {
var _that = this[PRIVATE];
if (result == null) {
return Promise.resolve();
......@@ -148,7 +148,7 @@ var Group = (function () {
result.then(function (resolution) {
clearTimeout(timeout);
//For the API to be completely, 100% consistent, allow recursion.
_that.promisify(resolution, group).then(res, rej);
_that.promisify(resolution, suite).then(res, rej);
}, rej)
.catch(rej); //Catch runtime exceptions during recursive `promisify`
});
......@@ -156,7 +156,7 @@ var Group = (function () {
if (typeof result === 'function') {
//For the API to be completely, 100% consistent, allow recursion.
return _that.promisify(result.call(group, group), group);
return _that.promisify(result.call(suite, suite), suite);
}
return result ? Promise.resolve() : Promise.reject();
......@@ -168,8 +168,8 @@ var Group = (function () {
},
};
Group.prototype = {
constructor : Group,
Suite.prototype = {
constructor : Suite,
get error() { return this[PRIVATE].error; },
get status() { return this[PRIVATE].status; },
get label() { return this[PRIVATE].label; },
......@@ -184,34 +184,34 @@ var Group = (function () {
_that = this[PRIVATE];
assertion = _that.wrap(assertion);
var group,
var suite,
promise = _that.promise.then(function () {
//No need to catch exceptions since the promise we're in will handle them.
//https://promisesaplus.com/#point-34 - both `promise` and `group` will be set by execution time
return assertion.call(group, group);
//https://promisesaplus.com/#point-34 - both `promise` and `suite` will be set by execution time
return assertion.call(suite, suite);
}, function (error) {
_that.skip.call(group);
_that.skip.call(suite);
throw error;
});
group = new Group({
suite = new Suite({
label : message,
promise : promise,
parent : that,
callback : _that.callback
});
_that.children.push(group);
return group;
_that.children.push(suite);
return suite;
},
};
return Group;
return Suite;
}());
function Distilled(callback, options) {
options = options || {};
Group.call(this, {
Suite.call(this, {
label : null,
promise : null,
parent : null,
......@@ -220,7 +220,7 @@ function Distilled(callback, options) {
});
}
Distilled.prototype = Group.prototype;
Distilled.prototype = Suite.prototype;
Distilled.STATUS = STATUS;
Distilled.REPORTERS = REPORTERS;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment