question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support jest-like `moduleNameMapper` in vitest

See original GitHub issue

Clear 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

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

3reactions
zthxxxcommented, Jul 12, 2022

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 also vitest.config.ts with resolve.alias, but nothing works.

With resolve.alias, the reason maybe vite use @rollup/plugin-alias which use @rollup/plugin-node-resolve cannot make alias for sub-dependencies with PNPM.

2reactions
sheremet-vacommented, Jul 12, 2022

@sheremet-va such as replace xxx/es/ to xxx/lib which are NO need in “vite dev / build” but ONLY need in testing phase

Use process.env.VITEST or mode === 'test' to distinguish between test and dev env.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found