Pact Reference
Free reference guide: Pact Reference
About Pact Reference
The Pact Reference is a searchable quick-reference for Pact consumer-driven contract testing. It covers consumer-side testing (PactV3 setup, addInteraction, executeTest, MessageConsumerPact), provider-side verification (Verifier, stateHandlers, requestFilter), contract structure (Pact file format, providerState, Content-Type, pending pacts), matchers (MatchersV3.like, eachLike, regex, integer, datetime), Pact Broker operations (publish, can-i-deploy, webhooks, environment management), and verification strategies (consumerVersionSelectors, CI/CD pipelines, WIP pacts).
Built for QA engineers, backend developers, and DevOps teams implementing microservice contract testing, this reference provides copy-ready TypeScript and CLI examples for every Pact workflow step.
All 26 entries are organized into six categories -- Consumer, Provider, Contract, Matchers, Broker, and Verification -- enabling fast lookup during test implementation, CI pipeline configuration, or debugging contract failures.
Key Features
- PactV3 consumer test setup with addInteraction, provider states, and executeTest examples
- Provider verification with Verifier, stateHandlers for test data setup, and requestFilter for auth tokens
- Contract structure reference: Pact JSON format, providerState, pending pacts, and Content-Type handling
- MatchersV3 API: type matching (like), array matching (eachLike), regex, integer, decimal, and datetime matchers
- Pact Broker CLI commands: publish, can-i-deploy, create-environment, record-deployment, and webhooks
- CI/CD pipeline integration with GitHub Actions examples for provider verification and can-i-deploy checks
- MessageConsumerPact for event-driven architectures and asynchronous message contract testing
- Searchable across all six categories with instant keyword filtering
Frequently Asked Questions
What Pact topics does this reference cover?
It covers the complete Pact workflow: consumer-side testing (PactV3, addInteraction, executeTest, message pacts), provider verification (Verifier, stateHandlers, requestFilter), contract structure (JSON format, provider states, pending pacts), matchers (like, eachLike, regex, integer, datetime), Pact Broker operations (publish, can-i-deploy, webhooks, environments), and CI/CD integration (GitHub Actions, consumerVersionSelectors, WIP pacts).
What is consumer-driven contract testing?
Consumer-driven contract testing is an approach where the consumer (API client) defines the expected interactions with a provider (API server) in a contract file. The provider then verifies it can fulfill all contracts. This ensures API compatibility without requiring integration tests and catches breaking changes before deployment.
How do Pact matchers work?
Matchers validate the structure and type of responses rather than exact values. MatchersV3.like(1) checks that the field is a number, eachLike({id: 1}) validates array element structure, regex() matches against a pattern, integer() and decimal() enforce number types, and datetime() validates date/time formats. This makes contracts flexible while still enforcing the API shape.
What is the can-i-deploy command?
can-i-deploy is a Pact Broker CLI command that checks whether a specific version of a service can be safely deployed to an environment. It verifies that all consumer contracts have been successfully verified by the provider. It is the final gate before deployment in a CI/CD pipeline.
How do I set up provider state handlers?
Provider state handlers are functions that set up the test data required by each interaction. Define them in the Verifier options with stateHandlers mapping state names (from consumer tests) to async functions. For example, "a user exists" might create a test user in the database before verification.
What are pending and WIP pacts?
Pending pacts are new contracts that will not fail the provider build if verification fails, giving providers time to implement the expected behavior. WIP (Work In Progress) pacts are automatically included from a specified date, allowing the provider to discover new consumer expectations without manual configuration.
Can Pact test message-based (event-driven) integrations?
Yes. MessageConsumerPact allows you to define expected message contracts for event-driven architectures. The consumer specifies the expected message content, and the provider verifies it can produce messages matching the contract. This works for Kafka, RabbitMQ, SNS/SQS, and other message brokers.
Is this Pact reference free?
Yes, completely free with no account or download required. All content runs in your browser with zero server calls. It is part of liminfo.com's collection of free developer and testing tools.