{"id":25540969,"url":"https://github.com/peterknezek/har-to-mocks","last_synced_at":"2026-03-04T01:23:01.213Z","repository":{"id":37930354,"uuid":"420815006","full_name":"peterknezek/har-to-mocks","owner":"peterknezek","description":"Extract response from .har file and create JSON mocks for mock server.","archived":false,"fork":false,"pushed_at":"2026-01-16T03:05:25.000Z","size":5882,"stargazers_count":28,"open_issues_count":6,"forks_count":14,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-16T03:08:57.686Z","etag":null,"topics":["cli","har","har-to-mocks","json","mock","mocking","mocks","requests","testing"],"latest_commit_sha":null,"homepage":"","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/peterknezek.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":"2021-10-24T22:56:16.000Z","updated_at":"2025-05-09T08:19:21.000Z","dependencies_parsed_at":"2024-03-03T00:25:36.631Z","dependency_job_id":"b49d9248-3ddb-4725-adca-fdb6730a5976","html_url":"https://github.com/peterknezek/har-to-mocks","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"326bf05070e12de0fc0301a77feba87753574207"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"purl":"pkg:github/peterknezek/har-to-mocks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterknezek%2Fhar-to-mocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterknezek%2Fhar-to-mocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterknezek%2Fhar-to-mocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterknezek%2Fhar-to-mocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterknezek","download_url":"https://codeload.github.com/peterknezek/har-to-mocks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterknezek%2Fhar-to-mocks/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28636815,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T15:01:31.228Z","status":"ssl_error","status_checked_at":"2026-01-21T14:42:58.942Z","response_time":86,"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":["cli","har","har-to-mocks","json","mock","mocking","mocks","requests","testing"],"created_at":"2025-02-20T06:22:31.079Z","updated_at":"2026-03-04T01:23:01.192Z","avatar_url":"https://github.com/peterknezek.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"har-to-mocks\n============\n\nExtract response from .har file and create JSON mocks for mock server.\n\n[![Version](https://img.shields.io/npm/v/har-to-mocks.svg)](https://npmjs.org/package/har-to-mocks)\n[![Downloads/week](https://img.shields.io/npm/dw/har-to-mocks.svg)](https://npmjs.org/package/har-to-mocks)\n[![License](https://img.shields.io/npm/l/har-to-mocks.svg)](https://github.com/peterknezek/har-to-mocks/blob/master/package.json)\n\n## Install CLI\n```\nnpm install -g har-to-mocks\n```\n\nor by npx\n\n```\nnpx har-to-mocks [path to .har] [path mock/api folder] --dry-run\n```\n\n## How does it work?\n\n### Inspect and filter requests in .har files\n\nFile can contain hundreds of requests so it's important to be able filter data. For filtering you can use flags:\n- (`--url`) for filtering by match in the url. Search is case sensitive and matches against the full URL including query parameters (e.g., `--url=?q=search` or `--url=/api/search?id=123`)\n- (`-m`, `--method=GET --method=POST`) for filter specific method. Supported: 'GET', 'POST', 'PUT', 'DELETE' and 'PATCH' methods. Default value is 'GET'.\n- (`-t`, `--type=xhr`) for filtering request type. Default value is 'xhr'\n\nVideo example: [YouTube har-to-mocks@1.1.1](https://youtu.be/Pc2J8aHRKNY).\n\nexample:\n```\n$ har-to-mocks ./file.har --url=api/service  --method=GET\n```\nwill display:\n```\nFiltered requests:\n\n Name          │ Method │ Path                        │ Query\n ──────────────┼────────┼─────────────────────────────┼──────\n userRoles     │ GET    │ /api/service/userRoles      │\n currentUserId │ GET    │ /api/service/currentUserId  │\n active        │ GET    │ /api/service/clients/active │\n```\n\nThe Query column displays URL query parameters for easy identification of similar requests.\n\nIf output folder is not specified, mocks will not be written and no Status column is shown.\n\n### Interactive Mode\n\nUse the `--interactive` (or `-i`) flag to manually select which endpoints to write:\n\n```\n$ har-to-mocks ./file.har ./mocks --interactive\n```\n\nIn interactive mode:\n1. A checkbox list appears with all endpoints\n2. **Response Preview**: As you navigate with arrow keys, the JSON response of the focused endpoint is displayed below the list\n3. Endpoints that would be written by default are pre-selected\n4. After selection, a folder tree preview is shown\n5. You're asked to confirm before files are written\n\n**Keyboard shortcuts:**\n- `↑/↓` - Navigate through endpoints (updates response preview)\n- `Space` - Toggle selection\n- `a` - Toggle all\n- `i` - Invert selection\n- `Enter` - Confirm selection\n\nThe response preview helps you distinguish between multiple responses from the same endpoint with different data - useful when duplicate routes return different responses and you need to choose the right one.\n\n### Extract data from .har to mock/api folder\n\nThe second argument should be path to `mock`'s folder. Export structure is prepared for [mocks-to-msw](https://github.com/peterknezek/mocks-to-msw) which helps with integration with MSW (Mock Service Worker) and [connect-api-mocker](https://www.npmjs.com/package/connect-api-mocker).\n\nWARNING: When second argument is defined cli will write files. To avoid unwanted overwrite use `--dry-run` flag to skip writing part of process.\n\nWhen a target folder is specified, the Status column shows what will happen to each file:\n- **create** - File doesn't exist, will be created\n- **update** - File already exists, will be overwritten\n- **skip** - Duplicate endpoint, will be skipped (a later entry writes to the same file)\n\nexample:\n```\n$ har-to-mocks ./file.har ./mocks --url=api/service  --method=GET --dry-run\n```\nwill display:\n```\nFiltered requests:\n\n Name          │ Method │ Path                        │ Query │ Status\n ──────────────┼────────┼─────────────────────────────┼───────┼───────\n userRoles     │ GET    │ /api/service/userRoles      │       │ create\n currentUserId │ GET    │ /api/service/currentUserId  │       │ create\n active        │ GET    │ /api/service/clients/active │       │ create\n\nFolder tree which will be applied:\n\n└─ mocks\n   └─ api\n      └─ service\n         ├─ userRoles\n         │  └─ GET.json\n         ├─ currentUserId\n         │  └─ GET.json\n         └─ clients\n            └─ active\n               └─ GET.json\n\nNo files were written. If you want to write files remove the (--dry-run) flag.\n```\n\nIf files already exist, the tree shows which will be updated:\n```\nFolder tree which will be applied:\n\n└─ mocks\n   └─ api\n      └─ service\n         ├─ userRoles\n         │  └─ GET.json [UPDATE]\n         ├─ currentUserId\n         │  └─ GET.json\n         └─ clients\n            └─ active\n               └─ GET.json [UPDATE]\n```\n\nWhen multiple requests share the same path and method (but have different query parameters), they would write to the same file. A helpful hint is displayed:\n```\nNote: Some endpoints have status \"skip\" because they share the same path and method.\nThe last occurrence will be written. To select specific endpoints, use interactive mode:\n\n  har-to-mocks \u003cfile.har\u003e \u003coutput-folder\u003e --interactive\n```\n\n## Development\n\n### Prerequisites\n\n- Node.js \u003e= 18.0.0\n- npm \u003e= 7.0.0\n\n### Tech Stack\n\nThis project uses modern JavaScript tooling:\n\n- **Framework**: [@oclif/core](https://oclif.io/) v4 - Modern CLI framework\n- **Module System**: ES Modules (ESM)\n- **Testing**: [Vitest](https://vitest.dev/) with snapshot testing\n- **TypeScript**: NodeNext module resolution for ESM compatibility\n- **Linting**: ESLint with TypeScript support\n\n### Getting Started\n\n1. Clone the repository\n2. Install dependencies:\n   ```bash\n   npm install\n   ```\n\n3. Build the project:\n   ```bash\n   npm run build\n   ```\n\n4. Run the CLI locally:\n   ```bash\n   ./bin/dev [args]\n   ```\n\n### Available Scripts\n\n- `npm run build` - Compile TypeScript to JavaScript\n- `npm run lint` - Run ESLint\n- `npm run lint:fix` - Fix ESLint issues automatically\n- `npm test` - Run tests in watch mode\n- `npm run test:ci` - Run tests once (for CI)\n- `npm run test:ui` - Open Vitest UI for interactive testing\n- `npm run coverage` - Generate test coverage report\n\n### Testing\n\nThe project maintains 100% test coverage with:\n\n- **Unit tests** using Vitest with snapshot assertions\n- **Integration tests** that verify CLI behavior end-to-end\n- **Snapshot testing** to catch unintended output changes\n\nRun tests:\n```bash\nnpm test\n```\n\nGenerate coverage report:\n```bash\nnpm run coverage\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterknezek%2Fhar-to-mocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterknezek%2Fhar-to-mocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterknezek%2Fhar-to-mocks/lists"}