Support jest-like `moduleNameMapper` in vitest
See original GitHub issueClear and concise description of the problem
Sometime we have to deal with non-standard third-party packages, such as replace xxx/es/
to xxx/lib
which are no need in “vite dev / build” so that CANNOT set with resolve.alias
but ONLY need in testing phase, and it’s also NOT satisfy vitest deps.fallbackCJS
mode.
Suggested solution
Maybe support some configuration like jest moduleNameMapper
.
Alternative
No response
Additional context
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that request the same feature to avoid creating a duplicate.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:15 (14 by maintainers)
Top Results From Across the Web
Configuring Vitest
Configuring Vitest #. Configuration #. vitest will read your root vite.config.ts when it is present to match with the plugins and setup as ......
Read more >`moduleNameMapper` settings in jest.config.js doesn't work ...
I have tested with my React-app in typescript, using ts-jest like below. import ...
Read more >jest over vitest - Brad Garropy
With jest , you can use the moduleNameMapper configuration to stub out different file extensions. This was useful for all types of images...
Read more >Testing Vite with minimal config using Vitest - LogRocket Blog
Why Vitest, and how does it compare to tools like Jest? ... moduleNameMapper: { // stub out CSS imports per Jest's recommendation "\\....
Read more >From Jest to Vitest - Migration and Benchmark
This error comes from react-testing-library and it has to do with js-dom support of vitest. I'm going to look for some resources for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Because of the time, I want to try some way to bypass the problem before they fixed and publish a new version.
I have tried to use
deps.inline: true
(with install jsdom fixed the error above) and alsovitest.config.ts
withresolve.alias
, but nothing works.With
resolve.alias
, the reason maybevite
use@rollup/plugin-alias
which use@rollup/plugin-node-resolve
cannot make alias for sub-dependencies with PNPM.Use
process.env.VITEST
ormode === 'test'
to distinguish between test and dev env.