Skip to content
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

2.0.5 breaks module mocking via __mocks__ folder #6262

Closed
6 tasks done
EvHaus opened this issue Aug 1, 2024 · 0 comments · Fixed by #6266
Closed
6 tasks done

2.0.5 breaks module mocking via __mocks__ folder #6262

EvHaus opened this issue Aug 1, 2024 · 0 comments · Fixed by #6266

Comments

@EvHaus
Copy link
Contributor

EvHaus commented Aug 1, 2024

Describe the bug

After upgrading from 2.0.4 to 2.0.5 our tests which rely on module mocking via the __mocks__ folder are now failing with:

Error: ENOENT: no such file or directory, stat '/myproject/__mocks__/index.ts'

Reproduction

To reproduce this, you'll need:

  • A __mocks__ folder with the following structure:
    • __mocks__
      • /archiver
        • /index.ts
      • /ora
        • /index.ts
  • A test which uses one of the mocked modules (in this case archiver or ora) and calls vi.mock('ora')

It seems like (maybe after #6204) Vitest now expects the __mocks__ folder to have an index.* file, whereas before it wasn't needed.

For a StackBlitz repro see: https://stackblitz.com/edit/vitest-dev-vitest-snzivu?file=package.json,test%2Fbasic.test.ts,src%2Fbasic.ts&initialPath=__vitest__/. Run npm run test to reproduce.

System Info

System:
    OS: macOS 14.6
    CPU: (12) arm64 Apple M2 Max
    Memory: 1.99 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v20.16.0/bin/yarn
    npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
  Browsers:
    Chrome: 127.0.6533.89
    Chrome Canary: 129.0.6631.0
    Safari: 17.6

Used Package Manager

yarn

Validations

@github-actions github-actions bot locked and limited conversation to collaborators Aug 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant