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.

process.chdir() is not supported in workers (--no-threads doesn't work)

See original GitHub issue

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

System:
  OS: Linux 5.4 Linux Mint 20.3 (Una)
  CPU: (8) x64 Intel(R) Core(TM) i7-3630QM CPU @ 2.40GHz
  Memory: 3.70 GB / 15.52 GB
  Container: Yes
  Shell: 5.0.17 - /bin/bash
Binaries:
  Node: 18.2.0 - /usr/local/bin/node
  Yarn: 1.22.11 - ~/.npm-global/bin/yarn
  npm: 8.5.1 - ~/.npm-global/bin/npm
Browsers:
  Chrome: 102.0.5005.61
  Firefox: 101.0
npmPackages:
  vitest: ^0.13.1 => 0.13.1

Used Package Manager

pnpm

Validations

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:14 (9 by maintainers)

github_iconTop GitHub Comments

10reactions
scalvertcommented, Jul 19, 2022

So what’s the path forward here? Simply not using process.chdir doesn’t seem like a reasonable forward path.

The use case we currently support in many packages is creating a tmp dir or npm package using something like fixturify-project, and use that directory as a fixture for tests. At the end of the test, we dispose of the test directory, which requires us to switch directories before to support OS tests such as windows-latest, which will error if you try to rm a directory when it’s the current dir.

This seems like a reasonably common usage, and we were previously using --no-threads with vitest when we needed to support this scenario. Now that --no-threads no longer works for this use case, there doesn’t seem to be a workaround.

I understand that this is a larger issue with threads and changing directories, but it seems like we could collectively figure out a solution.

0reactions
sheremet-vacommented, Nov 18, 2022

@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: https://github.com/vitest-dev/vitest/pull/1790 You can tackle it, if you want.

Read more comments on GitHub >

github_iconTop Results From Across the Web

process.chdir is not available in workers · Issue #566 - GitHub
TypeError : process.chdir() is not supported in workers. Is there a way to opt certain tests to not run in a worker?
Read more >
Process.chdir() has no effect on require - Stack Overflow
I'd like to be able to trick require into thinking that the current working directory is the project root. The example above does...
Read more >
Node.js process.chdir() Method - GeeksforGeeks
The process.chdir() method is an inbuilt application programming interface of the process module which is used to change the current working ...
Read more >
z/OS UNIX reason codes - IBM
The rmdir service vnode operation is not supported. Action: Verify that the operation was performed on a physical file system that supports the...
Read more >
uWSGI Options — uWSGI 2.0 documentation - Read the Docs
parser : uwsgi_opt_set_int. help : spawn the specified number of workers/processes ... help : do not enable harakiri during after-request-hook ...
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