Skip to main content

Migrating from 15.x.x to 16.x.x

New features​

  1. GraphQL support for V3 and V4 interfaces β€” GraphQL interactions can now be used with PactV3 and PactV4 (fixes #1093)
  2. Asynchronous message support β€” V4 now supports asynchronous messages via addAsynchronousInteraction() (fixes #1186)
  3. Synchronous message bodies β€” Bodies are now passed into the executeTest function for synchronous messages
  4. Matching rules support β€” withMatchingRules is 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 exportv16 exportNotes
PactPactV2The V2 HTTP Pact DSL
MatchersMatchersV2The V2 matchers
PactV4Pact (alias)The V4 Pact DSL is now the default
MatchersV3Matchers (alias)The V3 matchers are now the default

Note: PactV3 and MatchersV3 continue 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
PactV4Can be simplified to Pact β€” optional but recommended
MatchersV3Can be simplified to Matchers β€” optional but recommended
PactV3No changes needed

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.