UNPKG

specify-core

Version:

Describe, structure and runs tests for the Specify framework.

140 lines 4.16 kB
var /** * Runs tests. * * @module specify-core/lib/runner */ // -- Dependencies ----------------------------------------------------- Future = require('data.future'); var rx = require('rx'); var adt = require('adt-simple'); var curry = require('core.lambda').curry; var Report = require('./report').Report; function assimilateResult(report, signal) { return signal.isTestResult ? report.add(signal.value) : report; } 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 = // -- Configuration ---------------------------------------------------- /** * Represents the configuration for executing a series of tests. * * @class * @summary * { slowThreshold : <Number/ms> * , timeout : <Number/ms> * , runOnly : Case → Boolean * } */ 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; }(); var /** * The default configuration for running tests. * * @static * @summary Config */ defaultConfig = Config.create({ slowThreshold: 300, timeout: 2000, runOnly: function () { return true; } }); // -- Core functionality ----------------------------------------------- /** * Constructs a task for running all tests. * * @static * @method * @summary * Config * → [Test] * → (Rx.Observable[α, Signal], Rx.Observable[α, Report] → Void) * → Future[Error, Report] */ makeRunner = curry(3, makeRunner); function makeRunner(config, suites, reporter) { return new Future(function (reject, resolve) { var stream = suites.map(function (a) { return a.run([], config); }).reduce(function (a, b) { return a.concat(b); }, rx.Observable.empty()).publish(); var reportStream = stream.reduce(assimilateResult, Report.empty()); reporter(stream, reportStream); reportStream.subscribe(function onValue(report) { resolve(report); }, function onError(error) { reject(error); }, function onCompleted() { }); stream.connect(); }); } /** * Runs a series of test cases. * * @static * @method * @summary * Config → [Test] → (Rx.Observable[α, Signal], Rx.Observable[α, Report] → Void) → Void */ run = curry(3, run); function run(config, suites, reporter) { makeRunner(config, suites, reporter).fork(function (e) { throw e; }, function (report) { if (report.failed.length) exit(1); if (!report.all().length) exit(1); else exit(0); }); function exit(status) { if (typeof process != 'undefined' && process.exit) process.exit(status); } } module.exports = { run: run, runWithDefaults: run(defaultConfig), makeRunner: makeRunner, Config: Config, defaultConfig: defaultConfig }; //# sourceMappingURL=runner.js.map