{"id":22772337,"url":"https://github.com/pactflow/example-bi-directional-consumer-nock","last_synced_at":"2025-09-14T14:57:39.984Z","repository":{"id":66228848,"uuid":"478203049","full_name":"pactflow/example-bi-directional-consumer-nock","owner":"pactflow","description":"Bi-Directional Contract Testing example consumer using a BYO testing tool (Nock) to generate Pact consumer contracts","archived":false,"fork":false,"pushed_at":"2025-09-08T01:00:50.000Z","size":5767,"stargazers_count":2,"open_issues_count":2,"forks_count":10,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-09-08T02:34:22.942Z","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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-04-05T16:01:48.000Z","updated_at":"2025-09-08T00:41:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"1e38c2d1-6368-4008-b4e3-29cb01702fc4","html_url":"https://github.com/pactflow/example-bi-directional-consumer-nock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pactflow/example-bi-directional-consumer-nock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-bi-directional-consumer-nock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-bi-directional-consumer-nock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-bi-directional-consumer-nock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-bi-directional-consumer-nock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pactflow","download_url":"https://codeload.github.com/pactflow/example-bi-directional-consumer-nock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fexample-bi-directional-consumer-nock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275121412,"owners_count":25409030,"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","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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:11.095Z","updated_at":"2025-09-14T14:57:39.962Z","avatar_url":"https://github.com/pactflow.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Example NodeJS/React Consumer - Nock (BYO Adapter)\n\n\u003c!-- Build Badge --\u003e\n\n![Build](https://github.com/pactflow/example-bi-directional-consumer-nock/workflows/Build/badge.svg)\n\n\u003c!-- Can I Deploy Badge --\u003e\n\n[![Can I deploy Status](https://testdemo.pactflow.io/pacticipants/pactflow-example-bi-directional-consumer-nock/branches/master/latest-version/can-i-deploy/to-environment/production/badge)](https://testdemo.pactflow.io/pacticipants/pactflow-example-bi-directional-consumer-nock/branches/master/latest-version/can-i-deploy/to-environment/production/badge)\n\n- [Example NodeJS/React Consumer - Nock (BYO Adapter)](#example-nodejsreact-consumer---nock-byo-adapter)\n  - [Overview of Example](#overview-of-example)\n  - [Overview of Part of Bi-Directional Contract Testing Flow](#overview-of-part-of-bi-directional-contract-testing-flow)\n  - [Compatibile with Providers](#compatibile-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    - [Windows](#windows)\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 NodeJS/React \"Product\" API consumer that uses Nock, Pact, [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\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 master)\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## Compatibile with Providers\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\u003c!-- * [pactflow-example-bi-directional-provider-postman](https://github.com/pactflow/example-bi-directional-provider-postman) --\u003e\n\nSee [Environment variables](#environment-variables) on how to set these up.\n  \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 an 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\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\u003c!-- - `PACT_PROVIDER=pactflow-example-bi-directional-provider-postman`: Postman - (https://github.com/pactflow/example-bi-directional-provider-postman) --\u003e\n- `PACT_PROVIDER=pactflow-example-bi-directional-provider-restassured`:  Rest Assured - (https://github.com/pactflow/example-bi-directional-provider-restassured)\n\n\n## Usage\n\n### Steps\n\nNOTE: The nock recordings are already in the project, in the `./fixtures` directory, see below for how to obtain these recordings.\n\n* `make clean` - ensure previous pacts are cleared\n* `make test` - run the nock test locally\n* `make fake_ci` - run the nock version of the CI process locally\n\n*Re-record nock fixtures*\n\nYou first need to start up the provider API in order to obtain nock recordings. The API must be running on `http://localhost:3001` for this step to work.\n\nFor the default [Provider](https://github.com/pactflow/example-provider-dredd) designed for this workshop, you can simply start it up by running `npm start` in the root directory of the provider project, as per its README.\n\n* `npm run test:record` - this will run nock in record mode, and your api client will issue real requests to the API \n* `npm run test:nock` - run the nock tests in replay only mode, validating all stubs were used in the process, and writing a pact file if successful\n  \n## OS/Platform specific considerations\n\nThe makefile is configured to run on Unix based systems such as you would find in most common CI/CD pipelines. \n\nThey can be run locally on Unix/Mac, or on Windows via [WSL2](https://docs.microsoft.com/en-us/windows/wsl/install). \n\n### Windows \n\nYou can still try this example locally on Windows using powershell and running commands manually. \n\nThese will be the same commands that are used in the makefile with a few manual tweaks.\n\n\u003cdetails\u003e\n  \u003csummary\u003eClick to see windows specific instructions here\u003c/summary\u003e\n  \n\n1. Make sure you have set all of the environment variables, in powershell they can be set like so.\n\n    ```\n     $env:GIT_BRANCH=\"main\"\n    ```\n\n  1. Publish the pact that was generated. The step uses the pact-cli docker image to publish the pact to your pactflow account.\n  The path for `\u003cpath_to_project_root\u003e` needs to be converted from Windows paths to UNIX ones as the Docker container is using UNIX. Either hard code this or set it as another environment variable.\n\n      `C:\\Users\\Person\\Documents\\example-bi-directional-consumer-dotnet` \n      \n      becomes\n      \n      `/c/Users/Candy/Documents/PactFlow/example-bi-directional-consumer-dotnet`\n\n      $env:VARIABLE_NAME refers to the environment variables in windows.\n\n      ```\n      docker run --rm -v \u003cpath_to_project_root\u003e:\u003cpath_to_project_root\u003e -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli publish \u003cpath_to_pacts_folder\u003e --consumer-app-version $env:GIT_COMMIT --branch $env:GIT_BRANCH\n\n      ```\n\n  4. Check can-i-deploy to see if your provider is compatible with your pact.\n\n      ```\n      docker run --rm -v \u003cpath_to_project_root\u003e:\u003cpath_to_project_root\u003e -e PACT_BROKER_BASE_URL -e PACT_BROKER_TOKEN pactfoundation/pact-cli  broker can-i-deploy --pacticipant pactflow-example-bi-directional-consumer-dotnet --version $env:GIT_COMMIT --to-environment production  --retry-while-unknown 0 --retry-interval 10\n      ```\n\n5. Have a look at what other commands are available in the Makefile. All of them can be ran locally from Powershell by changing the windows paths to UNIX and replacing the environment variable references. Any variable referenced as `${VARIABLE}` can be changed to `$env:VARIABLE` to reference environment variables in Powershell.\n\n\n\u003c/details\u003e\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-nock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpactflow%2Fexample-bi-directional-consumer-nock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpactflow%2Fexample-bi-directional-consumer-nock/lists"}