Skip to content

Commit 395dc01

Browse files
committed
feat!: change Pact to PactV2 / PactOptions to PactV2Options
1 parent c65d962 commit 395dc01

11 files changed

+46
-41
lines changed

README.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212

1313
### Features
1414

15-
- [x] instantiates the PactOptions for you
15+
- [x] instantiates the PactV2Options/PactV3Options for you
1616
- [x] Setups Pact mock service before and after hooks so you don’t have to
1717
- [x] Set Jest timeout to 30 seconds preventing brittle tests in slow environments like Docker
1818
- [x] Sensible defaults for the pact options that make sense with Jest
1919
- [x] Supports both the main release of pact-js (9.x.x) and the beta 10.x.x for Pact spec V3
2020

2121
## `Jest-Pact` Roadmap
2222

23+
- [ ] Add PactV4 interface with `JestProvidedPactFnV4`
24+
- [ ] BREAKING CHANGE: make `JestProvidedPactFn` default to `JestProvidedPactFnV4`
25+
- [ ] BREAKING CHANGE: rename `JestProvidedPactFn` to `JestProvidedPactFnV2`
2326
- [ ] Ensure that jest-pact plays well with jest's default of watch-mode (This has been mothballed, please see this [draft pr](https://github.com/pact-foundation/jest-pact/pull/53) for details. Contributions welcome!
2427
- [ ] Ensure that pact failures print nice diffs (at the moment you have to go digging in the log files)
2528
- [ ] Add a setup hook for clearing out log and pact files
@@ -232,14 +235,16 @@ Jest-Pact has two primary functions:
232235
233236
Additionally, `pactWith.only / fpactWith`, `pactWith.skip / xpactWith`, `messagePactWith.only / fmessagePactWith` and `messagePactWith.skip / xmessagePactWith` behave as you would expect from Jest.
234237
235-
There are two types exported:
238+
There are two types exported (depending on whether you are using the V2 or V3 Pact interface):
236239
237-
- `JestProvidedPactFn`: This is the type of the second argument to `pactWith`, ie: `(provider: Pact) => void`
238-
- `JestPactOptions`: An extended version of `PactOptions` that has some additional convienience options (see below).
240+
- `JestProvidedPactFn`: This is the type of the second argument to `pactWith`, ie: `(provider: PactV2) => void`
241+
- `JestPactOptions`: An extended version of `PactV2Options` that has some additional convenience options (see below).
242+
- `JestProvidedPactFnV3`: This is the type of the second argument to `pactWith`, ie: `(provider: PactV3) => void`
243+
- `JestPactOptionsV3`: An extended version of `PactV3Options` that has some additional convenience options (see below).
239244
240245
## Configuration
241246
242-
You can use all the usual `PactOptions` from pact-js, plus a timeout for
247+
You can use all the usual `PactV2Options`/`PactV3Options` from pact-js, plus a timeout for
243248
telling jest to wait a bit longer for pact to start and run.
244249
245250
```ts
@@ -257,14 +262,14 @@ interface ExtraOptions {
257262
logFileName?: string; // filename for the log file
258263
}
259264

260-
type JestPactOptions = PactOptions & ExtraOptions;
265+
type JestPactOptions = PactV2Options & ExtraOptions;
261266

262267
type JestMessageConsumerOptions = MessageConsumerOptions & ExtraOptions;
263268
```
264269
265270
### Defaults
266271
267-
Jest-Pact sets some helpful default PactOptions for you. You can override any of these by explicitly setting corresponding option. Here are the defaults:
272+
Jest-Pact sets some helpful default `PactV2Options`/`PactV3Options` for you. You can override any of these by explicitly setting corresponding option. Here are the defaults:
268273
269274
- `log` is set so that log files are written to `/pact/logs`, and named `<consumer>-<provider>-mockserver-interaction.log`. If you provided an explicit `port`, then the log file name is `<consumer>-<provider>-mockserver-interaction-port-<portNumber>.log`
270275
- `dir` is set so that pact files are written to `/pact/pacts`

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jest-pact",
3-
"version": "0.11.4",
3+
"version": "0.12.0",
44
"description": "a pact adaptor for jest",
55
"main": "dist/index.js",
66
"scripts": {
@@ -22,7 +22,7 @@
2222
"url": "git+https://github.com/pact-foundation/jest-pact.git"
2323
},
2424
"engines": {
25-
"node": ">=16"
25+
"node": ">=20"
2626
},
2727
"author": "YOU54F",
2828
"contributors": [
@@ -43,7 +43,7 @@
4343
"devDependencies": {
4444
"@commitlint/cli": "^19.0.0",
4545
"@commitlint/config-conventional": "^19.2.2",
46-
"@pact-foundation/pact": "^15.0.0",
46+
"@pact-foundation/pact": "^16.0.0",
4747
"@pact-foundation/pact-js-prettier-config": "^1.0.0",
4848
"@tsconfig/node14": "^14.0.0",
4949
"@types/jest": "^30.0.0",
@@ -72,7 +72,7 @@
7272
"typescript": "5.9.2"
7373
},
7474
"peerDependencies": {
75-
"@pact-foundation/pact": "^v10.0.0-beta.61 || ^10.0.2 || ^11.0.2 || ^12.0.0 || ^13.0.0 || ^14.0.0 || ^15.0.0",
75+
"@pact-foundation/pact": "^16.0.0" ,
7676
"jest": "^24.0.0 || ^25.0.0 || ^26.0.0 || ^27.0.0 || ^28.0.0 || ^29.0.0 || ^30.0.0"
7777
},
7878
"lint-staged": {

src/internal/scaffold.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { MessageConsumerOptions, PactOptions } from '@pact-foundation/pact';
1+
import { MessageConsumerOptions, PactV2Options } from '@pact-foundation/pact';
22
import { ConsumerOptions, WrapperFn, WrapperWithOnlyAndSkip } from './types';
33

4-
const describeString = (options: PactOptions | MessageConsumerOptions) =>
4+
const describeString = (options: PactV2Options | MessageConsumerOptions) =>
55
`Pact between ${options.consumer} and ${options.provider}`;
66

77
const describePactWith = <

src/pactWith.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { Pact } from '@pact-foundation/pact';
1+
import { PactV2 } from '@pact-foundation/pact';
22
import { applyPactOptionDefaults } from './internal/config';
33
import { WrapperFn } from './internal/types';
44
import { withTimeout } from './internal/withTimeout';
55

66
import { extendPactWith } from './internal/scaffold';
77
import { JestPactOptions, JestProvidedPactFn } from './types';
88

9-
const setupProvider = (options: JestPactOptions): Pact => {
10-
const pactMock: Pact = new Pact(options);
9+
const setupProvider = (options: JestPactOptions): PactV2 => {
10+
const pactMock: PactV2 = new PactV2(options);
1111

1212
beforeAll(() => pactMock.setup());
1313
afterAll(() => pactMock.finalize());
@@ -17,7 +17,7 @@ const setupProvider = (options: JestPactOptions): Pact => {
1717
};
1818

1919
// This should be moved to pact-js, probably
20-
export const getProviderBaseUrl = (provider: Pact): string =>
20+
export const getProviderBaseUrl = (provider: PactV2): string =>
2121
provider.mockService
2222
? provider.mockService.baseUrl
2323
: `http://${provider.opts.host}:${provider.opts.port}`;

src/test/fpactwith.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { InteractionObject, Pact } from '@pact-foundation/pact';
1+
import { InteractionObject, PactV2 } from '@pact-foundation/pact';
22
import supertest = require('supertest');
33
import { fpactWith } from '../index';
44

5-
const getClient = (provider: Pact) => supertest(provider.mockService.baseUrl);
5+
const getClient = (provider: PactV2) => supertest(provider.mockService.baseUrl);
66

77
const postValidRequest: InteractionObject = {
88
state: 'A pet 1845563262948980200 exists',
@@ -20,7 +20,7 @@ const postValidRequest: InteractionObject = {
2020
describe('fpactwith', () => {
2121
fpactWith(
2222
{ consumer: 'MyConsumer', provider: 'NoProvider' },
23-
(provider: Pact) => {
23+
(provider: PactV2) => {
2424
beforeEach(() => provider.addInteraction(postValidRequest));
2525

2626
it('should only run this test', () =>

src/test/messagePactWith.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
Matchers,
2+
MatchersV2,
33
MessageConsumerPact,
44
synchronousBodyHandler,
55
} from '@pact-foundation/pact';
@@ -17,7 +17,7 @@ function dogApiHandler(dog: Dog): void {
1717
throw new Error('missing fields');
1818
}
1919
}
20-
const { like, term } = Matchers;
20+
const { like, term } = MatchersV2;
2121

2222
const arbitraryPact = (provider: MessageConsumerPact) => {
2323
describe('receive dog event', () => {

src/test/pactwith.only.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { InteractionObject, Pact } from '@pact-foundation/pact';
1+
import { InteractionObject, PactV2 } from '@pact-foundation/pact';
22
import supertest = require('supertest');
33
import { pactWith } from '../index';
44

5-
const getClient = (provider: Pact) => supertest(provider.mockService.baseUrl);
5+
const getClient = (provider: PactV2) => supertest(provider.mockService.baseUrl);
66

77
const postValidRequest: InteractionObject = {
88
state: 'A pet 1845563262948980200 exists',
@@ -20,7 +20,7 @@ const postValidRequest: InteractionObject = {
2020
describe('pactwith.only', () => {
2121
pactWith.only(
2222
{ consumer: 'MyConsumer', provider: 'NoProvider' },
23-
(provider: Pact) => {
23+
(provider: PactV2) => {
2424
beforeEach(() => provider.addInteraction(postValidRequest));
2525
it('should only run this test', () =>
2626
getClient(provider)

src/test/pactwith.skip.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Pact } from '@pact-foundation/pact';
1+
import { PactV2 } from '@pact-foundation/pact';
22
import { pactWith } from '../index';
33

44
describe('pactwith.skip', () => {
55
pactWith.skip(
66
{ consumer: 'MyConsumer', provider: 'NoOtherProvider' },
7-
(_provider: Pact) => {
7+
(_provider: PactV2) => {
88
test('the test that should be skipped', () => {
99
throw new Error('tests inside xpactWith should not run');
1010
});

src/test/pactwith.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { InteractionObject, Pact } from '@pact-foundation/pact';
1+
import { InteractionObject, PactV2 } from '@pact-foundation/pact';
22
import { agent } from 'supertest';
33
import { getProviderBaseUrl, pactWith } from '../index';
44

5-
const getClient = (provider: Pact) =>
5+
const getClient = (provider: PactV2) =>
66
agent(provider.mockService.baseUrl);
77
const pactPort = 5001;
88

@@ -21,7 +21,7 @@ const postValidRequest: InteractionObject = {
2121

2222
pactWith(
2323
{ consumer: 'MyConsumer', provider: 'pactWith', port: pactPort },
24-
(provider: Pact) => {
24+
(provider: PactV2) => {
2525
describe('pact integration', () => {
2626
beforeEach(() => provider.addInteraction(postValidRequest));
2727

@@ -59,7 +59,7 @@ pactWith(
5959

6060
pactWith(
6161
{ consumer: 'MyConsumer', provider: 'pactWith2' },
62-
(provider: Pact) => {
62+
(provider: PactV2) => {
6363
describe('pact integration 2', () => {
6464
beforeEach(() => provider.addInteraction(postValidRequest));
6565

@@ -95,7 +95,7 @@ pactWith(
9595
);
9696

9797
describe('custom log locations', () => {
98-
const arbitraryPact = (provider: Pact) => {
98+
const arbitraryPact = (provider: PactV2) => {
9999
describe('pact test', () => {
100100
beforeEach(() => provider.addInteraction(postValidRequest));
101101

@@ -115,7 +115,7 @@ describe('custom log locations', () => {
115115
provider: 'pactWith2',
116116
logDir: 'pact/log/custom',
117117
},
118-
(provider: Pact) => {
118+
(provider: PactV2) => {
119119
arbitraryPact(provider);
120120
}
121121
);
@@ -128,7 +128,7 @@ describe('custom log locations', () => {
128128
logDir: 'pact/log/custom',
129129
logFileName: 'someLog.txt',
130130
},
131-
(provider: Pact) => {
131+
(provider: PactV2) => {
132132
arbitraryPact(provider);
133133
}
134134
);
@@ -141,7 +141,7 @@ describe('custom log locations', () => {
141141
provider: 'pactWith2',
142142
logFileName: 'someOtherLog.txt',
143143
},
144-
(provider: Pact) => {
144+
(provider: PactV2) => {
145145
arbitraryPact(provider);
146146
}
147147
);

src/test/xpactwith.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { Pact } from '@pact-foundation/pact';
1+
import { PactV2 } from '@pact-foundation/pact';
22
import { xpactWith } from '../index';
33

44
describe('xpactwith', () => {
55
xpactWith(
66
{ consumer: 'MyConsumer', provider: 'NoOtherProvider' },
7-
(_provider: Pact) => {
7+
(_provider: PactV2) => {
88
test('the test that should be skipped', () => {
99
throw new Error('tests inside xpactWith should not run');
1010
});

0 commit comments

Comments
 (0)