Configuring MockServiceWorker on O3 repos

Hi all,

I wanted to share an update regarding the enhancement of our O3 integration tests. Recently, we have discovered that we can improve the O3 integration tests by utilizing MockServiceWorker (MSW), a tool specifically designed for mocking API calls. Currently, I am in the process of configuring MockServiceWorker on the esm-admin-tools repository.

When we execute tests with MockServiceWorker, it intercepts the API calls specified in the handlers and replaces them with the predefined responses. Following the MSW documentation, I have configured it on the esm-admin-tools repository by implementing a sample handler through this pull request. For debugging purposes, I have enabled the option to list all unhandled request intercepts.

Unfortunately, I have encountered a problem with the implementation: it appears that none of the API requests are being intercepted.

I also had a discussion regarding this with @dkigen on the last dev standup call and the problem might be related to the openmrsFetch function. I’ll be further looking into fixing this issue. Any guidance or suggestions would be greatly appreciated. Thank you.

cc: @ibacher @dkigen @jayasanka @ayushmishra

We provide a mocks for calls to the framework in jest tests, including a mock for openmrsFetch, so there are no requests for the service worker to intercept.

Did you run into some issue that lead you to want to use this library? Is there some short-coming with our current approach?

Thank you for your response. The reason I explored using MockServiceWorker (MSW) was not due to any shortcomings in our current approach, but rather to explore potential advantages that MSW offers. I came across an article which highlighted the benefits of using MSW for mocking API calls.

With MSW, we can achieve advantages such as easier usage, reducing duplication of mock setup across tests, and having simpler and cleaner code. It provides a declarative way to define handlers and predefined responses, making it more intuitive and efficient to simulate API behavior.