Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update msw to v2 #126

Merged
merged 7 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
node-version: [16.x, 18.x, 19.x, 20.x]
node-version: [18.x, 19.x, 20.x]
fail-fast: false

steps:
Expand Down
24 changes: 21 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ Let's start by listing it's methods:

| Parameter | Required? | Type | Default | Description |
| - | - | - | - | - |
| server | false | `SetupServerApi` | | server provided by msw - a server or worker must be provided|
| worker | false | `SetupWorkerApi` | | worker provided by msw - a server or worker must be provided|
| server | false | `SetupServer` | | server provided by msw - a server or worker must be provided|
| worker | false | `SetupWorker` | | worker provided by msw - a server or worker must be provided|
| timeout | `false` | `number` | 200 | Time in ms for a network request to expire, `verifyTest` will fail after twice this amount of time. |
| consumer | `true` | `string` | | name of the consumer running the tests |
| providers | `true` | `{ [string]: string[] } | (request: MockedRequest) => string | null` | | names and filters for each provider or function that returns name of provider for given request |
| providers | `true` | `{ [string]: string[] } \| ({ request: Request; requestId: string }) => string \| null` | | names and filters for each provider or function that returns name of provider for given request |
| pactOutDir | `false` | `string` | ./msw_generated_pacts/ | path to write pact files into |
| includeUrl | `false` | `string[]` | | inclusive filters for network calls |
| excludeUrl | `false` | `string[]` | | exclusive filters for network calls |
Expand Down Expand Up @@ -219,6 +219,24 @@ Without further do, it looks like the following:

Here, `matchingRules` represent the assertions of the expectation, while `body`, `query` and `path` contains it's example values.

## Migrating pact-msw-adapter from v2 to v3
YOU54F marked this conversation as resolved.
Show resolved Hide resolved

In [October 2023 msw released new version 2](https://mswjs.io/blog/introducing-msw-2.0) that bring significant changes to the msw interface. To reflect these changes we've released pact-msw-adapter@v3 that's compatible with msw@v2.

To migrate you'll need to update `msw to >=2.0` and migrate your usage of the library ([migration guide here](https://mswjs.io/docs/migrations/1.x-to-2.x)).

Breaking changes on pact-msw-adapter side:
- minimal required version of Node is v18
- some exported types were renamed and extended to match msw behaviour
- `MswMatch` is now `MatchedRequest` and is `{ request: Request; requestId: string; response: Response }`
- `ExpiredRequest` still called the same and is `{ request: Request; requestId: string; startTime: number; duration?: number }`
- added `PendingRequest` as `{ request: Request; requestId: string; }`
- `PactMswAdapterOptions.providers` function variant is now consistent with msw and has signature `(event: PendingRequest) => string | null`
- `PactMswAdapter.emitter` events are slightly updated to match msw behaviour
- `pact-msw-adapter:expired` handler must have signature `(event: ExpiredRequest) => void`
- `pact-msw-adapter:match` handler must have signature `(event: MatchedRequest) => void`
- `convertMswMatchToPact` is now async function

## Contributors

Background:
Expand Down
Loading
Loading