Skip to content

2.0.5 breaks module mocking via __mocks__ folder #6262

@EvHaus

Description

@EvHaus

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions