specify-core
Version:
Describe, structure and runs tests for the Specify framework.
265 lines • 8.62 kB
JavaScript
var /**
* Represents and handles test results.
*
* @module specify-core/lib/result
*/
// -- Dependencies -----------------------------------------------------
adt = require('adt-simple');
var // -- Duration ---------------------------------------------------------
/**
* The duration of a particular test.
*
* @class
* @summary
* { started : Date
* , finished : Date
* , slowThreshold : <Number/ms>
* }
*/
Duration = function () {
function Duration$2(started, finished, slowThreshold) {
if (!(this instanceof Duration$2)) {
return new Duration$2(started, finished, slowThreshold);
}
if (Object.prototype.toString.call(started) === '[object Date]') {
this.started = started;
} else {
throw new TypeError('Unexpected type for field: Duration.started');
}
if (Object.prototype.toString.call(finished) === '[object Date]') {
this.finished = finished;
} else {
throw new TypeError('Unexpected type for field: Duration.finished');
}
if (typeof slowThreshold === 'number' || Object.prototype.toString.call(slowThreshold) === '[object Number]') {
this.slowThreshold = slowThreshold;
} else {
throw new TypeError('Unexpected type for field: Duration.slowThreshold');
}
}
var derived = adt.Base.derive({
name: 'Duration',
constructor: Duration$2,
prototype: Duration$2.prototype,
variants: [{
name: 'Duration',
constructor: Duration$2,
prototype: Duration$2.prototype,
fields: [
'started',
'finished',
'slowThreshold'
]
}]
});
return derived.constructor;
}();
/**
* Whether this duration should be considered slow.
*
* @summary @Duration => Void → Boolean
*/
Duration.prototype.isSlow = function () {
return this.time() >= this.slowThreshold;
};
/**
* The total time of this duration in milliseconds.
*
* @summary @Duration => Void → <Number/ms>
*/
Duration.prototype.time = function () {
return this.finished - this.started;
};
/**
* The textual representation of this duration.
*
* @summary @Duration => Void → String
*/
Duration.prototype.toString = function () {
return this.time() + 'ms';
};
var // -- LogEntry ---------------------------------------------------------
/**
* Represents content that has been logged during the execution of a test.
*
* @class
* @summary
* { date: Date
* , log: Array[Any]
* }
*/
LogEntry = function () {
function LogEntry$2(date, log) {
if (!(this instanceof LogEntry$2)) {
return new LogEntry$2(date, log);
}
if (Object.prototype.toString.call(date) === '[object Date]') {
this.date = date;
} else {
throw new TypeError('Unexpected type for field: LogEntry.date');
}
if (Array.isArray ? Array.isArray(log) : Object.prototype.toString.call(log) === '[object Array]') {
this.log = log;
} else {
throw new TypeError('Unexpected type for field: LogEntry.log');
}
}
var derived = adt.Base.derive({
name: 'LogEntry',
constructor: LogEntry$2,
prototype: LogEntry$2.prototype,
variants: [{
name: 'LogEntry',
constructor: LogEntry$2,
prototype: LogEntry$2.prototype,
fields: [
'date',
'log'
]
}]
});
return derived.constructor;
}();
var // -- Result -----------------------------------------------------------
/**
* Represents the results of each test.
*
* @class
* @summary
* | Success: { title : Array[String]
* , duration : Duration
* , log : Array[LogEntry]
* }
* | Failure: { title : Array[String]
* , exception : Any
* , duration : Duration
* , log : Array[LogEntry]
* }
* | Ignored: { title: Array[String] }
*/
Result = function () {
function Result$2() {
}
function Success$2(title, duration, log) {
if (!(this instanceof Success$2)) {
return new Success$2(title, duration, log);
}
if (Array.isArray ? Array.isArray(title) : Object.prototype.toString.call(title) === '[object Array]') {
this.title = title;
} else {
throw new TypeError('Unexpected type for field: Result.Success.title');
}
if (duration instanceof Duration) {
this.duration = duration;
} else {
throw new TypeError('Unexpected type for field: Result.Success.duration');
}
if (Array.isArray ? Array.isArray(log) : Object.prototype.toString.call(log) === '[object Array]') {
this.log = log;
} else {
throw new TypeError('Unexpected type for field: Result.Success.log');
}
}
Success$2.prototype = new Result$2();
Success$2.prototype.constructor = Success$2;
function Failure$2(title, exception, duration, log) {
if (!(this instanceof Failure$2)) {
return new Failure$2(title, exception, duration, log);
}
if (Array.isArray ? Array.isArray(title) : Object.prototype.toString.call(title) === '[object Array]') {
this.title = title;
} else {
throw new TypeError('Unexpected type for field: Result.Failure.title');
}
this.exception = exception;
if (duration instanceof Duration) {
this.duration = duration;
} else {
throw new TypeError('Unexpected type for field: Result.Failure.duration');
}
if (Array.isArray ? Array.isArray(log) : Object.prototype.toString.call(log) === '[object Array]') {
this.log = log;
} else {
throw new TypeError('Unexpected type for field: Result.Failure.log');
}
}
Failure$2.prototype = new Result$2();
Failure$2.prototype.constructor = Failure$2;
function Ignored$2(title) {
if (!(this instanceof Ignored$2)) {
return new Ignored$2(title);
}
if (Array.isArray ? Array.isArray(title) : Object.prototype.toString.call(title) === '[object Array]') {
this.title = title;
} else {
throw new TypeError('Unexpected type for field: Result.Ignored.title');
}
}
Ignored$2.prototype = new Result$2();
Ignored$2.prototype.constructor = Ignored$2;
var derived = adt.Cata.derive(adt.Base.derive({
name: 'Result',
constructor: Result$2,
prototype: Result$2.prototype,
variants: [
{
name: 'Success',
constructor: Success$2,
prototype: Success$2.prototype,
fields: [
'title',
'duration',
'log'
]
},
{
name: 'Failure',
constructor: Failure$2,
prototype: Failure$2.prototype,
fields: [
'title',
'exception',
'duration',
'log'
]
},
{
name: 'Ignored',
constructor: Ignored$2,
prototype: Ignored$2.prototype,
fields: ['title']
}
]
}));
Result$2.Success = derived.variants[0].constructor;
Result$2.Failure = derived.variants[1].constructor;
Result$2.Ignored = derived.variants[2].constructor;
return Result$2;
}();
var Success = Result.Success;
var Failure = Result.Failure;
var Ignored = Result.Ignored;
/**
* Returns the full title of the test that yielded this result, that is, the
* name of the test preceded by the name of all the Suites it's in.
*
* @summary @Result => Void → String
*/
Result.prototype.fullTitle = function () {
return this.title.join(' ');
};
/**
* Returns the name of the test that yielded this result.
*
* @summary @Result => Void → String
*/
Result.prototype.name = function () {
return this.title[this.title.length - 1];
};
// -- Exports ----------------------------------------------------------
module.exports = {
Duration: Duration,
LogEntry: LogEntry,
Result: Result
};
//# sourceMappingURL=result.js.map