{"id":22861556,"url":"https://github.com/onurakkaya/mockserver_ts","last_synced_at":"2026-05-09T01:04:51.139Z","repository":{"id":267848606,"uuid":"892820257","full_name":"onurakkaya/mockserver_ts","owner":"onurakkaya","description":"Multiple MockServer Management in TypeScript","archived":false,"fork":false,"pushed_at":"2024-12-12T19:36:37.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T08:44:13.053Z","etag":null,"topics":["integration-testing","javascript","jest","mock","mock-server","mockjs","mockserver","mockserver-manager","multimockserver","multiple-mock-server","testing","testing-tools","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/onurakkaya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","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-22T20:59:26.000Z","updated_at":"2024-12-12T19:36:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"87ecc40f-0226-469c-a2f9-7ee96558dd3f","html_url":"https://github.com/onurakkaya/mockserver_ts","commit_stats":null,"previous_names":["onurakkaya/mockserver_ts"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/onurakkaya/mockserver_ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onurakkaya%2Fmockserver_ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onurakkaya%2Fmockserver_ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onurakkaya%2Fmockserver_ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onurakkaya%2Fmockserver_ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/onurakkaya","download_url":"https://codeload.github.com/onurakkaya/mockserver_ts/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/onurakkaya%2Fmockserver_ts/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32803626,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"ssl_error","status_checked_at":"2026-05-08T08:22:45.650Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6: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":["integration-testing","javascript","jest","mock","mock-server","mockjs","mockserver","mockserver-manager","multimockserver","multiple-mock-server","testing","testing-tools","typescript"],"created_at":"2024-12-13T10:09:33.564Z","updated_at":"2026-05-09T01:04:51.135Z","avatar_url":"https://github.com/onurakkaya.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MockServer TS\n\nThis repository contains a baseline source for managing multiple mockservers in a project.\n\n## Table of Contents\n\n- [Setup](#setup)\n- [Run](#run)\n- [Debug](#debug)\n- [Testing](#testing)\n- [Description](#description)\n- [Demo Mock Servers](#demomockservers)\n- [Contributing](#contributing)\n- [License](#license)\n\n## Setup\n\n1. The repository should be cloned:\n    ```sh\n    git clone https://github.com/onurakkaya/mockserver_ts.git\n    cd mockserver_ts\n    ```\n\n2. Dependencies should be installed:\n    ```sh\n    yarn install\n    ```\n\n## Run\n\nTo start the mock server, the following command should be run:\n```sh\nyarn start\n```\n\nThe MockManager server will be started on the default port `4040`. The available methods and MockManager server health can be browsed at http://localhost:4000.\n\n## Debug\n\nTo debug the server, the built-in TSX debugger via VS Code can be used. A breakpoint should be added to the line which needs to be debugged, then the project should be started from VS Code (F5).\n\nNote: To use the TSX debugger, the tsx node package must be installed globally on the computer.\n```sh\nnpm install -g tsx\n```\n\n## Testing\n\nTo run the tests, the following command should be used:\n```sh\nyarn test\n```\n\nThe tests are configured to be run with Jest, and a coverage report will be generated in the `coverage` directory.\n\n## Description\nThis concept basically consists of two sections.\n\n### Mock Server\nAll MockServers must be inherited from this class. The main functionality of a Mock Server is contained within the class.\n\n#### Basic Info\nSome basic information can be set or retrieved for the MockServer using the available functions listed below.\n - setDefaultPort(port)\n - getDefaultPort() --\u003e returns port number\n - resetDefaultPort() --\u003e default port is set to null\n - getServerName() --\u003e returns server name\n - getServerInstance() --\u003e returns fastify server object\n - getServerStatus() --\u003e returns 1 if the server is started, 0 if the server is stopped.\n - getServerStatusString() --\u003e returns \"Started\" or \"Stopped\" as a string\n - getRoutes() --\u003e returns a list of defined custom routes as a ServerRoute array (method, path, handler)\n - The serverName can only be set in the constructor. If MockServer is extended, it can be set by calling the super() function, e.g., super(\"serverName\").\n\n#### Default Route\nMockServer has its own predefined default route \"/\", which shows all available routes registered to MockServers.\n\n#### Custom Route Registration\nCustom routes can be registered via the registerRouteIfNotExists function. The function takes method (get/post/put/delete), path: string, and handler: function parameters.\n\nNote: The path is case-sensitive.\n\n#### Start/Stop Server\nMockServer can be started and stopped by predefined StartServer and StopServer functions. StartServer also has an optional customPort parameter.\n\n### Mock Manager\nMockManager, which is also extended from MockServer, manages all MockServers registered to itself.\n\n#### Default Route\nThis is extended from Mock Server.\n\n#### Mock Server Registration\nTo have your service managed by MockManager, your mock server should be registered with the Mock Manager using the `registerMockServer(mockServer)` function.\n\n#### Routes\n#### /startServerByName\nMultiple MockServers can be started with this request. The body should be in \"MockServerRequest\" type. A sample body is shown below:\n```json\nPOST \n{\n    \"mockServers\": [\n        {\n            \"mockServer\": \"UserService\",\n            \"customPort\": null\n        },\n        {\n            \"mockServer\": \"ProductService\",\n            \"customPort\": null\n        }\n    ]\n}\n```\n\n#### /stopServerByName\nMultiple MockServers can be stopped with this request. The body should be in \"MockServerRequest\" type. A sample body is shown below:\n```json\nPOST \n{\n    \"mockServers\": [\n        {\n            \"mockServer\": \"UserService\",\n            \"customPort\": null\n        },\n        {\n            \"mockServer\": \"ProductService\",\n            \"customPort\": null\n        }\n    ]\n}\n```\n#### /getServerInfoByName\nServer health and status information can be retrieved with this request for a specified mock server.\nUsage: GET /getServerInfoByName?serverName=#ServerName#\n\n#### /startAll\nAll registered mock servers can be started with this command.\nUsage: GET /startAll\n\n#### /stopAll\nAll registered mock servers can be stopped with this command.\nUsage: GET /stopAll\n\n#### /getServerInfo\nServer health and status information for all registered mock servers can be retrieved with this command.\nUsage: GET /getServerInfo\n\n## DemoMockServers\nSome example mock server implementations are provided.\n\n### UserServiceMockServer\nBasic create, read, and delete commands are included in the mock server. The server is registered in `index.ts` by default.\n\nThe `UserServiceMockServer` will be available on port `4001` by default. It provides the following endpoints:\n- `GET /users`: Retrieve all users.\n- `GET /users/:id`: Retrieve a user by ID.\n- `POST /users`: Create a new user.\n- `DELETE /users/:id`: Delete a user by ID.\n\n### ProductServiceMockServer\nBasic create, read, and delete commands, as well as an Authorization header check, are included in the mock server. The server is registered in `index.ts` by default.\n\nThe `ProductServiceMockServer` will be available on port `4002` by default. It provides the following endpoints:\n- `GET /products`: Retrieve all products.\n- `GET /products/:id`: Retrieve a product by ID.\n- `POST /products`: Create a new product.\n- `DELETE /products/:id`: Delete a product by ID.\n\n## Contributing\n\nContributions are welcome! Please follow these steps:\n\n1. **The repository should be forked**: Click the \"Fork\" button at the top right of the repository page.\n2. **Your fork should be cloned**:\n    ```sh\n    git clone https://github.com/onurakkaya/mockserver_ts.git\n    cd mockserver_ts\n    ```\n3. **A branch should be created**:\n    ```sh\n    git checkout -b your-branch-name\n    ```\n4. **Your changes should be made**: Implement your feature, bug fix, or documentation update.\n5. **Your changes should be committed**:\n    ```sh\n    git commit -m \"Description of your changes\"\n    ```\n6. **Your fork should be pushed**:\n    ```sh\n    git push origin your-branch-name\n    ```\n7. **A pull request should be created**: Go to the original repository and click \"New Pull Request\".\n\n## License\n\nThis project is licensed under the GNU General Public License v3.0. See the [LICENSE](LICENSE.md) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonurakkaya%2Fmockserver_ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fonurakkaya%2Fmockserver_ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fonurakkaya%2Fmockserver_ts/lists"}