mocks-server / main

Node.js mock server running live, interactive mocks in place of real APIs
https://www.mocks-server.org
Apache License 2.0
281 stars 14 forks source link

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

Open OleksandrKucherenko opened 7 months ago

OleksandrKucherenko commented 7 months ago

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

Additional context

OleksandrKucherenko commented 3 months ago

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:

Known issues:

  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):