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

Extension discovers tests but does not run them when Vitest is installed above the root #308

Closed
6 tasks done
roryschadler opened this issue Mar 19, 2024 · 8 comments
Closed
6 tasks done
Labels
p4-important Violate documented behavior or significantly improves performance (priority)

Comments

@roryschadler
Copy link

Describe the bug

I have a monorepo1 which has two components, a Python tool and a TypeScript project. I've installed vitest in the TypeScript project, which isn't the root of the repo, and when vitest is run from the command line in that subdirectory, it works fine.

This extension does discover the tests just fine2, but will not run them if I click the run button on the top level of the tree (typescript-project in the screenshot below).

It will run them if I click the run button for client or server, which I've confirmed by setting up a side effect for the test and seeing it occur. But it will not report the test results in this case.

I'm running the latest pre-release version of this extension (0.5.6 as of now). Thank you all for looking into this, I really appreciate it!

Reproduction

https://github.com/roryschadler/vitest-non-root-monorepo

System Info

...vitest-non-root-monorepo/typescript-project % npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*}' --binaries --browsers --IDEs

  System:
    OS: macOS 14.3.1
    CPU: (10) arm64 Apple M1 Max
    Memory: 377.92 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.6.1 - ~/.nvm/versions/node/v20.6.1/bin/node
    Yarn: 3.6.3 - ~/.nvm/versions/node/v20.6.1/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v20.6.1/bin/npm
  IDEs:
    Emacs: 29.2 - /opt/homebrew/bin/emacs
    VSCode: 1.87.2 - /usr/local/bin/code
    Vim: 9.0 - /usr/bin/vim
    Xcode: /undefined - /usr/bin/xcodebuild
  Browsers:
    Chrome: 122.0.6261.129
    Edge: 122.0.2365.92
    Safari: 17.3.1
  npmPackages:
    vitest: ^1.4.0 => 1.4.0 ```

Used Package Manager

yarn

Validations

Footnotes

  1. https://github.com/roryschadler/vitest-non-root-monorepo

  2. Screenshot 2024-03-19 at 1 24 26 PM

@sheremet-va sheremet-va added p4-important Violate documented behavior or significantly improves performance (priority) and removed pending triage labels Mar 20, 2024
@sheremet-va
Copy link
Member

Can you add steps on how to install dependencies in your reproduction, please. Currently I see this error when running yarn test in typescript-project folder:

Error: Cannot find package 'happy-dom' imported from /vitest-non-root-monorepo/typescript-project/node_modules/vitest/dist/vendor/index.GVFv9dZ0.js

@sheremet-va
Copy link
Member

Can you add steps on how to install dependencies in your reproduction, please

Fixed it. Turns out I had an old global yarn installed. The error should be fixed by 204d15b

@roryschadler
Copy link
Author

Thanks for the quick turnaround @sheremet-va! I confirm that v0.5.7 resolves almost all of this issue. The only remaining issue is

This extension does discover the tests just fine, but will not run them if I click the run button on the top level of the tree (typescript-project in the screenshot below above).

Would you like me to open a separate issue for that?

@sheremet-va
Copy link
Member

sheremet-va commented Mar 20, 2024

Oh, I didn't notice that, sorry. So, it doesn't run all tests or all in a folder?

@sheremet-va sheremet-va reopened this Mar 20, 2024
@roryschadler
Copy link
Author

As far as I can tell, it doesn't run any tests. I'd expect it to run all the tests under the typescript-project folder. Clicking run on the client or server level will run all tests under client or server respectively, as expected.

I've just pushed a commit to that reproduction, which adds a side-effect to one of the tests. When I click run on the server level, a file is created and test results are reported. When I delete that file, then click run on the typescript-project level, no file is created and no results are reported

@sheremet-va
Copy link
Member

sheremet-va commented Mar 20, 2024

Hm, this is actually a bug in Vitest:

Screenshot 2024-03-20 at 14 48 43

This happens because the filter checks the relative path, but typescript-project is outside of the root, so it becomes ../. Please open an issue in Vitest, - I am already working on a fix there.

@roryschadler
Copy link
Author

Ah, thanks for digging into that! I'll do that later today. Could you please share the underlying vitest command that's being run in your screenshot? I can't reproduce that error running just yarn test in vitest-non-root-monorepo/typescript-project.

@sheremet-va
Copy link
Member

sheremet-va commented Mar 20, 2024

I can't reproduce that error running just yarn test in vitest-non-root-monorepo/typescript-project.

I didn't change anything. You need to specify the full path to typescript-project with a slash at the end.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p4-important Violate documented behavior or significantly improves performance (priority)
Projects
None yet
Development

No branches or pull requests

2 participants