{"id":16015578,"url":"https://github.com/radekbednarik/har-to-expectations","last_synced_at":"2026-04-26T08:36:35.841Z","repository":{"id":214447135,"uuid":"735998905","full_name":"radekBednarik/har-to-expectations","owner":"radekBednarik","description":"CLI utility to convert .har file to expectation .json file.","archived":false,"fork":false,"pushed_at":"2024-03-12T14:19:14.000Z","size":256,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T03:35:29.793Z","etag":null,"topics":["cli","expectations","har","mock-server","nodejs","typescript"],"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/radekBednarik.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":"2023-12-26T17:31:14.000Z","updated_at":"2023-12-29T09:00:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"69d6cbb1-5996-4c15-ab64-02170f51d62b","html_url":"https://github.com/radekBednarik/har-to-expectations","commit_stats":{"total_commits":41,"total_committers":2,"mean_commits":20.5,"dds":"0.024390243902439046","last_synced_commit":"6aad30773c81e2f64d13d99a6f23c2c2c31fe82f"},"previous_names":["radekbednarik/har-to-expectations"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekBednarik%2Fhar-to-expectations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekBednarik%2Fhar-to-expectations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekBednarik%2Fhar-to-expectations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/radekBednarik%2Fhar-to-expectations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/radekBednarik","download_url":"https://codeload.github.com/radekBednarik/har-to-expectations/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247281621,"owners_count":20913205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","expectations","har","mock-server","nodejs","typescript"],"created_at":"2024-10-08T15:40:46.535Z","updated_at":"2026-04-26T08:36:35.767Z","avatar_url":"https://github.com/radekBednarik.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# har-to-expectations\n\nCLI tool to convert HAR file to expectations .json file which is ready for the [Mock-Server](https://www.mock-server.com/mock_server/creating_expectations.html)\n\nExported .json file is then ready to be either further manually modified or sent to the Mock-Server as is.\n\nYou could use [this tool](https://www.npmjs.com/package/@bednarik_radek/mockserver-cli) to handle this easily from CLI.\n\n## Installation\n\n```bash\nnpm install -g @bednarik_radek/har-to-expectations\n```\n\n## Usage\n\nTo display CLI help run:\n\n```bash\nnpx har -h\n```\n\nYou should see something like this:\n\n```bash\nUsage: har [options] [command]\n\nOptions:\n  -h, --help                            display help for command\n\nCommands:\n  convert \u003charPath\u003e \u003cjsonPath\u003e \u003cregex\u003e  converts .har file to .json file with expectations.\n  merge [options] \u003charPath\u003e \u003cjsonPath\u003e \u003cregex\u003e merges new .har file into existing .json expectations file.\n  help [command]                        display help for command\n```\n\n## conversion\n\n### Example\n\n- we have exported a HAR file from the browser to the `./har` folder\n- we want to convert it to the `./expectations` folder\n\n```bash\nnpx har convert ./har/requests.har ./expectations/expectations.json \"https://www.example.com\"\n```\n\nThis command will do the following:\n\n- read the `./har/requests.har` file and parse it to the JSON object with Har typings\n\n- filter out all requests which are not matching the `https://www.example.com` regex\n\n- convert the remaining requests to the JSON object as valid expectations\n\n- save the result to the `./expectations/expectations.json` file\n\n## Important notes\n\nThis utility is not doing full `.har`-to-`.json` conversion. It is only converting the requests and responses from the .har. Also, it is only adding certain parts of to expectations from requests/responses, which are needed to use them as mocks.\n\n### What is converted\n\n- request\n\n  - method\n  - pathname\n  - body, if it is present\n  - query parameters, if they are present\n\n- response\n\n  - status code\n  - response body, if it is present\n\n## Merging\n\n### Example\n\n- we want to add new expectations to the **existing** .json file\n\n- if expectation alredy exists, we want to update the `httpResponse` part - thus updating the mocked values\n\n```bash\nnpx har merge ./network-log.har ./existing-expectations.json --update\n```\n\n## Logging\n\n- provide:\n  - `LOG_LEVEL` ENV variable to set the log level. Default is `info`\n  - `LOG_ENABLED=true` ENV variable to enable logging. Default is `false`. Logging is done only to console. It is pretty-printed.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradekbednarik%2Fhar-to-expectations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fradekbednarik%2Fhar-to-expectations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fradekbednarik%2Fhar-to-expectations/lists"}