zoubingwu / msw-auto-mock

A cli tool to generate random mock data from OpenAPI definition for msw.
273 stars 57 forks source link

feat: added static generation mocks #38

Closed Artem-Nanavov closed 10 months ago

Artem-Nanavov commented 10 months ago

Hello everybody. So, here what I did. ; )

What? Added an option for generating static mocks.

Why? Firstly, we have an issue for this. ))

Some people can you this lib for generate mocks (prefer static) and use it for visual regression test, right now we can't give this option, but this PR fix this problem.

If you want to generate static mock - just add --static flag into command and run.

How?

  1. Added CLI option in the cli.ts.
  2. Added condition into function, which is generating mocks. If we want static - we will return value, if we don't want - we return string with dynamic mock (I didn't change it, only added option for static).

P.S. If you know how to make it more simple, comment below. ))

zoubingwu commented 10 months ago

I think this can be done with a much simpler solution, after calling transformJSONSchemaToFakerCode, we can put it in a new Function and run it once so it get a static data, I've already implemented it and will create another pull request soon

zoubingwu commented 10 months ago

@Artem-Nanavov pls check this out https://github.com/zoubingwu/msw-auto-mock/pull/43

Artem-Nanavov commented 10 months ago

@zoubingwu I checked, your solution's better than mine. I'm closing my MR. ;-)