Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please provide support of HAR files as a source of mocks #487

Open
OleksandrKucherenko opened this issue Dec 1, 2023 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@OleksandrKucherenko
Copy link

OleksandrKucherenko commented Dec 1, 2023

Is your feature request related to a problem? Please describe.
Html Archive (HAR) - is a modern way to snapshot webpage loading. Web browser can produce those files in several clicks.

Describe the solution you'd like
HAR (Html Archive) is JSON file that contains recorded by dev tools networks calls. So all we have to build around it is a way to extract collection, routes and connect it to the mock server.

Will be also great to support Zipped HAR files, they are quite huge in size, can easily reach 30-40Mb in size, and this is not optimal for git repos.

Describe alternatives you've considered

  • can be composed utilities that can convert HAR json to set of files: collection, routes, etc.
  • will be great to have Capture/Update functionality for proxy mode, when mocks-server record all requests/responses for reuse

Additional context

@javierbrea javierbrea added the enhancement New feature or request label Dec 15, 2023
@OleksandrKucherenko
Copy link
Author

OleksandrKucherenko commented Mar 28, 2024

Initial implementation: https://github.com/OleksandrKucherenko/webpack.config/blob/main/mocks/scripts/README.md

# usage
# now its time to convert HAR to set of JSON files
mocks/scripts/export.har.ts ./mocks/fixtures/16b19ff8-640f-4489-af03-9adff0e902da/recorded.har

Design points:

  • CLI tool that generates mock server configuration files from HAR

Known issues:

  • some kind of specifics to endpoints routes exists in a script, will be required small modifications for each business
  • not implemented yet a good parameters hashing logic (required for detecting change of parameters order in query path or query body)
  export:har processing file: './mocks/fixtures/16b19ff8-640f-4489-af03-9adff0e902da/recorded.har' +0ms
  export:har include failed entries: true +1ms
  export:har enabled debug info: false +0ms
  export:har total HAR entries: 133 +198ms
  export:har source url: https://example.com/server +1ms
  export:har "application/json" entries: 85 +1ms
  export:har searching for unique entries... +0ms
  export:har detected repeated entries: 37 +9ms
  export:har mapped entries: 48 +24ms
  export:har output mapping file: "./mocks/fixtures/16b19ff8-640f-4489-af03-9adff0e902da/mapping.json" +0ms

./mocks/scripts/export.har.ts --help
export.har.ts <file>

Converts a HAR (Html ARchive) file to a collection of JSON files

Options:
  --file     HAR file to convert                             [string] [required]
  --failed   extract failed entries                    [boolean] [default: true]
  --debug    enable debug logs                        [boolean] [default: false]
  --version  Show version number                                       [boolean]
  --help     Show help                                                 [boolean]

extras (React Project Setup with Proxy and MockServer's):

@javierbrea javierbrea moved this to To do in Backlog May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: To do
Development

No branches or pull requests

2 participants