Skip to content

Commit 874cb20

Browse files
committed
feat: add init playwright adapter js
1 parent 28669a4 commit 874cb20

24 files changed

+480
-2246
lines changed

.eslintrc.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@
99
"es6": true,
1010
"jest": true
1111
},
12-
"extends": [
13-
"eslint:recommended",
14-
"plugin:react/recommended",
15-
"plugin:cypress/recommended"
16-
],
12+
"extends": ["eslint:recommended", "plugin:react/recommended"],
1713
"globals": {
1814
"Atomics": "readonly",
1915
"SharedArrayBuffer": "readonly",
@@ -27,10 +23,6 @@
2723
"ecmaVersion": 2018,
2824
"sourceType": "module"
2925
},
30-
"plugins": [
31-
"react",
32-
"cypress"
33-
],
34-
"rules": {
35-
}
36-
}
26+
"plugins": ["react", "playwright"],
27+
"rules": {}
28+
}

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ env:
1111
VERSION: ${{ github.sha }}
1212
GIT_REF: ${{ github.ref }}
1313
PACT_PROVIDER: pactflow-example-bi-directional-provider-postman
14-
PACTICIPANT: pactflow-example-bi-directional-consumer-cypress
14+
PACTICIPANT: pactflow-example-bi-directional-consumer-playwright
1515

1616
jobs:
1717
test:

.github/workflows/playwright.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Playwright Tests
2+
on:
3+
push:
4+
branches: [ main, master ]
5+
pull_request:
6+
branches: [ main, master ]
7+
jobs:
8+
test:
9+
timeout-minutes: 60
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v2
14+
with:
15+
node-version: '14.x'
16+
- name: Install dependencies
17+
run: npm ci
18+
- name: Install Playwright Browsers
19+
run: npx playwright install --with-deps
20+
- name: Run Playwright tests
21+
run: npx playwright test
22+
- uses: actions/upload-artifact@v2
23+
if: always()
24+
with:
25+
name: playwright-report
26+
path: playwright-report/
27+
retention-days: 30

.github/workflows/test_pact_cli_tools_cross_os.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
env:
6767
PACT_TOOL: ${{ matrix.pact_tool }}
6868
BRANCH: ${{ needs.setup.outputs.BRANCH }}
69-
PACTICIPANT: "pactflow-example-bi-directional-consumer-cypress-${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.pact_tool }}"
69+
PACTICIPANT: "pactflow-example-bi-directional-consumer-playwright-${{ matrix.os }}-${{ matrix.node-version }}-${{ matrix.pact_tool }}"
7070
PACT_PROVIDER: ${{ matrix.pact_provider }}
7171
PACT_CLI_VERSION: ${{ needs.setup.outputs.PACT_CLI_VERSION}}
7272
PACT_TOOL_USER_CHOICE: ${{ needs.setup.outputs.PACT_TOOL }}

.github/workflows/trigger_docs_update.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ jobs:
1616
curl -X POST https://api.github.com/repos/pactflow/partners.pactflow.io/dispatches \
1717
-H 'Accept: application/vnd.github.everest-preview+json' \
1818
-H "Authorization: Bearer $GITHUB_TOKEN" \
19-
-d '{"event_type": "pactflow-example-bi-directional-consumer-cypress-updated"}'
19+
-d '{"event_type": "pactflow-example-bi-directional-consumer-playwright-updated"}'
2020
env:
2121
GITHUB_TOKEN: ${{ secrets.GHTOKENFORTRIGGERINGPACTDOCSUPDATE }}
2222
- name: Trigger docs.pactflow.io update workflow
2323
run: |
2424
curl -X POST https://api.github.com/repos/pactflow/docs.pactflow.io/dispatches \
2525
-H 'Accept: application/vnd.github.everest-preview+json' \
2626
-H "Authorization: Bearer $GITHUB_TOKEN" \
27-
-d '{"event_type": "pactflow-example-bi-directional-consumer-cypress-updated"}'
27+
-d '{"event_type": "pactflow-example-bi-directional-consumer-playwright-updated"}'
2828
env:
2929
GITHUB_TOKEN: ${{ secrets.GHTOKENFORTRIGGERINGPACTDOCSUPDATE }}

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ yarn-error.log*
3131
pacts/
3232
logs/
3333

