-
-
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
process.chdir() is not supported in workers (--no-threads doesn't work) #1436
Comments
Does it work with |
Thanks for the quick reply! I haven't tried with jest, I don't have it set up at the moment, I haven't used it in a while :) Mocking won't help in my case because I needed this to run some CI tests, I will just use It is surprising and confusing though, maybe we should document it more clearly? |
My quick attempt at trying the same with |
I guess stackblitz doesn't support Jest.
Why is it confusing? I thought it was a common knowledge that we run tests in worker. I think we can try forward calling |
I tried locally with jest and it works as expected both in ESM and CJS. I can
I was hoping for an option to run code in the main thread like the old |
We don't provide this option, so tests won't have access to the same global space as Vitest internals and server. |
It's reasonable. Thanks for your help! |
I am converting jest specs to vitest. |
So what's the path forward here? Simply not using The use case we currently support in many packages is creating a tmp dir or npm package using something like This seems like a reasonably common usage, and we were previously using I understand that this is a larger issue with threads and changing directories, but it seems like we could collectively figure out a solution. |
We cannot migrate this package to vitest yet, until the following issue is resolved: vitest-dev/vitest#1436
Is there a way to turn of workers for a file? |
Closed my duplicate issue in favour of this one. At the very least this limitation should be called out on the jest migration guide IMO, but obviously it would be even better to have some kind of official path forward on this! Lerna makes extensive use of changing directory in its jest tests that I’d love to use vitest for |
How about an option to use |
@sheremet-va would the core team be willing to accept a PR to add an option that enables to run tests in main thread without going through tinypool. I was trying to utilise vitest to build a runtime test suite system for an internal project, where I would need the test to run in process so it can access the system in runtime, and this would be a requirement then. |
I already tried it, but communication was really slow: #1790 You can tackle it, if you want. |
Q: When Vitest workspaces are used, is there a way to set |
@koistya you can mock it in your setup files: vi.spyOn(process, 'cwd').mockReturnValue('/path/you/want') Please, next time open a discussion instead of commenting in closes issues. |
Describe the bug
When I try to call
process.chdir
in a test, I get "TypeError: process.chdir() is not supported in workers". From #566 I understand the solution is passing--no-threads
but it doesn't seem to work.Reproduction
https://stackblitz.com/edit/node-ve8ywd?file=package.json
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: