How to Choose Pacts With Consumer Version Selectors
Consumer version selectors tell the verifier which consumer pacts to pull, for example the latest on the main branch plus all versions deployed to production.
Replace broad pact URLs with consumerVersionSelectors. Common selectors are the matching branch, the latest from main, and everything currently deployed to an environment.
Steps
- Add
consumerVersionSelectorsto the verifier config. - Include
mainBranch: truefor the current mainline contract. - Include
deployedOrReleased: trueto cover live consumers.
Selectors
provider.verify.js
await new Verifier({
provider: 'orders-api',
providerBaseUrl: 'http://localhost:8080',
pactBrokerUrl: process.env.PACT_BROKER_BASE_URL,
pactBrokerToken: process.env.PACT_BROKER_TOKEN,
providerVersion: process.env.GITHUB_SHA,
consumerVersionSelectors: [
{ mainBranch: true },
{ matchingBranch: true },
{ deployedOrReleased: true },
],
}).verifyProvider();Gotchas
- Verifying every historical version is slow; selectors keep the set to what actually matters.
deployedOrReleaseddepends on record-deployment being called after real deploys.
Related guides
How to Record Deployments and Releases in the Pact BrokerTell the Pact Broker which version is live in each environment using record-deployment and record-release, so…
How to Read the Consumer/Provider Compatibility MatrixUnderstand the Pact Broker matrix that maps every consumer version against every provider version, which is t…