consumer-contracts
Advanced tools
Comparing version 1.4.0 to 1.5.0
module.exports.Contract = require('./lib/contract'); | ||
module.exports.Joi = require('joi'); | ||
module.exports.validateContracts = require('./lib/validator'); |
var _ = require('lodash'); | ||
var async = require('async'); | ||
var FileHound = require('filehound'); | ||
@@ -7,12 +6,4 @@ var path = require('path'); | ||
var formatter = require('./formatter'); | ||
var validateContracts = require('./validator'); | ||
function validateContract(contract, cb) { | ||
contract.validate(function (err) { | ||
cb(null, { | ||
contract: contract, | ||
err: err | ||
}); | ||
}); | ||
} | ||
function validateFiles(files) { | ||
@@ -29,3 +20,3 @@ var contracts; | ||
async.mapSeries(contracts, validateContract, function (err, results) { | ||
validateContracts(contracts, function (err, results) { | ||
var failures = _(results).filter('err').compact().value(); | ||
@@ -32,0 +23,0 @@ var totalCompleted = contracts.length; |
{ | ||
"name": "consumer-contracts", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Consumer driven contracts for Node.js", | ||
@@ -31,3 +31,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"async": "^1.5.2", | ||
"async": "^2.0.0", | ||
"chalk": "^1.0.0", | ||
@@ -43,7 +43,7 @@ "commander": "^2.8.1", | ||
"chai": "^3.5.0", | ||
"codeclimate-test-reporter": "^0.3.0", | ||
"codeclimate-test-reporter": "^0.4.0", | ||
"istanbul": "^0.4.2", | ||
"jshint": "^2.8.0", | ||
"mocha": "^2.2.5", | ||
"nock": "^7.0.2", | ||
"mocha": "^3.0.1", | ||
"nock": "^9.0.2", | ||
"sinon": "^1.17.3" | ||
@@ -50,0 +50,0 @@ }, |
@@ -294,1 +294,27 @@ <h1 align="center"> | ||
``` | ||
## Programmatic Usage | ||
To validate an array of contracts programmatically, first require the `validateContracts` function: | ||
```js | ||
var validateContracts = require('consumer-contracts').validateContracts; | ||
``` | ||
The `validateContracts` function can then be called with an array of contracts and a callback function which takes two arguments, | ||
`error` and `results`: | ||
```js | ||
var contracts = [ | ||
new Contract(...), | ||
new Contract(...) | ||
]; | ||
var handleContractValidations = function (err, res) { ... } | ||
validateContracts(contracts, handleContractValidations); | ||
``` | ||
The `error` argument will always be null, as `consumer-contracts` will always run every contract in the array rather than failing fast, as such, error handling must deal with the `err` field of each object in the results array as detailed below. | ||
The `results` will be an array of objects with fields `contract` and `err`. The `contract` field of the result object contains the executed Contract object including any `before` and `after` fields. The `err` field contains any error that occurred when validating the specific contract. Error handling should check the `err` field of every result object is `null` before declaring the contract suite as having been run successfully. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32216
15
493
320
+ Addedasync@2.6.4(transitive)
- Removedasync@1.5.2(transitive)
Updatedasync@^2.0.0