Get unlimited public & private packages + package-based permissions with npm Pro.Get started »


1.0.3 • Public • Published

npm version Build Status

Contract Testing using Newman

With newman-contract you dont need to relly on postman to read or write your contract tests, just write your contract definition like any other file and then use the powerful newman cli to run it!

If you are not familiar with Consumer-Driven contract tests using Postman, I recommend you to read this article.

⚠️ This package is in early development and can still have major changes


  • Creates a boilerplate collection for contract testing
  • Human readable error messages
  • Easy sorce control over your contracts
  • Able to use process.env to build collections
  • Support for esModules
  • Typescipt definitions

Getting Started


npm install --save newman
npm install --save newman-contract

Then, create a file exporting your contract definition:

// contract/search.js
const { ContractDefinition } = require("newman-contract")
const baseUrl = ""
module.exports = ContractDefinition({
  method: "GET",
  endpoint: `${baseUrl}/search`,
  query: { query: 'my term' }
  schema: {
    type: "object",
    properties: {
        // ... Your JSON schema to match response

Or, with ES Modules:

import { ContractDefinition } from 'newman-contract'
export default ContractDefinition({ ... })

Now, you need to run newman with a ContractCollection

const newman = require('newman')
const { ContractCollection } = require('newman-contract'){
    collection: ContractCollection({ fromPattern: 'contract/*.js' })
    reporters: ['cli'] // You can use any newman reporter

API Reference

ContractDefinition(Object contract) -> Object

Parse the given contract object to a contract definition, building a postman test to match the response to the given schema.

  • method: HTTP method
  • endpoint: endpoint to wich the request is made (accepts encoded query)
  • schema: response schema to match
  • name (optional): Name for the especific test
  • query (optinal): JSON Object containing all request query (priority over encoded query)
  • headers (optional): JSON Object containing all request headers
  • body (optional): JSON Object containing request body data

ContractCollection(Object options) -> JSON Object

Finds all Contract Definitions and builds a postman collection out of it.

  • fromPattern: Glob pattern to find the contract definitions
  • name (optional): Custom name for collection (Default: 'Contract Collection')
  • exportToPath (optional): File path to wich the final collection will be exported to


npm i newman-contract

DownloadsWeekly Downloads






Unpacked Size

31.7 kB

Total Files


Last publish


  • avatar