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

Local interceptors not working when using vi.mock in Vitest browser mode #537

Open
2 tasks done
diego-aquino opened this issue Jan 25, 2025 · 2 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@diego-aquino
Copy link
Member

Prerequisites

  • I confirm that none of the open issues match my problem
  • I confirm that the documentation does not cover a solution to problem

Operating system

Ubuntu 24.04

Runtime

Node.js

Runtime version

22.13.1

Zimic version

0.12.3

Reproduction repository

https://github.com/diego-aquino/zimic-vi-mock-issue

Reproduction steps

  1. pnpm install
  2. pnpm test

Current behavior

The example test contains a simple fetch and a corresponding interceptor. However, the fetch fails with a network error. The problem appears to be related to using vi.mock, because commenting that line makes the test pass.

I suspect the cause are the changes introduced in the latest version of MSW. Vitest browser comes with an embedded MSW instance, likely used to mock imports when vi.mock is applied. However, Zimic's internal MSW version is not the latest because not all of our tests pass due to mswjs/msw#2146.

Expected behavior

Zimic should be able to intercept requests even if vi.mock is being used. We'll probably have to upgrade MSW to its latest version in #423. To fix the failing tests, we can use a tool such as patch-package to patch mswjs/msw#2146 with a workaround, while it is not fixed in MSW itself.

@diego-aquino diego-aquino added bug Something isn't working needs triage labels Jan 25, 2025
@diego-aquino diego-aquino changed the title Interceptors not working when using vi.mock in Vitest browser mode Local interceptors not working when using vi.mock in Vitest browser mode Jan 25, 2025
@diego-aquino diego-aquino self-assigned this Jan 25, 2025
@diego-aquino diego-aquino moved this to In progress in Zimic Jan 25, 2025
@diego-aquino diego-aquino added this to the v0.12.4 milestone Jan 25, 2025
@diego-aquino
Copy link
Member Author

@diego-aquino diego-aquino removed this from the v0.12.4 milestone Jan 25, 2025
@diego-aquino diego-aquino moved this from In progress to To do in Zimic Jan 25, 2025
@diego-aquino diego-aquino added the blocked Blocked label Jan 25, 2025
@diego-aquino diego-aquino moved this from To do to Blocked in Zimic Jan 25, 2025
@diego-aquino diego-aquino removed the blocked Blocked label Jan 25, 2025
@diego-aquino
Copy link
Member Author

Since remote interceptors do not use MSW, they are not affected by this issue. Changing from a local to a remote interceptor serves as a current workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Blocked
Development

No branches or pull requests

1 participant