Skip to content

vitest related with barrel files #5009

@draco

Description

@draco

Describe the bug

I am trying to use vitest related with barrel files but it doesn't seem to be working and from the docs it's not exactly clear that it is a bug or not.

https://vitest.dev/guide/cli#vitest-related

This still seems like a static import (since the files are known at build time).

Reproduction

https://github.com/draco/test-barrels

  1. clone it
  2. npm install
  3. npm exec vitest related ./src/related.ts (detects)
❯ npm exec vitest related ./src/related.ts

 DEV  v1.2.1 /Users/s/Work/related-barrels

 ✓ src/related.test.ts (1)
   ✓ greet returns a greeting message

 Test Files  1 passed (1)
      Tests  1 passed (1)
   Start at  15:50:01
   Duration  209ms (transform 10ms, setup 0ms, collect 7ms, tests 1ms, environment 0ms, prepare 62ms)
  1. npm exec vitest related ./src/related.barrel.ts (doesn't detect)
❯ npm exec vitest related ./src/related.barrel.ts

 DEV  v1.2.1 /Users/s/Work/related-barrels

include: **/*.{test,spec}.?(c|m)[jt]s?(x)
exclude:  **/node_modules/**, **/dist/**, **/cypress/**, **/.{idea,git,cache,output,temp}/**, **/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build,eslint,prettier}.config.*
watch exclude:  **/node_modules/**, **/dist/**
No affected test files found

System Info

npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers


  System:
    OS: macOS 14.2.1
    CPU: (8) arm64 Apple M1
    Memory: 108.14 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - ~/Library/Caches/fnm_multishells/46014_1705649551291/bin/node
    Yarn: 1.22.21 - /opt/homebrew/bin/yarn
    npm: 9.5.1 - ~/Library/Caches/fnm_multishells/46014_1705649551291/bin/npm
    pnpm: 8.6.1 - ~/Library/Caches/fnm_multishells/46014_1705649551291/bin/pnpm
    bun: 1.0.23 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 120.0.6099.234
    Edge: 120.0.2210.144
    Safari: 17.2.1
  npmPackages:
    vite: ^5.0.8 => 5.0.11
    vitest: ^1.2.1 => 1.2.1

Used Package Manager

npm

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