'use strict';
// the core (should explain even be there?)
const { Report, addCondition, explain } = require('./report.js');
// TODO add eiffel-style design-by-contract
// import default condition arsenal
require( './cond/basic.js' );
require( './cond/array.js' );
require( './cond/deep.js' );
const getReport = (...args) => new Report().run(...args).done();
// Allow creating multiple parallel configurations of refute
// e.g. one strict (throwing errors) and other lax (just debugging to console)
function setup ( options = {}, orig ) {
// TODO validate options
const onFail = options.onFail || (rep => { throw new Error(rep.toString()) });
const refute = options.skip
? () => {}
: (...args) => {
const ok = new Report();
ok.onDone( x => { if ( !x.getPass() ) onFail(x, args) } );
ok.run(...args);
ok.done();
};
// reexport all from report.js
refute.Report = Report;
refute.explain = explain;
refute.addCondition = addCondition;
// shortcut to validating & returning a fresh contract
// TODO rename to avoid name clash with the class
// (eval?)
refute.report = getReport;
// refute.conf({...}) will generate a _new_ refute
refute.config = update => setup( { ...options, ...update }, refute );
return refute;
}
module.exports = setup();
/**
* @namespace refute
* @desc Functions exported by refutable's main module.
*/
/**
* @public
* @memberOf refute
* @function refute
* @param {Any} [...list] Data to feed to the callback
* @param {Contract} contract A code block with checks.
* @returns {undefined} Return value is ignored.
* @throws {Error} If one or more checks are failing, an exception is thrown
* with details about all passing/failing checks.
* This action can be changed via refute.config() call.
*
*/