Pact Node
A wrapper for the Pact mock service for it to work with node in an easy to manage way.
Installation
npm install @pact-foundation/pact-node --save
Usage
Simply require the library and call the create function.
var pact = require('@pact-foundation/pact-node');
var server = pact.create({port: 9999});
server.start().then(function() {
});
Documentation
Create Server
var pact = require('@pact-foundation/pact-node');
var server = pact.create({
port: <Number>,
host: <String>,
log: <String>,
ssl: <Boolean>,
cors: <Boolean>,
dir: <String>,
spec: <Number>,
consumer: <String>,
provider: <String>
});
List Servers
If you ever need to see which servers are currently created.
var pact = require('@pact-foundation/pact-node');
var servers = pact.list();
console.log(JSON.stringify(servers));
Remove All Servers
Remove all servers once you're done with them in one fell swoop.
var pact = require('@pact-foundation/pact-node');
pact.removeAll();
Start a server
Start the current server.
var pact = require('@pact-foundation/pact-node');
pact.create().start().then(function(){
});
Stop a server
Stop the current server.
var pact = require('@pact-foundation/pact-node');
pact.create().stop().then(function(){
});
Delete a server
Stop the current server and deletes it from the list.
var pact = require('@pact-foundation/pact-node');
pact.create().delete().then(function(){
});
Check if server is running
var pact = require('@pact-foundation/pact-node');
pact.create().running;
Events
There's 3 different events available, 'start', 'stop' and 'delete'. They can be listened to the same way as an EventEmitter.
var pact = require('@pact-foundation/pact-node');
var server = pact.create();
server.on('start', function() { console.log('started'); });
server.on('stop', function() { console.log('stopped'); });
server.on('delete', function() { console.log('deleted'); });
Contributing
To develop this project, simply install the dependencies and run npm run watch
to for continual development, linting and testing when a source file changes.
Testing
Running npm test
will execute the tests that has the *.spec.js
pattern.