// Copyright (c) 2013-2014 Quildreen Motta <quildreen@gmail.com>
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation files
// (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software,
// and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/**
* Represents and handles test results.
*
* @module hifive/result
*/
// -- Dependencies -----------------------------------------------------
var show = require('utils').inspect;
// -- Duration ---------------------------------------------------------
/**
* The duration of a particular test.
*
* @class
* @summary
* { started : Date
* , finished : Date
* , slowThreshold : <Number/ms>
* }
*/
var 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
*/
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';
};
// -- LogEntry ---------------------------------------------------------
/**
* Represents content that has been logged during the execution of a test.
*
* @class
* @summary
* { date: Date
* , log: Array[Any]
* }
*/
var 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;
}();
// -- 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] }
*/
var 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