Source: report.js

// 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 reports.
 *
 * @module hifive/report
 */
// -- Dependencies -----------------------------------------------------
var result = require('./result');
// -- Aliases ----------------------------------------------------------
var Success = result.Result.Success;
var Failure = result.Result.Failure;
var Ignored = result.Result.Ignored;
// -- 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]
 * }
 */
var 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 r13 = Success.unapply(a0);
        if (r13 != null && r13.length === 3) {
            var r14 = r13[0];
            var r15 = r13[1];
            var r16 = r13[2];
            var _ = r14, _ = r15, _ = r16;
            return report.set({ passed: report.passed.concat([result$2]) });
        }
        var r17 = Failure.unapply(a0);
        if (r17 != null && r17.length === 4) {
            var r18 = r17[0];
            var r19 = r17[1];
            var r20 = r17[2];
            var r21 = r17[3];
            var _ = r18, _ = r19, _ = r20, _ = r21;
            return report.set({ failed: report.failed.concat([result$2]) });
        }
        var r22 = Ignored.unapply(a0);
        if (r22 != null && r22.length === 1) {
            var r23 = r22[0];
            var _ = r23;
            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 → &lt;Number/ms&gt;
 */
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