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

@pact-foundation/pact-node

Package Overview
Dependencies
Maintainers
4
Versions
187
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pact-foundation/pact-node

A wrapper for the Ruby version of Pact to work within Node

  • 4.4.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
49K
decreased by-20.28%
Maintainers
4
Weekly downloads
 
Created
Source

Build Status npm npm npm

Pact Node

An idiomatic Node interface for the Pact mock service (Consumer) and Verification (Provider) process.

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.createServer({port: 9999});
server.start().then(function() {
	// Do your testing/development here
});

Documentation

Set Log Level

var pact = require('@pact-foundation/pact-node');
pact.logLevel('debug');

Create Pact Mock Server

var pact = require('@pact-foundation/pact-node');
var server = pact.createServer({
	port: <Number>,     // Port number that the server runs on, defaults to 1234
	host: <String>,     // Host on which to bind the server on, defaults to 'localhost'
	log: <String>,      // File to log output on relative to current working directory, defaults to none
	ssl: <Boolean>,     // Create a self-signed SSL cert to run the server over HTTPS , defaults to 'false'
	cors: <Boolean>,    // Allow CORS OPTION requests to be accepted, defaults to 'false'
	dir: <String>,      // Directory to write the pact contracts relative to the current working directory, defaults to none
	spec: <Number>,     // The pact specification version to use when writing pact contracts, defaults to '1'
	consumer: <String>, // The name of the consumer to be written to the pact contracts, defaults to none
	provider: <String>  // The name of the provider to be written to the pact contracts, defaults to none
});

Run Provider Verification

Read more about Verify Pacts.

var pact = require('@pact-foundation/pact-node');
var opts = {
	providerBaseUrl: <String>,       // Running API provider host endpoint. Required.
	pactUrls: <Array>,               // Array of local Pact file paths or Pact Broker URLs (http based). Required.
	providerStatesUrl: <String>,     // URL to fetch the provider states for the given provider API. Optional.
	providerStatesSetupUrl <String>, // URL to send PUT requests to setup a given provider state. Optional.
	pactBrokerUsername: <String>,    // Username for Pact Broker basic authentication. Optional
	pactBrokerPassword: <String>,    // Password for Pact Broker basic authentication. Optional
};

pact.verifyPacts(opts)).then(function () {
	// do something
});

Publish Pacts to a Broker

var pact = require('@pact-foundation/pact-node');
var opts = {
	pactUrls: <Array>,               // Array of local Pact files or directories containing them. Required.
	pactBroker: <String>,            // URL to fetch the provider states for the given provider API. Optional.
	pactBrokerUsername: <String>,    // Username for Pact Broker basic authentication. Optional
	pactBrokerPassword: <String>     // Password for Pact Broker basic authentication. Optional
};

pact.publishPacts(opts)).then(function () {
	// do something
});

List Mock Servers

If you ever need to see which servers are currently created.

var pact = require('@pact-foundation/pact-node');
var servers = pact.listServers();
console.log(JSON.stringify(servers));

Remove All Mock Servers

Remove all servers once you're done with them in one fell swoop.

var pact = require('@pact-foundation/pact-node');
pact.removeAllServers();

Start a Mock Server server

Start the current server.

var pact = require('@pact-foundation/pact-node');
pact.createServer().start().then(function(){
	// Do something after it started
});

Stop a Mock server

Stop the current server.

var pact = require('@pact-foundation/pact-node');
pact.createServer().stop().then(function(){
	// Do something after it stopped
});

Delete a Mock server

Stop the current server and deletes it from the list.

var pact = require('@pact-foundation/pact-node');
pact.createServer().delete().then(function(){
	// Do something after it was killed
});

Check if a Mock server is running

var pact = require('@pact-foundation/pact-node');
pact.createServer().running;

Mock Server 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.createServer();
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.

Keywords

FAQs

Package last updated on 19 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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