Contract Testing using Newman
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.envto build collections
- Support for esModules
- Typescipt definitions
npm install --save newman npm install --save newman-contract
Then, create a file exporting your contract definition:
// contract/search.jsconst ContractDefinition =const baseUrl = ""moduleexports =
Or, with ES Modules:
Now, you need to run newman with a
const newman =const ContractCollection =newman
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