Migrating from 15.x.x to 16.x.x
New featuresβ
- GraphQL support for V3 and V4 interfaces β GraphQL interactions can now be used with
PactV3andPactV4(fixes #1093) - Asynchronous message support β V4 now supports asynchronous messages via
addAsynchronousInteraction()(fixes #1186) - Synchronous message bodies β Bodies are now passed into the
executeTestfunction for synchronous messages - Matching rules support β
withMatchingRulesis now available for HTTP, async, and sync interactions
Breaking changesβ
Import renamesβ
The default Pact and Matchers exports have been changed to point to the V4 and V3 implementations respectively. The previous V2 implementations are still available under explicit names:
| v15 export | v16 export | Notes |
|---|---|---|
Pact | PactV2 | The V2 HTTP Pact DSL |
Matchers | MatchersV2 | The V2 matchers |
PactV4 | Pact (alias) | The V4 Pact DSL is now the default |
MatchersV3 | Matchers (alias) | The V3 matchers are now the default |
Note:
PactV3andMatchersV3continue to be available as named exports β they are unchanged.
Node.js versionβ
Node.js >=20 is now required. Versions 16β19 are no longer supported as they have reached end-of-life. If you cannot upgrade Node.js, remain on pact-js v15.
Downstream packagesβ
The import renames above are known to impact packages that re-export or depend on the Pact / Matchers types:
Check for updated versions of these packages that are compatible with pact-js v16.
Migration guideβ
Consumerβ
Quick referenceβ
| If you currently import⦠| Action |
|---|---|
Pact (V2 DSL) | Rename to PactV2 β required |
Matchers (V2 matchers) | Rename to MatchersV2 β required |
PactV4 | Can be simplified to Pact β optional but recommended |
MatchersV3 | Can be simplified to Matchers β optional but recommended |
PactV3 | No changes needed |
Upgrading to the V4 DSL (recommended)β
If your imports already use the V4 interface:
import {
SpecificationVersion,
PactV4,
LogLevel,
MatchersV3,
} from '@pact-foundation/pact';
Simplify to:
import {
SpecificationVersion,
Pact,
LogLevel,
Matchers,
} from '@pact-foundation/pact';
No other code changes are needed β the API is identical.
Preserving V2 behaviourβ
If your imports use the V2 interface and you want to keep using it, you need to update the import names.
CommonJS:
// Before
const { Pact, Matchers } = require('@pact-foundation/pact');
// After
const { PactV2: Pact, MatchersV2: Matchers } = require('@pact-foundation/pact');
ES Modules:
// Before
import {
Pact,
GraphQLInteraction,
Matchers,
LogLevel,
} from '@pact-foundation/pact';
// After
import {
PactV2 as Pact,
GraphQLInteraction,
MatchersV2 as Matchers,
LogLevel,
} from '@pact-foundation/pact';
Providerβ
No changes are required for provider verification β the Verifier API is fully backwards compatible.