consumer-contracts
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -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 @@ }; |
{ | ||
"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(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
28798
434
272