{"id":24753853,"url":"https://github.com/codeceptjs/msw-mock-server","last_synced_at":"2026-01-26T04:32:31.990Z","repository":{"id":261198648,"uuid":"883587750","full_name":"codeceptjs/msw-mock-server","owner":"codeceptjs","description":null,"archived":false,"fork":false,"pushed_at":"2024-11-05T08:34:36.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-18T19:22:39.887Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@codeceptjs/msw-mock-server","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codeceptjs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-11-05T08:26:41.000Z","updated_at":"2024-11-27T10:26:19.000Z","dependencies_parsed_at":"2024-11-05T08:36:19.524Z","dependency_job_id":"4bd4e7f1-875c-480c-9d77-19d88037a637","html_url":"https://github.com/codeceptjs/msw-mock-server","commit_stats":null,"previous_names":["codeceptjs/msw-mock-server"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/codeceptjs/msw-mock-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeceptjs%2Fmsw-mock-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeceptjs%2Fmsw-mock-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeceptjs%2Fmsw-mock-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeceptjs%2Fmsw-mock-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codeceptjs","download_url":"https://codeload.github.com/codeceptjs/msw-mock-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codeceptjs%2Fmsw-mock-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28766886,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T03:54:34.369Z","status":"ssl_error","status_checked_at":"2026-01-26T03:54:33.031Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":[],"created_at":"2025-01-28T11:36:34.514Z","updated_at":"2026-01-26T04:32:31.970Z","avatar_url":"https://github.com/codeceptjs.png","language":"JavaScript","readme":"## MockServer\n\n\u003c!-- Generated by documentation.js. Update this documentation by updating the source code. --\u003e\n\n#### Table of Contents\n\n-   [config](#config)\n-   [Configuration](#configuration)\n    -   [Properties](#properties)\n-   [MockService](#mockservice)\n    -   -   [Examples](#examples)\n        -   [Adding Interactions](#adding-interactions)\n        -   [Request Matching](#request-matching)\n            -   [Match on Query Params](#match-on-query-params)\n-   [Methods](#methods)\n    -   [Parameters](#parameters)\n    -   [startMockServer](#startmockserver)\n    -   [stopMockServer](#stopmockserver)\n    -   [addInteractionToMockServer](#addinteractiontomockserver)\n        -   [Parameters](#parameters-1)\n\n### config\n\n### Configuration\n\nThis helper should be configured in codecept.conf.(js|ts)\n\nType: [object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)\n\n#### Properties\n\n-   `port` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Mock server port\n-   `host` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)?** Mock server host\n\n### MockService\n\nMock Server - powered by [msw](https://www.npmjs.com/package/msw)\n\nThe MockServer Helper in CodeceptJS empowers you to mock any server or service via HTTP or HTTPS, making it an excellent tool for simulating REST endpoints and other HTTP-based APIs.\n\n\u003c!-- configuration --\u003e\n\n##### Examples\n\nYou can seamlessly integrate MockServer with other helpers like REST or Playwright. Here's a configuration example inside the `codecept.conf.js` file:\n\n```javascript\n{\n  helpers: {\n    REST: {...},\n    MockServer: {\n      require: '@codeceptjs/msw-mock-server',\n      // default mock server config\n      port: 9393,\n      host: 'mock-service.test',\n    },\n  }\n}\n```\n\n##### Adding Interactions\n\nInteractions add behavior to the mock server. Use the `I.addInteractionToMockServer()` method to include interactions. It takes an interaction object as an argument, containing request and response details.\n\n```javascript\nI.addInteractionToMockServer({\n   request: {\n     method: 'GET',\n     path: '/api/hello'\n   },\n   response: {\n     status: 200,\n     body: {\n       'say': 'hello to mock server'\n     }\n   }\n});\n```\n\n##### Request Matching\n\nWhen a real request is sent to the mock server, it matches the received request with the interactions. If a match is found, it returns the specified response; otherwise, a 404 status code is returned.\n\n###### Match on Query Params\n\nYou can send different responses based on query parameters:\n\n```javascript\nI.addInteractionToMockServer({\n  request: {\n    method: 'GET',\n    path: '/api/users',\n    queryParams: {\n      id: 1\n    }\n  },\n  response: {\n    status: 200,\n    body: 'user 1'\n  }\n});\n\nI.addInteractionToMockServer({\n  request: {\n    method: 'GET',\n    path: '/api/users',\n    queryParams: {\n      id: 2\n    }\n  },\n  response: {\n    status: 200,\n    body: 'user 2'\n  }\n});\n```\n\n-   GET to `/api/users?id=1` will return 'user 1'.\n-   GET to `/api/users?id=2` will return 'user 2'.\n-   For all other requests, it returns a 404 status code.\n\nHappy testing with MockServer in CodeceptJS! 🚀\n\n### Methods\n\n#### Parameters\n\n-   `passedConfig`  \n\n#### startMockServer\n\nStart the mock server\n\nReturns **any** void\n\n#### stopMockServer\n\nStop the mock server\n\nReturns **any** void\n\n#### addInteractionToMockServer\n\nAn interaction adds behavior to the mock server\n\n```js\nI.addInteractionToMockServer({\n   request: {\n     method: 'GET',\n     path: '/api/hello'\n   },\n   response: {\n     status: 200,\n     body: {\n       'say': 'hello to mock server'\n     }\n   }\n});\n```\n\n```js\n// with query params\nI.addInteractionToMockServer({\n   request: {\n     method: 'GET',\n     path: '/api/hello',\n     queryParams: {\n      id: 2\n    }\n   },\n   response: {\n     status: 200,\n     body: {\n       'say': 'hello to mock server'\n     }\n   }\n});\n```\n\n##### Parameters\n\n-   `interaction` **(CodeceptJS.MockInteraction | [object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object))** add behavior to the mock server\n\nReturns **any** void\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeceptjs%2Fmsw-mock-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeceptjs%2Fmsw-mock-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeceptjs%2Fmsw-mock-server/lists"}