{"id":22772318,"url":"https://github.com/pactflow/example-bi-directional-consumer-cypress","last_synced_at":"2025-10-06T02:50:31.871Z","repository":{"id":38185960,"uuid":"462084507","full_name":"pactflow/example-bi-directional-consumer-cypress","owner":"pactflow","description":"Cypress bi-directional contract testing example project","archived":false,"fork":false,"pushed_at":"2025-04-14T19:12:58.000Z","size":6022,"stargazers_count":8,"open_issues_count":2,"forks_count":26,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-15T06:48:11.113Z","etag":null,"topics":["example"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pactflow.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-22T00:55:17.000Z","updated_at":"2025-04-14T19:12:21.000Z","dependencies_parsed_at":"2024-03-13T19:23:58.785Z","dependency_job_id":"fe7cbc0b-1059-4fd3-bba6-f220403df5da","html_url":"https://github.com/pactflow/example-bi-directional-consumer-cypress","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-bi-directional-consumer-cypress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-bi-directional-consumer-cypress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-bi-directional-consumer-cypress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-bi-directional-consumer-cypress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pactflow","download_url":"https://codeload.github.com/pactflow/example-bi-directional-consumer-cypress/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249023707,"owners_count":21199958,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example"],"created_at":"2024-12-11T17:08:04.242Z","updated_at":"2025-10-06T02:50:31.791Z","avatar_url":"https://github.com/pactflow.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Example NodeJS/React Consumer - Cypress (BYO Adapter)\n\n[![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)\n\n[![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)\n\n- [Example NodeJS/React Consumer - Cypress (BYO Adapter)](#example-nodejsreact-consumer---cypress-byo-adapter)\n  - [Overview of Example](#overview-of-example)\n    - [Key points with Cypress](#key-points-with-cypress)\n  - [Overview of Part of Bi-Directional Contract Testing Flow](#overview-of-part-of-bi-directional-contract-testing-flow)\n  - [Compatible with Providers](#compatible-with-providers)\n  - [Pre-requisites](#pre-requisites)\n    - [Environment variables](#environment-variables)\n  - [Usage](#usage)\n    - [Steps](#steps)\n  - [OS/Platform specific considerations](#osplatform-specific-considerations)\n  - [Caveats](#caveats)\n  - [Related topics / posts / discussions](#related-topics--posts--discussions)\n  - [Other examples of how to do this form of testing](#other-examples-of-how-to-do-this-form-of-testing)\n  - [Found an issue?](#found-an-issue)\n\n## Overview of Example\n\n\u003c!-- Consumer Overview --\u003e\n\nThis 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.\n\nIt performs pre-deployment cross-compatibility checks to ensure that it is compatible with specified providers using the Bi-Directional contract capability of PactFlow.\n\n\u003c!-- General --\u003e\n\nSee 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\".\n\n### Key points with Cypress\n\nIt:\n\n- It is a React app implementing a \"Product\" website created with Create React App\n- It utilises Cypress to functionally test the website\n- It utilises [pact-cypress-adapter](https://www.npmjs.com/package/@pactflow/pact-cypress-adapter) to transform cypress mocks into Pact consumer contracts.\n\n## Overview of Part of Bi-Directional Contract Testing Flow\n\n\u003c!-- Consumer Overview --\u003e\n\nIn the following diagram, You can see how the consumer testing process works - it's the same as the current Pact process.\n\nWhen we call \"can-i-deploy\" the cross-contract validation process kicks off on PactFlow, to ensure any consumer consumes a valid subset of the OAS for the provider.\n\n![Consumer Test](docs/consumer-scope.png 'Consumer Test')\n\nThe project uses a Makefile to simulate a very simple build pipeline with two stages - test and deploy.\n\nWhen you run the CI pipeline (see below for doing this), the pipeline should perform the following activities (simplified):\n\n- Test\n  - Run tests (including the pact tests that generate the contract)\n  - Publish pacts, tagging the consumer version with the name of the current branch\n  - Check if we are safe to deploy to Production with `can-i-deploy` (ie. has the cross-contract validation has been successfully performed)\n- Deploy (only from \u003cmain|master\u003e)\n  - Deploy app to Production\n  - Record the Production deployment in the Pact Broker\n\n![Consumer Pipeline](docs./../docs/consumer-pipeline.png 'Consumer Pipeline')\n\n## Compatible with Providers\n\n\u003c!-- Provider Compatability --\u003e\n\nThis project is currently compatible with the following provider(s):\n\n- [pactflow-example-bi-directional-provider-dredd](https://github.com/pactflow/example-bi-directional-provider-dredd)\n- [pactflow-example-bi-directional-provider-restassured](https://github.com/pactflow/example-provider-restassured)\n- [pactflow-example-bi-directional-provider-postman](https://github.com/pactflow/example-bi-directional-provider-postman)\n\u003c!-- * [pactflow-example-bi-directional-provider-dotnet](https://github.com/pactflow/example-bi-directional-provider-dotnet) --\u003e\n\nSee [Environment variables](#environment-variables) on how to set these up.\n\n## Pre-requisites\n\n**Software**:\n\n- Tools listed at: https://docs.pactflow.io/docs/workshops/ci-cd/set-up-ci/prerequisites/\n- A pactflow.io account with a valid [API token](https://docs.pactflow.io/docs/getting-started/#configuring-your-api-token)\n\n### Environment variables\n\nTo be able to run some of the commands locally, you will need to export the following environment variables into your shell:\n\n- `PACT_BROKER_TOKEN`: a valid [API token](https://docs.pactflow.io/docs/getting-started/#configuring-your-api-token) for PactFlow\n- `PACT_BROKER_BASE_URL`: a fully qualified domain name with protocol to your pact broker e.g. https://testdemo.pactflow.io\n\n\u003c!-- CONSUMER env vars --\u003e\n\nSet `PACT_PROVIDER` to one of the following\n\n- `PACT_PROVIDER=pactflow-example-bi-directional-provider-dredd`: Dredd - (https://github.com/pactflow/example-bi-directional-provider-dredd)\n- `PACT_PROVIDER=pactflow-example-bi-directional-provider-postman`: Postman - (https://github.com/pactflow/example-bi-directional-provider-postman)\n- `PACT_PROVIDER=pactflow-example-bi-directional-provider-restassured`: Rest Assured - (https://github.com/pactflow/example-bi-directional-provider-restassured)\n\n## Usage\n\n### Steps\n\nNOTE: Cypress tests are located in `./cypress/e2e`. See below for how to start cypress test, generate a consumer contract, and publish the contract to pactflow.\n\n- `make install` - install project dependencies\n\nRun each step separately\n\n- `make test_and_publish` - tests the consumer and publishes pact contracts to PactFlow\n  - This will perform the following 2 calls\n    - `make test`\n    - `make publish_pacts`\n- `make can_i_deploy` - runs can-i-deploy to check if its safe to deploy the consumer\n- `make deploy` - deploys the app and records deployment\n\nor run the whole lot in one go\n\n- `make ci` - run the CI process, but locally (uses Docker by default)\n\nInstalling alternate pact CLI tools.\n\nIf you don't have docker, you can use one of the ruby tools. The standalone doesn't require that you install Ruby on your host machine.\n\n- `make install-pact-ruby-cli` - installs the pact ruby CLI tool\n- `make install-pact-ruby-standalone` - installs the pact standalone CLI depending on your platform\n- `make uninstall-pact-ruby-standalone` - uninstalls the pact standalone CLI\n\nUsing alternate pact CLI tools.\n\n- `PACT_TOOL=docker make ci` - run the CI process, using the pact Docker CLI tool\n- `PACT_TOOL=ruby_standalone make ci` - run the CI process, using the pact standalone CLI tool\n- `PACT_TOOL=ruby_cli make ci` - run the CI process, using the pact ruby CLI tool\n\n_How to use Cypress_\n\n- Spin up the ui project by running `npm run start`\n- Define your pact provider and consumer name at `cypress.config.cjs` as cypress environment variables\n- 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.\n- `npm run cypress:headless:chrome` - this will run cypress e2e test in headless mode, and write stubbed network calls a pact file\n- `npm run cypress:run` - this will run cypress e2e test with browser ui\n\n## OS/Platform specific considerations\n\nThe Makefile has been configured to run on Unix/Windows and MacOS-based systems, and tested against GitHub Actions\n\nThey can be run locally on Unix/Windows and MacOS, or on Windows via [WSL2](https://docs.microsoft.com/en-us/windows/wsl/install) or a shell with bash.\n\n## Caveats\n\n- [OAS considerations](https://docs.pactflow.io/docs/bi-directional-contract-testing/contracts/oas#considerations)\n\n## Related topics / posts / discussions\n\n- [Consumer Side Bi-Directional Contract Testing Guide](https://docs.pactflow.io/docs/bi-directional-contract-testing/consumer)\n- [Provider Side Bi-Directional Contract Testing Guide](https://docs.pactflow.io/docs/bi-directional-contract-testing/provider)\n\n## Other examples of how to do this form of testing\n\n- TBC\n\n## Found an issue?\n\nReach out via a GitHub Issue, or reach us over in the [Pact Foundation Slack](https://slack.pact.io)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpactflow%2Fexample-bi-directional-consumer-cypress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpactflow%2Fexample-bi-directional-consumer-cypress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpactflow%2Fexample-bi-directional-consumer-cypress/lists"}