-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Can't mock
or alias
module in browser mode when dependency is aliased (npm:[email protected]
)
#6483
Comments
This mocking error looks like a bug and not really related to What looks odd to me is I see these two requests on devtools and probably the 2nd one again exporting // http://localhost:5173/node_modules/.vite/deps/date-fns_addHours.js?t=1726706677742&v=fa62991a
const module = globalThis["__vitest_mocker__"].getFactoryModule("/node_modules/.vite/deps/date-fns_addHours.js");
export const addHours = module["addHours"]; // http://localhost:5173/node_modules/.vite/deps/date-fns_parse.js?t=1726706677742&v=fa62991a
const module = globalThis["__vitest_mocker__"].getFactoryModule("/node_modules/.vite/deps/date-fns_parse.js");
export const addHours = module["addHours"]; |
Hi @hi-ogawa, thanks for the PR, it solved the issue when using But there is still the case with resolve: {
alias: [
{
find: 'date-fns',
replacement: 'date-fns-v3',
customResolver(source, importer, options) {
if (importer?.includes('DateFnsV3')) return source
return null
},
}
]
}, |
@JCQuintas I haven't look deeply into that one (though I'm guessing there's some limitation with |
Describe the bug
Hello, we are trying to understand what would take to migrate into vitest on our repositories at MUI, both for browser and jsdom testing.
And we encountered an issue in regard to aliased dependencies.
We currently have the following in our package
This is due to the different signatures between these two versions. In the final code, this is a peer dependency, so inside our code we only always use
import from 'date-fns'
.But when testing, we want to test the actual library, which requires some aliasing.
I've tried with both
config.alias
andvi.mock
and they both work on jsdom, but not on browser.Reproduction
https://github.com/JCQuintas/vitest-browser-alias-mock
Important Files
Ensure you uncomment one of the comments in these files to test
Running
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: