Persisting data across multiple requests & service worker updates
See original GitHub issueIs your feature request related to a problem? Please describe. Suppose I create an account (via the mocks) and want to log out and log back in as the new user. Is there an elegant way to persist that newly created data using MSW?
Describe the solution you’d like
I think whatever solution should be agnostic to the storage method used, whether it’s a plain variable, an in-memory DB, or something else. I was thinking the most agnostic and simplest way to go about doing this is just to access whatever storage you may have when you execute your logic in the MSW routes (ex. inside rest.get
handler).
However, with the above approach, when the MSW worker is updated (ex. via Webpack hot reload), that state would be wiped in some cases.
Another approach to avoid the data reset would be to leverage the browser cache (via service worker, such as IndexedDB), but that wouldn’t be available on server side, which would be another problem.
Was hoping to get some thoughts on how to solve the issue of a persistent data store while using MSW mocks.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:14 (14 by maintainers)
Top GitHub Comments
This is going to be addressed in a separate library. Stay tuned for the upcoming announcements.
PR for readme created (and looks linked correctly above…)
I also tried to add a test case for the readme example - but the test fails, because
BroadcastChannel
is not available in Node nor jsdom => see https://github.com/mswjs/live-storage/compare/master...Aprillion:test?expand=1