Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

consumer-contracts

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

consumer-contracts - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

lib/validator.js

1

index.js
module.exports.Contract = require('./lib/contract');
module.exports.Joi = require('joi');
module.exports.validateContracts = require('./lib/validator');

13

lib/runner.js
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.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc