https://github.com/radekbednarik/har-to-expectations
CLI utility to convert .har file to expectation .json file.
https://github.com/radekbednarik/har-to-expectations
cli expectations har mock-server nodejs typescript
Last synced: about 2 months ago
JSON representation
CLI utility to convert .har file to expectation .json file.
- Host: GitHub
- URL: https://github.com/radekbednarik/har-to-expectations
- Owner: radekBednarik
- License: mit
- Created: 2023-12-26T17:31:14.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-12T14:19:14.000Z (about 1 year ago)
- Last Synced: 2025-04-01T03:35:29.793Z (about 2 months ago)
- Topics: cli, expectations, har, mock-server, nodejs, typescript
- Language: TypeScript
- Homepage:
- Size: 250 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# har-to-expectations
CLI 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)
Exported .json file is then ready to be either further manually modified or sent to the Mock-Server as is.
You could use [this tool](https://www.npmjs.com/package/@bednarik_radek/mockserver-cli) to handle this easily from CLI.
## Installation
```bash
npm install -g @bednarik_radek/har-to-expectations
```## Usage
To display CLI help run:
```bash
npx har -h
```You should see something like this:
```bash
Usage: har [options] [command]Options:
-h, --help display help for commandCommands:
convert converts .har file to .json file with expectations.
merge [options] merges new .har file into existing .json expectations file.
help [command] display help for command
```## conversion
### Example
- we have exported a HAR file from the browser to the `./har` folder
- we want to convert it to the `./expectations` folder```bash
npx har convert ./har/requests.har ./expectations/expectations.json "https://www.example.com"
```This command will do the following:
- read the `./har/requests.har` file and parse it to the JSON object with Har typings
- filter out all requests which are not matching the `https://www.example.com` regex
- convert the remaining requests to the JSON object as valid expectations
- save the result to the `./expectations/expectations.json` file
## Important notes
This 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.
### What is converted
- request
- method
- pathname
- body, if it is present
- query parameters, if they are present- response
- status code
- response body, if it is present## Merging
### Example
- we want to add new expectations to the **existing** .json file
- if expectation alredy exists, we want to update the `httpResponse` part - thus updating the mocked values
```bash
npx har merge ./network-log.har ./existing-expectations.json --update
```## Logging
- provide:
- `LOG_LEVEL` ENV variable to set the log level. Default is `info`
- `LOG_ENABLED=true` ENV variable to enable logging. Default is `false`. Logging is done only to console. It is pretty-printed.