specify-core
Version:
Describe, structure and runs tests for the Specify framework.
141 lines • 4.53 kB
JavaScript
var /**
* Represents and handles reports.
*
* @module specify-core/lib/report
*/
// -- Dependencies -----------------------------------------------------
adt = require('adt-simple');
var result = require('./result');
var // -- Aliases ----------------------------------------------------------
Success = result.Result.Success;
var Failure = result.Result.Failure;
var Ignored = result.Result.Ignored;
var // -- Report -----------------------------------------------------------
/**
* Summarises the execution of a series of test cases.
*
* @class
* @summary
* { started : Date
* , finished : Date
* , passed : Array[Result]
* , failed : Array[Result]
* , ignored : Array[Result]
* }
*/
Report = function () {
function Report$2(started, finished, passed, failed, ignored) {
if (!(this instanceof Report$2)) {
return new Report$2(started, finished, passed, failed, ignored);
}
if (Object.prototype.toString.call(started) === '[object Date]') {
this.started = started;
} else {
throw new TypeError('Unexpected type for field: Report.started');
}
if (Object.prototype.toString.call(finished) === '[object Date]') {
this.finished = finished;
} else {
throw new TypeError('Unexpected type for field: Report.finished');
}
if (Array.isArray ? Array.isArray(passed) : Object.prototype.toString.call(passed) === '[object Array]') {
this.passed = passed;
} else {
throw new TypeError('Unexpected type for field: Report.passed');
}
if (Array.isArray ? Array.isArray(failed) : Object.prototype.toString.call(failed) === '[object Array]') {
this.failed = failed;
} else {
throw new TypeError('Unexpected type for field: Report.failed');
}
if (Array.isArray ? Array.isArray(ignored) : Object.prototype.toString.call(ignored) === '[object Array]') {
this.ignored = ignored;
} else {
throw new TypeError('Unexpected type for field: Report.ignored');
}
}
var derived = adt.Base.derive({
name: 'Report',
constructor: Report$2,
prototype: Report$2.prototype,
variants: [{
name: 'Report',
constructor: Report$2,
prototype: Report$2.prototype,
fields: [
'started',
'finished',
'passed',
'failed',
'ignored'
]
}]
});
return derived.constructor;
}();
/**
* Adds a result to a report.
*
* @summary @Report => Result → Report
*/
Report.prototype.add = function (result$2) {
var report = this.set({ finished: new Date() });
return function (a0) {
var r0 = Success.unapply(a0);
if (r0 != null && r0.length === 3) {
var _ = r0[2];
var _ = r0[2];
var _ = r0[2];
return report.set({ passed: report.passed.concat([result$2]) });
}
var r1 = Failure.unapply(a0);
if (r1 != null && r1.length === 4) {
var _ = r1[3];
var _ = r1[3];
var _ = r1[3];
var _ = r1[3];
return report.set({ failed: report.failed.concat([result$2]) });
}
var r2 = Ignored.unapply(a0);
if (r2 != null && r2.length === 1) {
var _ = r2[0];
return report.set({ ignored: report.ignored.concat([result$2]) });
}
throw new TypeError('No match');
}.call(this, result$2);
};
/**
* Constructs a new empty report.
*
* @summary @Report => Void → Report
*/
Report.empty = function () {
return Report.create({
started: new Date(),
finished: new Date(),
passed: [],
failed: [],
ignored: []
});
};
/**
* Computes the duration of the report.
*
* @summary @Report => Void → <Number/ms>
*/
Report.prototype.time = function () {
return this.finished - this.started;
};
/**
* Returns all tests in this report.
*
* @summary @Report => Void → Array[Result]
*/
Report.prototype.all = function () {
return this.passed.concat(this.failed).sort(function (a, b) {
return a.started - b.started;
}).concat(this.ignored);
};
// -- Exports ----------------------------------------------------------
module.exports = { Report: Report };
//# sourceMappingURL=report.js.map