Skip to content

Commit

Permalink
Merge branch 'master' into after-tests-rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmelnikow committed Apr 13, 2017
2 parents 1298bf2 + 11152af commit ea8fe2c
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 70 deletions.
95 changes: 92 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,93 @@
.DS_Store
/node_modules
npm-debug.log

# Created by https://www.gitignore.io/api/node,osx

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

# End of https://www.gitignore.io/api/node,osx
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ node_js:
- 6
- 5
- 4
after_script: ./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly ./test/*.js -R spec && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage
after_script:
- npm run coverage && coveralls < coverage/lcov.info && rm -rf coverage
15 changes: 4 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build Status](https://api.travis-ci.org/MarkHerhold/IcedFrisby.svg?branch=master)](https://travis-ci.org/MarkHerhold/IcedFrisby/)
[![Coverage Status](https://coveralls.io/repos/github/MarkHerhold/IcedFrisby/badge.svg)](https://coveralls.io/github/MarkHerhold/IcedFrisby)
[![Dependency Status](https://gemnasium.com/RobertHerhold/IcedFrisby.svg)](https://gemnasium.com/RobertHerhold/IcedFrisby)
[![Greenkeeper badge](https://badges.greenkeeper.io/MarkHerhold/IcedFrisby.svg)](https://greenkeeper.io/)
[![npm](https://img.shields.io/npm/v/icedfrisby.svg)](http://www.npmjs.com/package/icedfrisby)


Expand All @@ -25,9 +25,9 @@ The [**IcedFrisby** Changelog](https://github.com/RobertHerhold/IcedFrisby/blob/

## Installation

Install IcedFrisby from NPM:
Install IcedFrisby and Mocha from NPM:

npm install icedfrisby --save-dev
npm install mocha icedfrisby --save-dev

**Note:** IcedFrisby is built and tested against the latest stable versions of Node.js (4, 5, and 6)

Expand Down Expand Up @@ -90,10 +90,6 @@ Any Mocha/Chai/whatever tests can be used inside the `after` and `afterJSON` cal

Run tests as you normally would with [Mocha](https://github.com/mochajs/mocha).

### Install Mocha

npm install -g mocha

### Run it from the CLI

cd your/project
Expand All @@ -103,11 +99,8 @@ Run tests as you normally would with [Mocha](https://github.com/mochajs/mocha).

## IcedFrisby Development

### Setup
Code quality is enforced with JSHint. You will need to install JSHint as it is run with the tests: `npm install -g jshint`

### Code Coverage
You can assess code coverage by running `istanbul cover _mocha ./spec/**/*_spec.js -R spec`
You can assess code coverage by running `npm run coverage`.

### Contributions
Contributions are awesome! If you have an idea or code that you want to contribute, feel free to submit a pull request and I will gladly review it. I am open to pretty much anything.
Expand Down
103 changes: 62 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 All @@ -170,6 +151,7 @@ function Frisby(msg) {
it: null,
isNot: false, // test negation
inspections: [], // array of inspections to perform before the expectations
before: [],
expects: [], // array expectations to perform
after: [],
retry: clone.retry || 0,
Expand All @@ -194,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 @@ -941,6 +956,18 @@ Frisby.prototype.waits = function(ms) {
return this;
};

/**
* @param {afterCallback} cb - callback
* @return {object}
* @desc callback function to run before the request is made
*/
Frisby.prototype.before = function (cb) {
this.current.before.push(function() {
cb.call(this);
});
return this;
};

/**
* @param {afterCallback} cb - callback
* @return {object}
Expand Down Expand Up @@ -1178,6 +1205,19 @@ Frisby.prototype.toss = function () {
mochaContext.retries = (self.current.outgoing.method.toUpperCase() ==
"POST") ? 0 : self.current.retry;

for(let i=0; i < self.current.before.length; i++) {
const fn = self.current.before[i];
if(false !== self._exceptionHandler) {
try {
fn.call(self);
} catch(e) {
self._exceptionHandler(e);
}
} else {
fn.call(self);
}
}

// wait optinally, launch request
if (self.current.waits > 0) {
setTimeout(() => {
Expand All @@ -1189,22 +1229,3 @@ Frisby.prototype.toss = function () {
});
});
};

//
// 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;
22 changes: 15 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,38 @@
"chai-things": "^0.2.0",
"chalk": "^1.1.3",
"check-types": "^7.0.1",
"joi": "^9.2.0",
"joi": "^10.4.1",
"lodash": "^4.16.6",
"mock-request": "^0.1.2",
"qs": "^6.3.0",
"request": "^2.76.0"
},
"peerDependencies": {
"mocha": "*"
},
"devDependencies": {
"coveralls": "^2.11.14",
"express": "^4.14.0",
"form-data": "2.1.1",
"form-data": "^2.1.4",
"intercept-stdout": "^0.1.2",
"istanbul": "^0.4.5",
"jshint": "^2.9.4",
"mocha": "^3.1.2",
"mocha-lcov-reporter": "^1.2.0",
"mochawesome": "^1.5.3",
"mock-request": "^0.1.2",
"nock": "^9.0.2"
},
"main": "./lib/icedfrisby",
"main": "lib/icedfrisby",
"files": [
"lib",
"API.md"
],
"engines": {
"node": "4.x.x || 5.x.x || 6.x.x"
},
"scripts": {
"pretest": "./node_modules/.bin/jshint lib/*.js",
"test": "./node_modules/.bin/mocha"
"coverage": "istanbul cover _mocha --report lcovonly",
"lint": "jshint lib/*.js",
"test:js": "mocha",
"test": "npm run lint && npm run test:js"
}
}
Loading

0 comments on commit ea8fe2c

Please sign in to comment.