Source: runner.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.
/**
 * Runs tests.
 *
 * @module hifive/runner
 */
// -- Dependencies -----------------------------------------------------
var Future = require('data.future');
var Maybe = require('data.maybe');
var rx = require('rx');
var adt = require('adt-simple');
var curry = require('core.lambda').curry;
var core = require('./core');
var Report = require('./report').Report;
// -- Aliases ----------------------------------------------------------
var Result = core.Signal.TestResult;
// -- Configuration ----------------------------------------------------
/**
 * Represents the configuration for executing a series of tests.
 *
 * @class
 * @summary
 * { slowThreshold : &lt;Number/ms&gt;
 * , timeout       : &lt;Number/ms&gt;
 * , runOnly       : Case → Boolean
 * }
 */
var Config = function () {
        function Config$2(slowThreshold, timeout, runOnly) {
            if (!(this instanceof Config$2)) {
                return new Config$2(slowThreshold, timeout, runOnly);
            }
            if (typeof slowThreshold === 'number' || Object.prototype.toString.call(slowThreshold) === '[object Number]') {
                this.slowThreshold = slowThreshold;
            } else {
                throw new TypeError('Unexpected type for field: Config.slowThreshold');
            }
            if (typeof timeout === 'number' || Object.prototype.toString.call(timeout) === '[object Number]') {
                this.timeout = timeout;
            } else {
                throw new TypeError('Unexpected type for field: Config.timeout');
            }
            if (Object.prototype.toString.call(runOnly) === '[object Function]') {
                this.runOnly = runOnly;
            } else {
                throw new TypeError('Unexpected type for field: Config.runOnly');
            }
        }
        var derived = adt.Base.derive({
                name: 'Config',
                constructor: Config$2,
                prototype: Config$2.prototype,
                variants: [{
                        name: 'Config',
                        constructor: Config$2,
                        prototype: Config$2.prototype,
                        fields: [
                            'slowThreshold',
                            'timeout',
                            'runOnly'
                        ]
                    }]
            });
        return derived.constructor;
    }();
/**
 * The default configuration for running tests.
 *
 * @static
 * @summary Config
 */
var defaultConfig = Config.create({
        slowThreshold: 300,
        timeout: 2000,
        runOnly: function () {
            return true;
        }
    });
// -- Core functionality -----------------------------------------------
/**
 * Runs a series of test cases.
 *
 * @static
 * @method
 * @summary 
 * Config
 * → [Test]
 * → (Rx.Observable[α, Signal] → Rx.Observable[α, Signal])
 * → Future[Error, Report]
 */
run = curry(3, run);
function run(config, suites, reporter) {
    return new Future(function (reject, resolve) {
        var resolved = false;
        var stream = suites.map(function (a) {
                return a.run([], config);
            }).reduce(function (a, b) {
                return a.concat(b);
            }, rx.Observable.empty());
        reporter(stream).reduce(function (a, b) {
            return b.cata({
                Result: function (a$2) {
                    return a.add(a$2);
                }
            });
        }, Report.empty()).subscribe(function onValue(report) {
            resolve(report);
        }, function onError(error) {
            reject(error);
        }, function onCompleted() {
        });
    });
}
// -- Exports ----------------------------------------------------------
module.exports = {
    run: run,
    runWithDefaults: run(defaultConfig),
    Report: Report,
    Config: Config,
    defaultConfig: defaultConfig
};
//# sourceMappingURL=runner.js.map