How can I configure Vitest to be able to run tests from a package folder in a monorepo?

34 Views Asked by At

I'm using Vitest in my monorepo (pnpm workspaces + tsc composite projects) and when I want to execute a test from the root directory it works:

npx vitest run -t "My test name"

but as soon as I cd into a folder, like cd packages/some-package and try to do the same I get an error:

➜ npx vitest run -t "Given a Config loader"

 RUN  v1.4.0 /home/addamsson/projects/larisel/packages/shared

 ↓ utils/test/config/ConfigLevelComparator.spec.ts (8) [skipped]
 ❯ utils/test/config/ConfigLoader.spec.ts (0)
 ❯ utils/test/config/configuration.spec.ts (0)

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Failed Suites 2 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 FAIL  utils/test/config/ConfigLoader.spec.ts [ utils/test/config/ConfigLoader.spec.ts ]
 FAIL  utils/test/config/configuration.spec.ts [ utils/test/config/configuration.spec.ts ]
Error: Failed to load url @shared/utils (resolved id: @shared/utils) in /home/addamsson/projects/larisel/packages/shared/utils/test/config/test/config.ts. Does the file exist?
 ❯ loadAndTransform ../../node_modules/.pnpm/[email protected]_@[email protected]/node_modules/vite/dist/node/chunks/dep-jvB8WLp9.js:53736:21

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/2]⎯

 Test Files  2 failed | 1 skipped (3)
      Tests  8 skipped (8)
   Start at  15:35:33
   Duration  1.15s (transform 486ms, setup 0ms, collect 437ms, tests 0ms, environment 0ms, prepare 717ms)

The URL it resolves to:

/home/addamsson/projects/larisel/packages/shared/utils/test/config/test/config.ts

exists so I don't know what the problem is.

The reason I need this is that I have a VSCode extension that CDs into the folder in which I have the test I'm trying to execute and I have no way to configure it.

0

There are 0 best solutions below