Skip to content

Commit

Permalink
Export Frisby constructor to support plugins (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow committed Apr 13, 2017
1 parent 0513779 commit 11152af
Showing 1 changed file with 36 additions and 41 deletions.
77 changes: 36 additions & 41 deletions lib/icedfrisby.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,6 @@ let _init = _icedfrisbyDefaults();
let _initDefined = false;


/**
* specify global defaults for IcedFrisby test run
* @param {object} obj - setup object
* @return {object}
* @desc global setup function
*/
function globalSetup(obj) {
if (!_.isUndefined(obj)) {
if (_initDefined) { globalSetupDefined(_init, obj); }

_initDefined = true;
_init = _.merge(_.cloneDeep(_icedfrisbyDefaults()), obj);

if(_init.useApp) {
_init.request.baseUri = _useAppImpl(_init.useApp);
}
}
return _init;
}


/**
* warn or die if user uses globalSetup() improperly
* @param {object} init -
Expand Down Expand Up @@ -103,6 +82,8 @@ function _hasHeader(headername, headers) {


/**
* Parse body as JSON, ensuring not to re-parse when body is already an object
* (thanks @dcaylor).
* @param {object} body - json object
* @return {object}
* @desc parse response body as json
Expand Down Expand Up @@ -149,7 +130,7 @@ function _useAppImpl (app, basePath) {
* @desc create IcedFrisby object
*/
function Frisby(msg) {
let clone = _.cloneDeep(globalSetup());
let clone = _.cloneDeep(Frisby.globalSetup());

if(clone.request && clone.request.headers) {
let headers = {};
Expand Down Expand Up @@ -195,6 +176,39 @@ function Frisby(msg) {

return this;
}
module.exports = Frisby;


Frisby.version = pkg.version;


/**
* specify global defaults for IcedFrisby test run
* @param {object} obj - setup object
* @return {object}
* @desc global setup function
*/
Frisby.globalSetup = function (obj) {
if (!_.isUndefined(obj)) {
if (_initDefined) { globalSetupDefined(_init, obj); }

_initDefined = true;
_init = _.merge(_.cloneDeep(_icedfrisbyDefaults()), obj);

if(_init.useApp) {
_init.request.baseUri = _useAppImpl(_init.useApp);
}
}
return _init;
};


/**
* Main Frisby method used to start new spec tests
*/
Frisby.create = function (msg) {
return new Frisby(msg);
};


/**
Expand Down Expand Up @@ -1228,22 +1242,3 @@ Frisby.prototype.toss = function (retry) {

});
};

//
// Parse body as JSON, ensuring not to re-parse when body is already an object (thanks @dcaylor)
//

////////////////////
// Module Exports //
////////////////////

//
// Main Frisby method used to start new spec tests
//
exports.create = function(msg) {
return new Frisby(msg);
};

// Public methods and properties
exports.globalSetup = globalSetup;
exports.version = pkg.version;

0 comments on commit 11152af

Please sign in to comment.