{"id":23157304,"url":"https://github.com/vgeorge/cypress-websocket-server","last_synced_at":"2025-04-04T17:45:48.273Z","repository":{"id":57211262,"uuid":"416881866","full_name":"vgeorge/cypress-websocket-server","owner":"vgeorge","description":"Cypress plugin to mock a websocket server during tests.","archived":false,"fork":false,"pushed_at":"2021-10-13T21:20:20.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-11T08:07:53.985Z","etag":null,"topics":["cypress","plugin","websocket","ws"],"latest_commit_sha":null,"homepage":"","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/vgeorge.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}},"created_at":"2021-10-13T20:01:53.000Z","updated_at":"2021-10-13T21:20:23.000Z","dependencies_parsed_at":"2022-08-29T20:41:43.146Z","dependency_job_id":null,"html_url":"https://github.com/vgeorge/cypress-websocket-server","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgeorge%2Fcypress-websocket-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgeorge%2Fcypress-websocket-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgeorge%2Fcypress-websocket-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vgeorge%2Fcypress-websocket-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vgeorge","download_url":"https://codeload.github.com/vgeorge/cypress-websocket-server/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247226196,"owners_count":20904464,"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":["cypress","plugin","websocket","ws"],"created_at":"2024-12-17T21:16:47.488Z","updated_at":"2025-04-04T17:45:48.247Z","avatar_url":"https://github.com/vgeorge.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cypress-websocket-server\n\nCypress plugin to mock a websocket server during tests.\n\n## Getting started\n\nInstall:\n\n```bash\nnpm i cypress-websocket-server\n```\n\nAdd `cy.setWebsocketWorkflow()` command by adding the following to `cypress/support/index.js`:\n\n```javascript\nimport { addCommand } from \"cypress-websocket-server\";\naddCommand();\n```\n\nAdd websocket server in `cypress/plugins/index.js`, accessible via endpoint `ws://localhost:1999`:\n\n```javascript\nconst { startMockWsServer } = require(\"cypress-websocket-server\");\n\nmodule.exports = (on, config) =\u003e {\n  startMockWsServer(config);\n};\n```\n\n## Workflow file format\n\nThe fixture `.json` file should contain an array of objects with properties:\n\n- `type`:\n  - `server`: a message that should be sent by the server\n  - `client`: a message the server expects from the client\n  - `reconnect`: an expected client reconnection\n- `payload` (optional): message data, can be of any object type\n\n## Example workflow\n\nIn a scenario where a websocket exchange is expected after the user clicking a button, the websocket can be configured to follow a specific workflow like this:\n\n```javascript\ndescribe(\"Trigger WS workflow on button click\", () =\u003e {\n  it(\"Run new project\", () =\u003e {\n    cy.visit(\"/\");\n    cy.setWebsocketWorkflow(\"expected-workflow.json\");\n    cy.get(\"[data-cy=ws-trigger-button]\").click();\n  });\n});\n```\n\nBeing the content of `expected-workflow.json`, in fixtures folder:\n\n```json\n[\n  {\n    \"type\": \"server\",\n    \"payload\": { \"message\": \"connected\" }\n  },\n  {\n    \"type\": \"client\",\n    \"payload\": { \"action\": \"get-user\" }\n  },\n  {\n    \"type\": \"server\",\n    \"payload\": {\n      \"message\": \"user-info\",\n      \"data\": {\n        \"id\": 1,\n        \"name\": \"My User\"\n      }\n    }\n  }\n]\n```\n\nThe server will listen to any connections in `ws://localhost:1999` and:\n\n- Send payload `{ \"message\": \"connected\" }` on client connection\n- Expect client message with payload `{ \"action\": \"get-user\" }`\n- Send back user info\n\nIf the client doesn't send the expected message in the right order, or send additional messages, an error will be printed to Cypress console.\n\n## License\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgeorge%2Fcypress-websocket-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvgeorge%2Fcypress-websocket-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvgeorge%2Fcypress-websocket-server/lists"}