34-
# cypress
35-
videos/
36-
screenshots/
34+
# playwright
35+
/test-results/
36+
/playwright-report/
37+
/playwright/.cache/

Makefile

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,25 @@
55
# Default to the read only token - the read/write token will be present on Travis CI.
66
# It's set as a secure environment variable in the .travis.yml file
77
GITHUB_ORG="pactflow"
8-
PACTICIPANT ?= "pactflow-example-bi-directional-consumer-cypress"
8+
PACTICIPANT ?= "pactflow-example-bi-directional-consumer-playwright"
99
GITHUB_WEBHOOK_UUID := "04510dc1-7f0a-4ed2-997d-114bfa86f8ad"
1010
PACT_CHANGED_WEBHOOK_UUID := "8e49caaa-0498-4cc1-9368-325de0812c8a"
1111
VERSION?=$(shell npx -y absolute-version)
1212
BRANCH?=$(shell git rev-parse --abbrev-ref HEAD)
1313

14+
15+
# Only deploy from main/master
16+
ifneq ($(filter $(BRANCH),main master),)
17+
DEPLOY_TARGET=deploy
18+
else
19+
DEPLOY_TARGET=no_deploy
20+
endif
21+
1422
## ====================
1523
## Demo Specific Example Variables
1624
## ====================
1725
REACT_APP_API_BASE_URL=http://localhost:3001
18-
PACT_FILES_LOCATION=cypress/pacts
26+
PACT_FILES_LOCATION=pacts
1927

2028
## ====================
2129
## CI tasks
@@ -29,7 +37,7 @@ all_ruby_cli: ci_ruby_cli
2937
# Run the ci target from a developer machine with the environment variables
3038
# set as if it was on Github Actions.
3139
# Use this for quick feedback when playing around with your workflows.
32-
ci: test test_and_publish can_i_deploy $(DEPLOY_TARGET)
40+
ci: test_and_publish can_i_deploy $(DEPLOY_TARGET)
3341

3442
# Run the ci target from a developer machine with the environment variables
3543
# set as if it was on CI.
@@ -41,7 +49,7 @@ fake_ci: .env
4149
test_and_publish: test publish_pacts
4250

4351
publish_pacts: .env
44-
@echo "\n========== STAGE: publish_pacts generated with cypress ==========\n"
52+
@echo "\n========== STAGE: publish_pacts generated with playwright ==========\n"
4553
@${PACT_BROKER_COMMAND} publish ${PACT_FILES_LOCATION} --consumer-app-version ${VERSION} --branch ${BRANCH}
4654

4755
## =====================
@@ -51,26 +59,20 @@ publish_pacts: .env
5159
install: npm install
5260

5361
test: .env
54-
@echo "\n========== STAGE: test ✅ (cypress) ==========\n"
62+
@echo "\n========== STAGE: test ✅ (playwright) ==========\n"
5563
npm run start:ui:and:test
5664

5765
## =====================
5866
## Deploy tasks
5967
## =====================
6068

61-
# Only deploy from main/master
62-
ifneq ($(filter $(BRANCH),main master),)
63-
DEPLOY_TARGET=deploy
64-
else
65-
DEPLOY_TARGET=no_deploy
66-
endif
6769

6870
create_environment:
6971
@"${PACT_BROKER_COMMAND}" create-environment --name production --production
7072

7173
deploy: deploy_app record_deployment
7274

73-
deploy_target: can_i_deploy $(DEPLOY_TARGET)
75+
deploy_target: $(DEPLOY_TARGET)
7476

7577
no_deploy:
7678
@echo "Not deploying as not on main branch"
@@ -204,4 +206,6 @@ install-pact-ruby-standalone:
204206
./pact/bin/pact-mock-service --help && \
205207
./pact/bin/pact-provider-verifier --help && \
206208
./pact/bin/pactflow help;; \
207-
esac
209+
esac
210+
211+
.PHONY: test

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# Example NodeJS/React Consumer - Cypress (BYO Adapter)
1+
# Example NodeJS/React Consumer - playwright (BYO Adapter)
22

