-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
setupFiles does not import npm module correctly in mono repo project setup #2029
Comments
cc @sheremet-va |
Seems the problem happens here. vitest/packages/vite-node/src/utils.ts Lines 77 to 84 in 95da4d6
Isn't it weird |
@sun0day I can confirm that in my case the problem happens here. its a monorepo, the tests are running inside |
I think this issue may solve by setting {
test: {
// `vitest` use the outside dir as root, different from `vite`
root: resolve(__dirname, "../../")
}
} But now there are two problems:
For fix problem two, could solve by use But I'm not sure if this would cause other problems. |
@ChpShy I would consider that as a hack rather than a solution, as even though it would solve the resolution, it would also cause vitest to include all tests from other projects in the monorepo. A better hack (which I am using right now) is to create a local file inside the project, that internally imports the dependency, and use that in the |
Also, this behavior works in monorepo as expected with older version |
This should actually be fixed I think. Can you confirm it doesn’t work with the latest version? |
It's not fixed yet (or not fully fixed). I have monorepo with packages:
@repo/testing contains setup file: import { vi } from 'vitest'
console.log('init')
vi.mock('framer-motion', async () => {
console.log('mock')
const framer = await vi.importActual<object>('framer-motion')
return {
...framer,
AnimatePresence: ({ children }: { children: React.ReactNode }) => children,
}
}) In package Actual console.log for v0.23.4: stdout | unknown test
init
stdout | unknown test
mock Actual console.log for v0.25.3: stdout | unknown test
init So in fact for 0.25.3 file is imported but |
So how is this related to this issue? This issue is specifically about importing setupFile, but in your example mock is not called. If you have a different problem, please create a separate issue, if it doesn't already exist. I ran reproduction from this issue with the latest version and it's working fine, so I'm closing this issue. |
Describe the bug
I have a mono repo project, where I am trying to use vitest to test one of the monorepo packages. I need some polyfills in the environment and I am trying to loading this using
setupFiles
and mentioning the npm package name there. As far as I have read the configuration documentation, this should work. But unfortunately it fails.Seemingly the problem is with the path resolution, the path seems to have been resolved correctly, but then root is prefixed on this absolute path. Find attached screenshot from shared reproduction stackblitz
Reproduction
stackblitz minimal repro
npm run test
inpackages/package
.reflect-metadata
moduleSystem Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: