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

Allow for the Intercepters to be treated as a plugin (Pretender, MSW) #1037

Open
3 of 5 tasks
cah-brian-gantzler opened this issue Apr 23, 2022 · 13 comments
Open
3 of 5 tasks

Comments

@cah-brian-gantzler
Copy link
Collaborator

cah-brian-gantzler commented Apr 23, 2022

Currently the interceptor is Pretender and it is pretty hardcoded. The intent is to isolate the Interceptor code into its own configuration, then move it to its own package to allow for other interceptors to be specified.

Currently the main entry point to the interceptor code is on the server (the get, put, post, etc methods) and the server is the this then the routes are configured. The goal would be to move these methods to the interceptor code and off the server.

Tasks

  • Move Pretender to its own config. Allow for a way to provide an alternate interceptor. Provide full backward compatibility and make Pretender the default interceptor. Extract pretender code to its own module for future move to another package #1036
  • Move the pretender code to its own package. (currently in progress see mirage-pretender)
  • Create a package that allows MSW to be used as an interceptor with Mirage. (Currently in progress see mirage-msw)
  • Remove the Pretender code from MirageJS and require the user to choose the interceptor (Pretender, MSW, or none). This will be a breaking change in MirageJS.
  • Move the interceptor creation methods (get, put, post, etc) to the interceptor config and make the interceptor config the this when the routes function is run. The Mirage Server will be supplied as a property on the config. For most users this should not be a breaking change, but more advanced uses this could be.
@IanVS
Copy link
Collaborator

IanVS commented Apr 26, 2022

@samselikoff do you see any glaring issues with this plan? It seems reasonable to me.

@samselikoff
Copy link
Contributor

Plan seems good and in fact this was the road we were headed down in https://github.com/miragejs/miragejs/pull/699/files I believe... simplifying the main Mirage server api to be server.handle(request) and then letting folks do whatever they want with it.

Honestly it might be better to remove a hard-coded interceptor altogether and just let Mirage be concerned with turning a request into a response (and making sure it can run in both the browser and node). Then people can use pretender, MSW, even express.

@cah-brian-gantzler
Copy link
Collaborator Author

Honestly it might be better to remove a hard-coded interceptor altogether and just let Mirage be concerned with turning a request into a response (and making sure it can run in both the browser and node). Then people can use pretender, MSW, even express.

The hard coded interceptor has already been removed to another repo. I just didnt remove it yet from miragejs as it would be a breaking change. But that is on the roadmap above, the 4th checkbox

@IanVS
Copy link
Collaborator

IanVS commented Jun 1, 2022

@samselikoff what do you think about making @cah-briangantzler a collaborator? He's doing more work on this package than anyone else at this point, and while I'm happy to keep reviewing and helping out as I can, I don't want to be a bottleneck to the progress that Brian is making.

@cah-brian-gantzler
Copy link
Collaborator Author

Im actually a collaborator on ember-cli-mirage where this repo originated. The work I'm doing there has been spilling over into this one. But I like to have another set of eyes, would prefer to not be the only one 😄

@samselikoff
Copy link
Contributor

Of course he can be a collab here I thought he already was! I definitely don't want to be anyone's bottleneck just because I don't have the cycles to work on this anymore 👍

@henrymoulton
Copy link
Contributor

@cah-brian-gantzler is this still active? Is MirageJS still active? I'm using it on a project and running into some issues.

@IanVS
Copy link
Collaborator

IanVS commented Nov 9, 2023

It's minimally active, yes. The creator stepped away and a few of us have been trying to keep the lights on.

MSW can indeed be used as an interceptor right now, using https://github.com/miragejs/mirage-msw. It's a bit rough, though, since msw starts up asynchronously, and everything thus far in mirage has been sync. So, to really get it working correctly we'll need to break some APIs I think.

@cah-brian-gantzler
Copy link
Collaborator Author

Yes, I created the initial support for MSW, but IanVS has been taking it to the next step improving it. Thanks IanVS.

@henrymoulton
Copy link
Contributor

Thanks for the replies both, I'll take a look at moving away from Pretender.

@IanVS
Copy link
Collaborator

IanVS commented Nov 9, 2023

I've added a readme to https://github.com/miragejs/mirage-msw, and published 0.1.2. Please open an issue there if you encounter any problems.

@nickschot
Copy link

Since there's been some activity on this, I've been working on a mirage-playwright interceptor in a similar vein to support Mirage use in Playwright tests. Should hopefully be open source soon.

@IanVS
Copy link
Collaborator

IanVS commented Jun 19, 2024

Status update: I've changed over my own non-trivial app to use mirage-msw, and it seems to be working well.

There are new alpha versions of miragejs published in order to support the async-startup needs of msw. So, if you want to try out mirage-msw, I recommend using at least the following versions:

  • miragejs: 0.2.0-alpha.2
  • mirage-msw: 0.2.2
  • msw: 2.0.0

It's still definitely experimental, but I think it's ready for a bit of alpha testing if anyone else is interested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants