{"id":22772299,"url":"https://github.com/pactflow/pact-cypress-adapter","last_synced_at":"2025-04-15T06:47:59.113Z","repository":{"id":40256878,"uuid":"463314086","full_name":"pactflow/pact-cypress-adapter","owner":"pactflow","description":"Cypress Pact Plugin","archived":false,"fork":false,"pushed_at":"2025-04-15T00:38:28.000Z","size":1264,"stargazers_count":27,"open_issues_count":19,"forks_count":14,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-15T06:47:54.017Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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":"CHANGELOG.md","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}},"created_at":"2022-02-24T21:58:19.000Z","updated_at":"2025-04-14T05:45:38.000Z","dependencies_parsed_at":"2025-04-05T14:22:54.815Z","dependency_job_id":"4b96d04b-9844-4608-81b6-e131f9b813ac","html_url":"https://github.com/pactflow/pact-cypress-adapter","commit_stats":null,"previous_names":["pactflow/cypress-pact-adapter"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fpact-cypress-adapter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fpact-cypress-adapter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fpact-cypress-adapter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pactflow%2Fpact-cypress-adapter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pactflow","download_url":"https://codeload.github.com/pactflow/pact-cypress-adapter/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":[],"created_at":"2024-12-11T17:08:01.672Z","updated_at":"2025-04-15T06:47:59.084Z","avatar_url":"https://github.com/pactflow.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pact Cypress Adapter\n[![Build and test](https://github.com/pactflow/cypress-pact-adapter/actions/workflows/test-and-build.yaml/badge.svg)](https://github.com/pactflow/cypress-pact-adapter/actions/workflows/test-and-build.yaml) [![npm version](https://badge.fury.io/js/@pactflow%2Fpact-cypress-adapter.svg)](https://badge.fury.io/js/@pactflow%2Fpact-cypress-adapter)\n\nGenerate Pact contracts from your existing Cypress tests. \n\n\u003e Accelerate your entry into contract testing with the Cypress development experience you know and love. — With Pact Cypress Adapter you can get the extra layer of testing safety, easily using existing mocks you’ve created with Cypress. \n\u003e\n\u003e Read our [blog post](https://pactflow.io/blog/use-cypress-in-contract-testing/) to find out more, otherwise dive-right in.\n\n## Installation\n**NPM**:\n```bash\nnpm i -D @pactflow/pact-cypress-adapter\n```\n\n**yarn**:\n```bash\nyarn add -D @pactflow/pact-cypress-adapter\n```\n\n## Setup for Cypress 10\nSetup your cypress plugin at `cypress/plugins/index.js`\n\n```js\nconst pactCypressPlugin = require('@pactflow/pact-cypress-adapter/dist/plugin')\nconst fs = require('fs')\n\nmodule.exports = (on, config) =\u003e {\n  pactCypressPlugin(on, config, fs)\n}\n```\n\nFinally, update `cypress/support/e2e.js` file to include cypress-pact commands via adding:\n```js\nimport '@pactflow/pact-cypress-adapter'\n```\n\n## Setup for Cypress 9.x and below\nSetup your cypress plugin at `cypress/plugins/index.js`\n\n```js\nconst pactCypressPlugin = require('@pactflow/pact-cypress-adapter/dist/plugin')\nconst fs = require('fs')\n\nmodule.exports = (on, config) =\u003e {\n  pactCypressPlugin(on, config, fs)\n}\n```\n\nFinally, update `cypress/support/index.js` file to include cypress-pact commands via adding:\n```js\nimport '@pactflow/pact-cypress-adapter'\n```\n\n## Configuration\nBy default, this plugin omits most cypress auto-generated HTTP headers. \n\n### Add more headers to blocklist for Cypress 10\nTo exclude other headers in your pact, add them as a list of strings in `cypress.config.{js,ts,mjs,cjs}` under key `env.headersBlocklist`. Eg. in your cypress config file\n```js\n{\n    ...otherCypressConfig,\n    \"env\": {\n        \"headersBlocklist\": [\"ignore-me-globally\"]\n    }\n}\n```\n\n### Add more headers to blocklist for Cypress 9.x and below\nTo exclude other headers in your pact, add them as a list of strings in `cypress.json` under key `env.headersBlocklist`. Eg. in your `cypress.json`\n```js\n{\n    ...otherCypressConfig,\n    \"env\": {\n        \"headersBlocklist\": [\"ignore-me-globally\"]\n    }\n}\n```\n\nNote: Header blocklist can be set up at test level. Check command [cy.setupPactHeaderBlocklist](/#cy.setupPactHeaderBlocklist([headers]))\n\n### Ignore cypress auto-generated header blocklist\nTo stop cypress auto-generated HTTP headers being omitted by the plugin,  set `env.ignoreDefaultBlocklist` in your `cypress.json`. Eg. in your `cypress.json`\n```js\n{\n    ...otherCypressConfig,\n    \"env\": {\n        \"headersBlocklist\": [\"ignore-me-globally\"],\n        \"ignoreDefaultBlocklist\": true\n\n    }\n}\n```\n\n## Commands \n### cy.setupPact(consumerName:string, providerName: string)\nConfigure your consumer and provider name\n\n**Example**\n```js\nbefore(() =\u003e {\n    cy.setupPact('ui-consumer', 'api-provider')\n})\n```\n### cy.usePactWait([alias] | alias)\nListen to aliased `cy.intercept` network call(s), record network request and response to a pact file.\n[Usage and example](https://docs.cypress.io/api/commands/intercept) about `cy.intercept`\n\n**Example**\n```js\nbefore(() =\u003e {\n    cy.setupPact('ui-consumer', 'api-provider')\n    cy.intercept('GET', '/users').as('getAllUsers')\n})\n\n//... cypress test\n\nafter(() =\u003e {\n    cy.usePactWait(['getAllUsers'])\n})\n\n```\n\n### cy.setupPactHeaderBlocklist([headers])\nAdd a list of headers that will be excluded in a pact at test case level\n\n**Example**\n```js\nbefore(() =\u003e {\n    cy.setupPact('ui-consumer', 'api-provider')\n    cy.intercept('GET', '/users', headers: {'ignore-me': 'ignore me please'}).as('getAllUsers')\n    cy.setupPactHeaderBlocklist(['ignore-me'])\n})\n\n//... cypress test\n\nafter(() =\u003e {\n    cy.usePactWait(['getAllUsers'])\n})\n```\n\n### cy.usePactRequest(option, alias) and cy.usePactGet([alias] | alias)\nUse `cy.usePactRequest` to initiate network calls and use `cy.usePactGet` to record network request and response to a pact file.\n\nConvenience wrapper for `cy.request(options).as(alias)` \n\n- Accepts a valid Cypress request options argument [Cypress request options argument](https://docs.cypress.io/api/commands/request#Arguments) \n\n**Example**\n```js\n\nbefore(() =\u003e {\n    cy.setupPact('ui-consumer', 'api-provider')\n    cy.usePactRequest(\n      {\n        method: 'GET',\n        url: '/users',\n      },\n      'getAllUsers'\n    )\n})\n\n//... cypress test\n\nafter(() =\u003e {\n    cy.usePactGet(['getAllUsers'])\n})\n\n```\n\n## Example Project\nCheck out simple react app example projects at [/example/todo-example](/example/todo-example/). Example contains examples for Cypress 10.x and Cypress 9.x.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpactflow%2Fpact-cypress-adapter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpactflow%2Fpact-cypress-adapter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpactflow%2Fpact-cypress-adapter/lists"}