{"id":16720937,"url":"https://github.com/yoavniran/cypress-intercept-formdata","last_synced_at":"2025-03-21T21:30:41.979Z","repository":{"id":38418878,"uuid":"341979210","full_name":"yoavniran/cypress-intercept-formdata","owner":"yoavniran","description":"cypress.io command to work with Intercept multipart/form-data requests","archived":false,"fork":false,"pushed_at":"2023-10-02T11:03:48.000Z","size":2100,"stargazers_count":10,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T05:11:54.273Z","etag":null,"topics":["ci-cd","cypress","cypress-io","form-data","intercept"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/cypress-intercept-formdata","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/yoavniran.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":["yoavniran"]}},"created_at":"2021-02-24T17:26:49.000Z","updated_at":"2024-11-01T04:28:42.000Z","dependencies_parsed_at":"2024-06-19T05:31:21.104Z","dependency_job_id":"b82589d8-3797-46c8-a2b0-2259d83d1e1f","html_url":"https://github.com/yoavniran/cypress-intercept-formdata","commit_stats":{"total_commits":41,"total_committers":3,"mean_commits":"13.666666666666666","dds":"0.14634146341463417","last_synced_commit":"67f7385a07b610b1386dd4301300b8a9a58f8910"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fcypress-intercept-formdata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fcypress-intercept-formdata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fcypress-intercept-formdata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yoavniran%2Fcypress-intercept-formdata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yoavniran","download_url":"https://codeload.github.com/yoavniran/cypress-intercept-formdata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244874103,"owners_count":20524572,"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":["ci-cd","cypress","cypress-io","form-data","intercept"],"created_at":"2024-10-12T22:27:32.909Z","updated_at":"2025-03-21T21:30:41.336Z","avatar_url":"https://github.com/yoavniran.png","language":"JavaScript","funding_links":["https://github.com/sponsors/yoavniran"],"categories":[],"sub_categories":[],"readme":"# cypress-intercept-formdata (CIFD)\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"LICENSE.md\"\u003e\n       \u003cimg src=\"https://img.shields.io/github/license/yoavniran/cypress-intercept-formdata?color=blue\u0026style=plastic\" alt=\"MIT License\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/cypress-intercept-formdata\"\u003e\n        \u003cimg src=\"https://badge.fury.io/js/cypress-intercept-formdata.svg\" alt=\"npm version\" height=\"20\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/yoavniran/cypress-intercept-formdata/actions/workflows/test.yml\"\u003e\n        \u003cimg src=\"https://github.com/yoavniran/cypress-intercept-formdata/actions/workflows/test.yml/badge.svg\"/\u003e \n    \u003c/a\u003e  \n    \u003ca href=\"https://codecov.io/gh/yoavniran/cypress-intercept-formdata\"\u003e\n      \u003cimg src=\"https://codecov.io/gh/yoavniran/cypress-intercept-formdata/branch/master/graph/badge.svg\" alt=\"codecov status\"/\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/cypress-intercept-formdata.svg?style=plastic\u0026color=blue\u0026label=monthly%20downloads\"/\u003e\n    \u003cimg src=\"https://shields.io/npm/dt/cypress-intercept-formdata.svg?style=plastic\u0026color=green\u0026label=total+downloads\"/\u003e\n\u003c/p\u003e\n\nThis package is intended to be used with [Cypress.io](https://www.cypress.io/) [intercept](https://docs.cypress.io/api/commands/intercept.html) command.\n\nAs of version 6.2 or 6.3 the request.body accessed from the intercept is an ArrayBuffer for multipart/form-data requests.\n\nThis makes it difficult to work with the body of the request and make assertions on it.\n\nCIFD makes it easy to use the multipart body in your specs.\n\n## Installation\n\n```shell\n#pnpm: \n   $ pnpm add cypress-intercept-formdata\n\n#NPM:\n   $ npm i cypress-intercept-formdata\n``` \n\n## Usage\n\nAdd to your commands file:\n\n```javascript\n\n//cypress/support/commands.js\n\nimport \"cypress-intercept-formdata\";\n\n//...\n```\n\nThen in your spec:\n\n```javascript\n\ncy.intercept(\"POST\", \"http://localhost:8888/api/test\", {\n\tstatusCode: 200,\n\tbody: { success: true },\n}).as(\"uploadRequest\");\n\n//...\n\ncy.wait(\"@uploadRequest\")\n\t.interceptFormData((formData) =\u003e {\n\t\texpect(formData[\"foo\"]).to.eq(\"bar\");\n\t});\n\n```\n\n### Uploading Files\n\nIf you have file(s) uploaded as part of the request they will be available in the formData object as well:\nThe value is the file name\n\n```javascript\n\ncy.wait(\"@uploadRequest\")\n\t.interceptFormData((formData) =\u003e {\n\t\texpect(formData[\"file\"]).to.eq(\"fileName.txt\");\n\t});\n```\n\nMultiple files are also supported:\n\n```javascript\ncy.wait(\"@uploadRequest\")\n\t.interceptFormData((formData) =\u003e {\n\t\texpect(formData[\"file\"][0]).to.eq(\"fileName1.txt\");\n\t\texpect(formData[\"file\"][1]).to.eq(\"fileName2.txt\");\n\t});\n```\n\n#### File Content\n\nBy default, CIFD simply adds the file name being uploaded to the formData object. If you'd like to\nassert more deeply on the file(s) being uploaded, you can set _options.loadFileContent_ to true:\n\n\n```javascript\n  cy.wait(\"@submitForm\")\n    .interceptFormData((formData) =\u003e {\n        expect(formData[\"file\"]).to.be.instanceof(File);\n        expect(formData[\"file\"]).to.have.property(\"type\", \"image/jpeg\");\n        expect(formData[\"file\"].size).to.be.eq(2551829);\n    }, { loadFileContent: true });\n```\n\u003e Multiple files are supported as well.\n\n\n### Use inside intercept routeHandler\n\nCypress intercept command accepts a [routeHandler](https://docs.cypress.io/api/commands/intercept.html#Intercepting-a-request)\n\nIf you want to inspect/assert on the body from the handler, you can import the interceptFormData directly and call it like this:\n\n```javascript\nimport { interceptFormData } from \"cypress-intercept-formdata\";\n\n//...\n\ncy.intercept(\"POST\", \"http://localhost:8888/api/test\", (req) =\u003e {\n  const formData = interceptFormData(req);\n  \n  expect(formData[\"first_name\"]).to.eq(\"James\");\n});\n\n```\n\n## Testing this Library\n\nIn terminal 1:\n\n```bash\npnpm serve\n```\n\nIn terminal 2:\n\n```bash\npnpm cy:run\n```\n\nOR\n\n```bash\npnpm cy:open\n```\n\n### Testing while developing\n\nIn terminal 3:\n\n```bash\npnpm watch\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoavniran%2Fcypress-intercept-formdata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoavniran%2Fcypress-intercept-formdata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoavniran%2Fcypress-intercept-formdata/lists"}