newman-contract
A helper for contract testing using newman
Last updated 4 months ago by arupertti .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install newman-contract 
SYNC missed versions from official npm registry.

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.

:warning: This package is in early development and can still have major changes

Features:

  • 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

Install:

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 = "https://my-api.com"

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')

newman.run({
    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.

contract
  • 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.

options
  • 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

Current Tags

  • 1.0.3                                ...           latest (4 months ago)
  • 1.1.0                                ...           next (3 months ago)

5 Versions

  • 1.1.0                                ...           3 months ago
  • 1.0.3                                ...           4 months ago
  • 1.0.2                                ...           4 months ago
  • 1.0.1                                ...           4 months ago
  • 1.0.0                                ...           4 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (17)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |