Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including karma-pact with all npm packages installed. Try it out:

require("@pact-foundation/pact-node/package.json"); // @pact-foundation/pact-node is a peer dependency. require("karma/package.json"); // karma is a peer dependency. var karmaPact = require("karma-pact")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

karma-pact v0.0.7

Launches a Pact Mock Server for Karma

Karma Pact

Build Status

Implementation of a Karma Plugin to launch a Pact Mock Server before executing your Pact tests on the browser.

From the Pact website:

The Pact family of frameworks provide support for Consumer Driven Contracts testing.

A Contract is a collection of agreements between a client (Consumer) and an API (Provider) that describes the interactions that can take place between them.

Consumer Driven Contracts is a pattern that drives the development of the Provider from its Consumers point of view.

Pact is a testing tool that guarantees those Contracts are satisfied.

Read Getting started with Pact for more information on how to get going.

Installation

First install the package from NPM:

npm install --save-dev karma-pact

Then, on your Karma Configuration file, add the below:

module.exports = function (config) {
  config.set({
    // in here we are simply telling to use Jasmine with Pact
    frameworks: ['jasmine', 'pact'],
    // the Pact opts will go here
    pact: {}
  })

The pact configuration in the file is as follows (same present at pact-node):

{
  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
}

Examples

Check the karma folder under Pact JS for examples with Mocha and Jasmine.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

If you would like to implement Pact in another language, please check out the Pact specification and have a chat to one of us on the pact-dev Google group.

The vision is to have a compatible Pact implementation in all the commonly used languages, your help would be greatly appreciated!

Contact

  • Twitter: @pact_up
  • Google users group: https://groups.google.com/forum/#!forum/pact-support
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free