Skip to content

process.chdir is not available in workers #566

@NullVoxPopuli

Description

@NullVoxPopuli

Describe the bug

if you're testing node utilities, maybe ones that help interact with the file system, and you need to call chdir, there is no way to test that behavior because all tests run in node workers, which aren't allowed to call process.chdir

Reproduction

it('repro', () => {
  process.chdir('anywhere')
}

raises:

TypeError: process.chdir() is not supported in workers

Is there a way to opt certain tests to not run in a worker?
otherwise I'd need to test anything that uses chdir, in mocha or something.

System Info

System:
    OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
    CPU: (6) x64 Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz
    Memory: 7.69 GB / 16.18 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 16.13.2 - ~/.volta/tools/image/node/16.13.2/bin/node
    Yarn: 1.22.17 - ~/.volta/tools/image/yarn/1.22.17/bin/yarn
    npm: 7.24.2 - ~/Development/NullVoxPopuli/ember-apply/node_modules/.bin/npm
  Browsers:
    Chrome: 97.0.4692.71
    Firefox: 96.0


### Used Package Manager

yarn

### Validations

- [X] Follow our [Code of Conduct](https://github.com/vitest-dev/vitest/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitest-dev/vitest/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitest.dev/guide).
- [X] Check that there isn't [already an issue](https://github.com/vitest-dev/vitest/issues) that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitest-dev/vitest/discussions) or join our [Discord Chat Server](https://chat.vitest.dev).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions