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

Intergrate with msw mock service #1069

Closed
himself65 opened this issue Sep 19, 2024 · 11 comments
Closed

Intergrate with msw mock service #1069

himself65 opened this issue Sep 19, 2024 · 11 comments
Labels
feature 🚀 New feature or request needs info ⏳ Further information is required RSVP 👍👎 Explicit request for reactions to gauge interest in resolving this issue

Comments

@himself65
Copy link

Description

I think it's possible to generate mock server handler for better unit testing

@himself65 himself65 added the feature 🚀 New feature or request label Sep 19, 2024
@mrlubos mrlubos added the RSVP 👍👎 Explicit request for reactions to gauge interest in resolving this issue label Sep 19, 2024
@mrlubos
Copy link
Member

mrlubos commented Sep 19, 2024

@himself65 What do you do currently?

@mrlubos mrlubos added the needs info ⏳ Further information is required label Sep 26, 2024
@mrlubos
Copy link
Member

mrlubos commented Dec 20, 2024

Related to #1486

@mrlubos
Copy link
Member

mrlubos commented Jan 6, 2025

Closing this in favour of #1486, please move any discussion there!

@mrlubos mrlubos closed this as completed Jan 6, 2025
@mrlubos
Copy link
Member

mrlubos commented Jan 21, 2025

Hey @himself65, are you using MSW Source? What's the benefit for you to have Hey API generate MSW handlers?

@himself65
Copy link
Author

So I don't need manually write random data code

@mrlubos
Copy link
Member

mrlubos commented Jan 21, 2025

@himself65 which parts do you still need to write manually when using MSW Source?

@mkeyy0
Copy link

mkeyy0 commented Feb 12, 2025

Also, I recently found msw-auto-mock, looks like it also covers all the functionality you might need. (When you prefer static generation over runtime)

@mrlubos
Copy link
Member

mrlubos commented Feb 12, 2025

@mkeyy0 did you end up using it? The GenAI feature looks interesting

@mkeyy0
Copy link

mkeyy0 commented Feb 12, 2025

No, I've just found it and right now trying it in my repo, I'll give you feedback a bit later during the day

@mkeyy0
Copy link

mkeyy0 commented Feb 12, 2025

After a small investigation, it looks like msw-auto-mock doesn't work for me by the following reasons:

  • It looks like it is developed to be used in the browser environment . It uses the next function that increases the counter using closure after each request execution and then makes a % on a possible request length which makes the request order of subsequent requests unpredictable. So this approach doesn't work for tests
  • Doesn't have built-in typescript support

Also, some things to say about MSW Source. I quite don't like the approach with runtime-generated data based on the schema, it looks like it also was developed for the browser environment rather than for the test one. Also right now it is not possible to get a specific response for a specific endpoint in a test environment. You can do it by adding ?response={response_code} query parameter but this doesn't work for tests of course.

I'm not even sure if should we ask for a plugin from your side or if should it be some additional functionality provided by MSW Source package. But from my side what I'd like to have from the plugin:

  • Support file generation based on the API schema of handlers. (200 status is always a default one that is sent)
  • Support generation of the factory-like function to create responses described in the OpenAPI schema. For example UserCreateUnauthorizedResponse etc. Why should it be a factory? Because one response object can't be read twice. You can see this issue for more info Generated HAR handlers cannot respond to the same URL more than once mswjs/source#66
  • TypeScript support.

File as output is the main feature I guess, because it simplifies debugging and you can change it, while in runtime you can't do anything.

@mrlubos

@mrlubos
Copy link
Member

mrlubos commented Feb 12, 2025

@mkeyy0 just want to say I appreciate these comments! Noted and will be taken into consideration. There's a draft pull request with the MSW plugin btw if you haven't seen, slowly working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 🚀 New feature or request needs info ⏳ Further information is required RSVP 👍👎 Explicit request for reactions to gauge interest in resolving this issue
Projects
None yet
Development

No branches or pull requests

3 participants