3-
[![Build](https://github.com/pactflow/example-bi-directional-consumer-cypress/actions/workflows/build.yml/badge.svg)](https://github.com/pactflow/example-bi-directional-consumer-cypress/actions/workflows/build.yml)
3+
[![Build](https://github.com/pactflow/example-bi-directional-consumer-playwright/actions/workflows/build.yml/badge.svg)](https://github.com/pactflow/example-bi-directional-consumer-playwright/actions/workflows/build.yml)
44

5-
[![Can I deploy Status](https://testdemo.pactflow.io/pacticipants/pactflow-example-bi-directional-consumer-cypress/branches/main/latest-version/can-i-deploy/to-environment/production/badge)](https://testdemo.pactflow.io/pacticipants/pactflow-example-bi-directional-consumer-cypress/branches/main/latest-version/can-i-deploy/to-environment/production/badge)
5+
[![Can I deploy Status](https://testdemo.pactflow.io/pacticipants/pactflow-example-bi-directional-consumer-playwright/branches/main/latest-version/can-i-deploy/to-environment/production/badge)](https://testdemo.pactflow.io/pacticipants/pactflow-example-bi-directional-consumer-playwright/branches/main/latest-version/can-i-deploy/to-environment/production/badge)
66

7-
- [Example NodeJS/React Consumer - Cypress (BYO Adapter)](#example-nodejsreact-consumer---cypress-byo-adapter)
7+
- [Example NodeJS/React Consumer - playwright (BYO Adapter)](#example-nodejsreact-consumer---playwright-byo-adapter)
88
- [Overview of Example](#overview-of-example)
9-
- [Key points with Cypress](#key-points-with-cypress)
9+
- [Key points with playwright](#key-points-with-playwright)
1010
- [Overview of Part of Bi-Directional Contract Testing Flow](#overview-of-part-of-bi-directional-contract-testing-flow)
1111
- [Compatibile with Providers](#compatibile-with-providers)
1212
- [Pre-requisites](#pre-requisites)
@@ -23,21 +23,21 @@
2323

2424
<!-- Consumer Overview -->
2525

26-
This is an example of a React "Product" API consumer that uses Cypress, [pact-cypress-adapter](https://www.npmjs.com/package/@pactflow/pact-cypress-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, [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.
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

3030
<!-- General -->
3131

3232
See the full [Pactflow Bi-Directional Workshop](https://docs.pactflow.io/docs/workshops/bi-directional-contract-testing) for which this can be substituted in as the "consumer".
3333

34-
### Key points with Cypress
34+
### Key points with playwright
3535

3636
It:
3737

3838
- It a React app implementing a "Product" website created with Create React App
39-
- It utilises Cypress to functionally test the website
40-
- It utilises [pact-cypress-adapter](https://www.npmjs.com/package/@pactflow/pact-cypress-adapter) to transform cypress mocks into Pact consumer contracts.
39+
- 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.
4141

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

@@ -102,7 +102,7 @@ Set `PACT_PROVIDER` to one of the following
102102

103103
### Steps
104104

105-
NOTE: Cypress tests are located in `./cypress/integration`. See below for how to start cypress test, generate consumer contract and publish contract to pactflow.
105+
NOTE: playwright tests are located in `./playwright/integration`. See below for how to start playwright test, generate consumer contract and publish contract to pactflow.
106106

107107
- `make install` - install project dependencies
108108

@@ -133,13 +133,13 @@ Using alternate pact CLI tools.
133133
- `PACT_TOOL=ruby_standalone make ci` - run the CI process, using the pact standalone CLI tool
134134
- `PACT_TOOL=ruby_cli make ci` - run the CI process, using the pact ruby CLI tool
135135

136-
_How to use Cypress_
136+
\_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 `cypress.json` as cypress environment variables
139+
- Define your pact provider and consumer name at `playwright.json` as playwright environment variables
140140
- 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 cypress:headless:chrome` - this will run cypress e2e test in headless mode, and write stubbed network calls a pact file
142-
- `npm run cypress:run` - this will run cypress e2e test with browser ui
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
143143

144144
## OS/Platform specific considerations
145145

cypress.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

cypress/integration/product.spec.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)