Skip to content

watchExclude option doesn't work for code in node_modules in some cases #4785

@Jinjiang

Description

@Jinjiang

Describe the bug

From what I tried so far, the watchExclude for code in node_modules option doesn't work when:

  • the environment is node.
  • the environment is jsdom and
    • the first time you edit the main file of a node module, or
    • every time you edit a non-main file of a node module

More discussion info: #4772 (reply in thread)

Reproduction

https://github.com/Jinjiang/reproductions/tree/vitest-watch-node_modules-20231220

pnpm install

# you can switch environment between 'node' (default value) and 'jsdom'
pnpm test

# in 'node' environment:
#
# modify any code in node_modules
# - the test is not re-run

# in 'jsdom' environment:
#
# modify code in node_modules/foo-cjs/index.js or node_modules/foo-esm/index.js
# - when you first time modify it, the test is not re-run
# - when you further modify it, the test is re-run
#
# modify code in node_modules/foo-cjs/foo.js or node_modules/foo-esm/foo.js
# - the test is not re-run

The expected behavior is that the test is always re-run when any code in node_modules/foo-cjs and node_modules/foo-esm is modified whatever the environment is.

System Info

System:
    OS: macOS 14.3
    CPU: (8) arm64 Apple M1
    Memory: 88.61 MB / 8.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.1.0 - ~/.asdf/installs/nodejs/20.1.0/bin/node
    Yarn: 1.22.19 - ~/.asdf/shims/yarn
    npm: 9.6.4 - ~/.asdf/plugins/nodejs/shims/npm
    pnpm: 8.12.0 - ~/Library/pnpm/pnpm
  Browsers:
    Safari: 17.3
  npmPackages:
    vite: ^5.0.10 => 5.0.10 
    vitest: ^1.0.4 => 1.0.4

Used Package Manager

pnpm

Validations

Metadata

Metadata

Assignees

Labels

p3-minor-bugAn edge case that only affects very specific usage (priority)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions