-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
vi.mock not working in browser mode with test files outside of root #7595
Comments
Did you try locally instead of stackblitz? Probably it won't work on stackblitz because of service worker or maybe for other reasons. |
Yes, of course. I tried so many things in my local. stackblitz is a minimal reproduction I just created. |
I tried your repro locally and it's working for me, for example with playwright/chromium export default defineConfig({
test: {
browser: {
provider: 'playwright',
// provider: 'webdriverio',
enabled: true,
instances: [
{ browser: 'chromium' },
// { browser: 'chrome' },
],
},
},
}); $ pnpm test
> @vitest/example-test@ test /home/hiroshi/Downloads/vitest-dev-vitest-pywprx8q
> vitest
DEV v3.0.7 /home/hiroshi/Downloads/vitest-dev-vitest-pywprx8q
✓ chromium test/basic.test.ts (1 test) 1ms
✓ basic mock
Test Files 1 passed (1)
Tests 1 passed (1)
Start at 13:54:52
Duration 1.49s (transform 0ms, setup 0ms, collect 137ms, tests 1ms, environment 0ms, prepare 214ms)
|
mmm I see, welp if the config is correct and it is supposed to work locally, I'll try to create another minimal repro in my local from scratch, since it does not work in my project. |
I found out when it's not working. I had in my project's vite config values for export default defineConfig({
root: './src',
test: {
include: ['../test/**/*.test.ts'],
browser: {
provider: 'playwright',
// provider: 'webdriverio',
enabled: true,
instances: [
{ browser: 'chromium' },
// { browser: 'chrome' },
],
},
},
}); Is that a bad configuration on my part? or is it still supposed to work like that? I can't remember why I have it configured like that... maybe it needed |
I'm not sure if there's a reason mock cannot work with this setup. I'll treat it as a bug for now. |
👋 Running into the same issue here on our project. Our app is a monorepo using npm workspaces so we run tests against each of our teams packages. @hi-ogawa do you have any ideas for workaround here until this gets patched? |
👋 @hi-ogawa Here's a really simplified repro https://github.com/bteng22/nx-vitest-monorepo I wasn't able to build it on stackblitz since the NX Daemon had issues on it. When you run Is there any workarounds you can suggest here? This one been a big blocker for a lot of work on our team! Thanks for your help. |
Tagging @sheremet-va as well to escalate this! Our project is in the middle of a migration from Jest to Vitest and we're completely blocked at the moment. Any guidance here would be really helpful. Thank you! |
Thanks for the repro. I took a look and that's slightly different condition than OP's repro, but I assume the cause is same. |
@bteng22 Hmm, I just tested the latest Vitest 3.1.0 and it looks working now. Can you test it? (Tested the OP's repro with the latest and that one seems still broken). |
I have also issue with this setup. After going to 3.1.0 it started working when I run my test file individually. |
@hi-ogawa Hmm still not working for me 😞 Here's the commit to update to The add function below is still the original and not a Vitest spy.
|
@arkadiy93 Please provide a reproduction for us to take a look (just like error said) 🙏 |
Describe the bug
I read it was implemented, but I can't get it to work. It works as expected when run in node though.
Is there a special configuration required that I haven't found in the docs?
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-pywprx8q?file=vite.config.ts
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: