Skip to content

Commit bb8e1fd

Browse files
committed
chore (docs): update usage instructions
1 parent c811e90 commit bb8e1fd

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

README.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
<!-- Consumer Overview -->
2525

26-
This is an example of a React "Product" API consumer that uses playwright, [pact-playwright-adapter](https://www.npmjs.com/package/@pactflow/pact-playwright-adapter), [Pactflow](https://pactflow.io) and GitHub Actions to generate and publish Pact consumer contracts.
26+
This is an example of a React "Product" API consumer that uses playwright & [Pactflow](https://pactflow.io) and GitHub Actions to generate and publish Pact consumer contracts.
2727

2828
It performs pre-deployment cross-compatibility checks to ensure that it is compatible with specified providers using the Bi-Directional contract capability of Pactflow.
2929

@@ -37,7 +37,7 @@ It:
3737

3838
- It a React app implementing a "Product" website created with Create React App
3939
- It utilises playwright to functionally test the website
40-
- It utilises [pact-playwright-adapter](https://www.npmjs.com/package/@pactflow/pact-playwright-adapter) to transform playwright mocks into Pact consumer contracts.
40+
- It utilises a small helper file to cover playwright routes into pact interactions
4141

4242
## Overview of Part of Bi-Directional Contract Testing Flow
4343

@@ -136,10 +136,31 @@ Using alternate pact CLI tools.
136136
\_How to use Playwright
137137

138138
- Spin up the ui project by running `npm run start`
139-
- Define your pact provider and consumer name at `playwright.json` as playwright environment variables
140-
- You can stub your network request and response with `cy.intercept`, and record network call to a consumer driven contract with `cy.usePactWait`. Each request you want to add to the contract must call this method.
141-
- `npm run playwright:headless:chrome` - this will run playwright e2e test in headless mode, and write stubbed network calls a pact file
142-
- `npm run playwright:run` - this will run playwright e2e test with browser ui
139+
- Run your playwright tests with `npm run test`
140+
141+
Look at one of the tests `test/productByQuery.spec.js`
142+
143+
1. Import `transformPlaywrightMatchToPact` from `test/playwrightSerialiser.js`
144+
2. add `transformPlaywrightMatchToPact` function call into your playwright [route](https://playwright.dev/docs/api/class-page#page-route)
145+
146+
```js
147+
const { transformPlaywrightMatchToPact } = require('./playwrightSerialiser')
148+
149+
await page.route(productApiPath + '/products?id=2', async (route) => {
150+
const response = {
151+
status: 200,
152+
body: JSON.stringify(testData),
153+
headers: {
154+
'Content-Type': 'application/json'
155+
}
156+
}
157+
route.fulfill(response)
158+
const pacticipant = 'pactflow-example-bi-directional-consumer-playwright'
159+
const provider = process.env.PACT_PROVIDER || 'pactflow-example-bi-directional-provider-dredd'
160+
await transformPlaywrightMatchToPact(route, { pacticipant, provider })
161+
return
162+
})
163+
```
143164

144165
## OS/Platform specific considerations
145166

package-lock.json

Lines changed: 14 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)