{"id":28603061,"url":"https://github.com/lensesio/cypress-websocket-testing","last_synced_at":"2026-03-08T00:31:04.663Z","repository":{"id":44040729,"uuid":"223212821","full_name":"lensesio/cypress-websocket-testing","owner":"lensesio","description":"Test WebSocket connections with Cypress","archived":false,"fork":false,"pushed_at":"2023-07-12T04:16:27.000Z","size":1078,"stargazers_count":83,"open_issues_count":15,"forks_count":11,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-06-11T16:53:05.206Z","etag":null,"topics":["cypress","testing","websocket"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lensesio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-21T16:07:27.000Z","updated_at":"2024-04-23T19:09:04.000Z","dependencies_parsed_at":"2023-02-03T03:45:41.318Z","dependency_job_id":null,"html_url":"https://github.com/lensesio/cypress-websocket-testing","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/lensesio/cypress-websocket-testing","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lensesio%2Fcypress-websocket-testing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lensesio%2Fcypress-websocket-testing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lensesio%2Fcypress-websocket-testing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lensesio%2Fcypress-websocket-testing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lensesio","download_url":"https://codeload.github.com/lensesio/cypress-websocket-testing/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lensesio%2Fcypress-websocket-testing/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30238836,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:30:53.000Z","status":"ssl_error","status_checked_at":"2026-03-08T00:30:44.061Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cypress","testing","websocket"],"created_at":"2025-06-11T16:43:12.736Z","updated_at":"2026-03-08T00:31:04.647Z","avatar_url":"https://github.com/lensesio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cypress-websocket-testing\n\nTest your WebSocket endpoints using [Cypress](https://docs.cypress.io/).\n\n[![Build Status](https://travis-ci.com/lensesio/cypress-websocket-testing.svg?branch=master)](https://travis-ci.com/Lensesio/cypress-websocket-testing)\n\u003cbr /\u003e\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![License: Apache 2](https://img.shields.io/badge/license-Apache-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![TypeScript](https://badges.frapsoft.com/typescript/love/typescript.svg?v=101)](https://github.com/ellerbrock/typescript-badges/)\n\n\n## Table of Contents\n\n- [Background](#Background)\n- [Installation](#Installation)\n- [Usage](#Usage)\n  - [JavaScript](#JavaScript)\n  - [TypeScript](#TypeScript)\n- [Arguments](#Arguments)\n- [Running the examples](#Running-the-examples)\n- [PRs](#prs)\n- [TODO](#TODO)\n- [License](#license)\n\n## Background\n\nCypress comes out of the box with a great set of tools that allow both UI and API integration tests to be written. Unfortunately the `cy.request()` command is limited to REST endpoints only, so this library is here to help with those cases when WebSockets need to be called/tested as part of more complex integration/E2E tests.\n\n## Installation\n\n```bash\nnpm i -D @lensesio/cypress-websocket-testing\n# or\nyarn add -D @lensesio/cypress-websocket-testing\n```\n\nYou also need to add `rxjs` to the project.\n```bash\nnpm i -D rxjs\n```\n\n## Usage\n\n### JavaScript\n\n`@lensesio/cypress-websocket-testing` extends Cypress' `cy` command.\n\nAdd this line to your project's `cypress/support/commands.js`:\n\n```\nimport { addStreamCommands } from '@lensesio/cypress-websocket-testing';\naddStreamCommands();\n```\n\nThen, in your test, you can use both commands that come with this lib. cy.stream and cy.streamRequest.\n\n```javascript\n// For common cases:\ncy.streamRequest(config, options).then(results =\u003e {\n        expect(results).to.not.be.undefined;\n})\n// When in need of a bit more flexibility\ncy.stream(config).then(subject =\u003e {\n      subject\n        .pipe(\n          takeUntil(timer(1000)),\n          reduce((acc , val) =\u003e acc.concat([val]), [])\n        )\n        .subscribe({\n          next: (results) =\u003e {\n            expect(results).to.not.be.undefined;\n          },\n          error: (err) =\u003e {},\n          complete: done\n        });\n    });\n```\n\n### TypeScript\n\nAs the library is written in Typescript, you can pass the type of the message to the command and to the config/options object. ( make sure that you already configured your Cypress tests to work [with TS](https://github.com/bahmutov/add-typescript-to-cypress) )\n\nFirst, add `@lensesio/cypress-websocket-testing` to the `cypress/tsconfig.json` file\n\n```\n{\n  \"compilerOptions\": {\n    \"types\": [\n        \"cypress\",\n        \"@lensesio/cypress-websocket-testing\"\n    ]\n  }\n}\n```\n\nThen to use in TypeScript tests: \n\n```typescript\n// For full set of config values, check rxjs documentation\nconst config: WebSocketSubjectConfig\u003cIMessage\u003e = {\n  url: \"ws://localhost:8080/\"\n};\n\nlet options: Partial\u003cStreamRequestOptions\u003cIMessage\u003e\u003e;\n\ncy.streamRequest\u003cIMessage\u003e(config, options).then((results?: IMessage[]) =\u003e {\n        expect(results).to.not.be.undefined;\n})\ncy.stream\u003cIMessage\u003e(config).then(subject =\u003e {\n      subject\n        .pipe(\n          takeUntil(timer(1000)),\n          reduce((acc: IMessage[], val: IMessage) =\u003e acc.concat([val]), [])\n        )\n        .subscribe({\n          next: (results?: IMessage[]) =\u003e {\n            expect(results).to.not.be.undefined;\n          },\n          error: (err: any) =\u003e {},\n          complete: done\n        });\n    });\n```\n\nNote: \nThere are some type conflicts when extending/adding operators to cy.stream() in tests directly. (due to  issues with Cypress including an old rxjs version as a dependency). Best way is to extend cy.stream() by building a custom command with it and use that instead.\n\n\n\n## Arguments\n\n- config\n\nA [WebSocketSubjectConfig](https://rxjs-dev.firebaseapp.com/api/webSocket/WebSocketSubjectConfig) object. See official docs for more information. Is passed as is to the underlying webSocket subject.\n\n- options:StreamRequestOptions (only for streamRequest command. Although optional, at least the takeWhileFn should be set)\n\nUsage `cy.streamRequest(config, options)`.\n\n| Option               | Default                | Description                                                                                                                                               |\n| -------------------- | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `streamTimeout`           | `defaultCommandTimeout` | Time to wait for the stream to complete. (if is greater than Cypress defaultCommandTimeout, you need to use the cy.wrap as a workaround. Investigating alternative ways)                                                                                                                            |\n| `retryDelay`            | `4000`                 | How long to way until a new connection attempt is made.                                                                   |\n| `retryAttempts`           | `5`                  | How many times to retry the connection before completing.                                                                                                     |\n| `startUpMessage`        | `any`          | A message to be sent on connection open.                                                                                                             |\n| `takeWhileFn`             | `()=\u003efalse`          | Function that will tell the stream when to close. If not set, it will close on the first message received in order to avoid having an open connection. |\n| `retryUntilFn`             | `()=\u003etrue`          | Function that will tell the stream how to check the results, and retry if the result is false. |\n\n\n\u003cbr /\u003e\n\u003cbr /\u003e\n\n## Running the examples\n\nIn order to try this project locally, you need to `npm install` in both the root and the examples/ folder. \nAfter, build the library using `npm run build` in the root folder, then go to examples/ , start the websocket server `npm start` and cypress using `npm run test:local`.\n\n## PRs\n\nPRs are welcome. Be sure to add \n- Tests\n- Reason for the PR \n\u003cbr /\u003e\nWhen committing, remember to use `npm run commit`, in order to start commitizen.\n\n\n## TODO\n- [] Find a fix for the cy.wrap workaround.\n- [] Improve error handling.\n- [] Add more examples for cy.stream command.\n\n## LICENSE\n\n[Apache 2.0](LICENSE.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flensesio%2Fcypress-websocket-testing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flensesio%2Fcypress-websocket-testing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flensesio%2Fcypress-websocket-testing/lists"}