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.2.1 to 1.3.0

5

lib/contract.js

@@ -42,2 +42,3 @@ var Joi = require('joi');

this.before = options.before;
this.after = options.after;
}

@@ -76,2 +77,6 @@

if (this.after) {
tasks.push(this.after);
}
async.series(tasks, cb);

@@ -78,0 +83,0 @@ };

2

package.json
{
"name": "consumer-contracts",
"version": "1.2.1",
"version": "1.3.0",
"description": "Consumer driven contracts for Node.js",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -234,2 +234,23 @@ <h1 align="center">

### `after` _optional_
If your contract requires some cleanup you can use the `after` property. It takes a function that will be run after the contract executes. The after function receives a callback argument that you should call once your cleanup is complete.
```js
module.exports = new Contract({
name: 'Contract name',
consumer: 'Consumer name',
request: {
// ...
},
response: {
// ...
},
after: function (done) {
// cleanup
done();
}
});
```
## CLI

@@ -236,0 +257,0 @@

@@ -232,3 +232,52 @@ var Contract = require('../lib/contract');

});
it('runs the after function after validating the contact', function (done) {
var after = sinon.stub().yields();
nock('http://api.example.com').get('/').reply(200);
var contract = new Contract({
name: 'Name',
consumer: 'Consumer',
request: {
url: 'http://api.example.com/'
},
response: {
statusCode: 200
},
after: after
});
contract.validate(function (err) {
assert.ifError(err);
sinon.assert.called(after);
done();
});
});
it('returns an error when the after function fails', function (done) {
var after = sinon.stub().yields(new Error('Cleanup error'));
nock('http://api.example.com').get('/').reply(200);
var contract = new Contract({
name: 'Name',
consumer: 'Consumer',
request: {
url: 'http://api.example.com/'
},
response: {
statusCode: 200
},
after: after
});
contract.validate(function (err) {
assert.ok(err);
assert.equal(err.message, 'Cleanup error');
done();
});
});
});
});
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