Replies: 1 comment 2 replies
-
The issue is not with static analysis, it's about the transform that would move |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am wondering if it'd be possible to extend the static analysis that checks for
import {vi} from "vitest"
to also detectconst {vi} = import.meta.vitest
.Currently, as far as I understand, module mocking for in-source tests requires
globals: true
or a top-level ESM import of Vitest. Globals can be problematic, esp. with TypeScript, and importing directly from Vitest in a source file may require finicky build step configuration to avoid emitting that call into a prod deployment.Since
const {...} = import.meta.vitest
is already the in-source testing equivalent ofimport {...} from "vitest"
for all other purposes than access tovi.mock()
, I would be very happy if that last gap could be filled.To add some details about our use case: We use in-source testing primarily to test module-internal helpers, with the intent of avoiding
export
ing these helpers solely to test them. Sometimes, however, such helpers exist because they're wrapping a more general/complex API defined in another module. For the sake of keeping unit tests as encapsulated as possible, we want to mock that external module while testing.Beta Was this translation helpful? Give feedback.
All reactions