{"id":18458456,"url":"https://github.com/relaycorp/ws-mock-js","last_synced_at":"2026-03-05T02:32:26.055Z","repository":{"id":37962697,"uuid":"304027377","full_name":"relaycorp/ws-mock-js","owner":"relaycorp","description":"Mock client and server to unit test the NPM package 'ws'","archived":false,"fork":false,"pushed_at":"2025-06-30T15:32:29.000Z","size":1198,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-08T21:43:46.779Z","etag":null,"topics":["websocket"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@relaycorp/ws-mock","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/relaycorp.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}},"created_at":"2020-10-14T13:40:20.000Z","updated_at":"2025-06-18T02:10:36.000Z","dependencies_parsed_at":"2022-09-02T11:40:42.284Z","dependency_job_id":"b879fee7-bc3a-4436-82fc-28bc4dd6c1a2","html_url":"https://github.com/relaycorp/ws-mock-js","commit_stats":{"total_commits":204,"total_committers":4,"mean_commits":51.0,"dds":0.6274509803921569,"last_synced_commit":"618557c56a8e55fe1588643ed510bb36047b465e"},"previous_names":[],"tags_count":57,"template":false,"template_full_name":null,"purl":"pkg:github/relaycorp/ws-mock-js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/relaycorp%2Fws-mock-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/relaycorp%2Fws-mock-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/relaycorp%2Fws-mock-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/relaycorp%2Fws-mock-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/relaycorp","download_url":"https://codeload.github.com/relaycorp/ws-mock-js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/relaycorp%2Fws-mock-js/sbom","scorecard":{"id":769790,"data":{"date":"2025-08-11","repo":{"name":"github.com/relaycorp/ws-mock-js","commit":"2a78d7e4a5442833bc33180285c1b5363924c5d6"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.7,"checks":[{"name":"Code-Review","score":-1,"reason":"Found no human activity in the last 30 changesets","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/ci.yml:1","Warn: no topLevel permission defined: .github/workflows/prs.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/relaycorp/ws-mock-js/ci.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:8: update your workflow using https://app.stepsecurity.io/secureworkflow/relaycorp/ws-mock-js/ci.yml/main?enable=pin","Warn: third-party GitHubAction not pinned by hash: .github/workflows/prs.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/relaycorp/ws-mock-js/prs.yml/main?enable=pin","Info:   0 out of   3 third-party GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Security-Policy","score":10,"reason":"security policy file detected","details":["Info: security policy file detected: github.com/relaycorp/.github/SECURITY.md:1","Info: Found linked content: github.com/relaycorp/.github/SECURITY.md:1","Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/relaycorp/.github/SECURITY.md:1","Info: Found text in security policy: github.com/relaycorp/.github/SECURITY.md:1"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 30 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":7,"reason":"3 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-23T01:55:16.977Z","repository_id":37962697,"created_at":"2025-08-23T01:55:16.977Z","updated_at":"2025-08-23T01:55:16.977Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30107212,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-05T01:39:18.192Z","status":"online","status_checked_at":"2026-03-05T02:00:06.710Z","response_time":93,"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":["websocket"],"created_at":"2024-11-06T08:18:40.455Z","updated_at":"2026-03-05T02:32:26.039Z","avatar_url":"https://github.com/relaycorp.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @relaycorp/ws-mock\n\nMock client and server to unit test servers and clients powered by [`ws`](https://www.npmjs.com/package/ws).\n\n## Install\n\n```\nnpm install @relaycorp/ws-mock\n```\n\n## Using the mock client\n\nYou'd use a mock client when you need to test a server. You should initialise `MockClient` by passing the `ws` server to be tested and then call `client.connect()` to initiate the connection. From that point you can interact with the server. For example:\n\n```typescript\ntest('Challenge should be sent as soon as client connects', async () =\u003e {\n  const client = new MockClient(wsServer);\n  await client.connect();\n\n  const challengeSerialized = await client.receive();\n  expect(challengeSerialized).toBeInstanceOf(ArrayBuffer);\n});\n```\n\nYou'll find real-world examples in [relaycorp/relaynet-internet-gateway](https://github.com/relaycorp/relaynet-internet-gateway/search?l=TypeScript\u0026q=%22%40relaycorp%2Fws-mock%22) and [relaycorp/awala-gateway-desktop](https://github.com/relaycorp/awala-gateway-desktop/search?l=TypeScript\u0026q=%22%40relaycorp%2Fws-mock%22).\n\n## Using the mock server\n\nYou'd use a mock server when you need to test a client. You basically need to initialise `MockServer` and replace the default export from `ws` with a mock WebSocket. Here's an example with Jest:\n\n```typescript\nlet mockServer: MockServer;\nbeforeEach(() =\u003e {\n  mockServer = new MockServer();\n});\njest.mock('ws', () =\u003e ({\n  __esModule: true,\n  default: jest.fn().mockImplementation(() =\u003e mockServer.client),\n}));\n\ntest('Server message should be played back', async () =\u003e {\n  const clientUnderTest = new ClientUnderTest();\n  const messageToEcho = 'foo';\n\n  await mockServer.use(\n    clientUnderTest.connectToServerAndInteractWithIt(),\n    async () =\u003e {\n      await mockServer.send(messageToEcho);\n\n      // Check that the client sent the message back to the server:\n      const clientResponse = await mockServer.receive();\n      expect(clientResponse).toEqual(messageToEcho);\n    },\n  );\n});\n```\n\nYou'll find [real-world examples in relaycorp/relaynet-poweb-js](https://github.com/relaycorp/relaynet-poweb-js/search?l=TypeScript\u0026q=%22%40relaycorp%2Fws-mock%22).\n\n## Using streams\n\nWhen using streams in the unit under test, make sure to mock the `createWebSocketStream` function in `ws`. Here's an example with Jest:\n\n```javascript\nimport { createMockWebSocketStream } from '@relaycorp/ws-mock';\nimport WebSocket from 'ws';\n\njest\n  .spyOn(WebSocket, 'createWebSocketStream')\n  .mockImplementation(createMockWebSocketStream);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frelaycorp%2Fws-mock-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frelaycorp%2Fws-mock-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frelaycorp%2Fws-mock-js/lists"}