vitest-dev / vscode

VS Code extension for Vitest
https://vitest.dev/vscode
MIT License
758 stars 85 forks source link

Vitest extension doesn't rerun tests when test files change #483

Open Igor-Vuk opened 1 month ago

Igor-Vuk commented 1 month ago

Describe the bug

When test files change, Vitests extension doesn't rerun them. The only way to rerun tests files and get new data is to click "Refresh tests" and then "Run tests" on every change inside test files. In terminal tests are rerunning normally on files save. I uploaded a short video

https://github.com/user-attachments/assets/17589783-8a98-4094-bc0a-a95d6b5a078e

Reproduction

Write any type of tests and run them

Output

.

Version

1.2.12 published 2024-09-30

Validations

olafure commented 1 month ago

Confirmed. I think this is related to #472 which was probably closed in error. This is not an vscode error like someone suggested, since 1.0.7 works. I think 1.2.0 might be OK too.

Igor-Vuk commented 1 month ago

just tried the latest release 1.2.13. Same thing. And there is no coverage report also.

olafure commented 1 month ago

I don't know if it's the root cause, but https://github.com/vitest-dev/vscode/blob/e0ea18511d80eb68a78e783d76479922dcc57967/src/api.ts#L142 is returning stale cache. If I create a new test file then it doesn't get included in the file list.

neoscrib commented 1 month ago

My entire team has downgraded to version 1.2.6 to work around this issue. It has its own issues, but better than having to click the refresh button in test explorer after every little change to a test file or SUT file.

LaurentMag commented 1 month ago

i will add my voice here, its clearly an issue and having to reload at every change is not the most ideal thing..

sheremet-va commented 1 month ago

Cannot reproduce with the reproduction you've provided. Note that you didn't fill the issue template correctly since the "Output" is empty.

github-actions[bot] commented 1 month ago

Hello @Igor-Vuk. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

sheremet-va commented 1 month ago

If I create a new test file then it doesn't get included in the file list.

This should be fixed by https://github.com/vitest-dev/vscode/commit/6e2f2c459ccd36754d352d46bda6425888ef088a

sheremet-va commented 1 month ago

In 1.2.15 I added some logs in the watcher if vitest.logLevel (can be configured in settings) is set to debug. If you cannot provide a reproduction, at least give me the output.

KirkJohnson commented 1 month ago

I have 1.4.4 installed and this still happens. Everytime I had a new test to a test file I ran previously it doesn't recognize the test is there I have to reload in order for extension to recognize new test.

ffMathy commented 1 month ago

We've had issues like this for ages. But I don't want to report it because there's no way I can make a repro, and so it'll just be closed.

Our developers have to reload VS Code like 10 times a day.

We are in the process of trying to switch to another test extension, but others are unstable too. We hope switching to Deno 2.0 will help, or perhaps even Bun when they finish their extension.

I hope someone finds a root cause. I wonder how many are secretly having this issue.

sheremet-va commented 1 month ago

I will reopen this to keep track of the issue.

Our developers have to reload VS Code like 10 times a day

Just an FYI, you don't need to restart the extension, you can press "Refresh Tests" button

Screenshot 2024-10-07 at 15 33 32

You can help debug this issue by setting vitest.logLevel to verbose and reporting the output. If you don't have a reproduction, reporting the output still helps find the issue

ffMathy commented 1 month ago

Refresh tests doesn't work for us. It simply doesn't do anything.

It does at first, but not after you've either run a test once or debugged a test once.

I'll try the debug option you provided to see if I can share more details.

sheremet-va commented 1 month ago

The refresh button calls vitest.close - it's possible that it gets stuck waiting for the test to finish collecting or there is a hanging process with your setup. To collect the test, the extension actually runs the test files but doesn't execute the test functions. How long does it take to run this command with a single file in your repo: vitest run {name_of_the_test} -t '~~'? (Note that -t will make so that all tests are skipped).

sheremet-va commented 1 month ago

1.6.0 adds an option vitest.experimentalStaticAstCollect to use AST parser to collect tests instead of running the files. This should help if your tests take a long time to import which causes a visible hang. This version also fixes a bug when watcher stopped working after pressing "Refresh Tests"

I wasn't able to reproduce the hanging "refresh tests" button yet even when there is an infinite loop in the test file 🤔

ryaninvents commented 3 weeks ago

This issue is affecting me using version 1.6.0. "Refresh tests" works for me, but it takes a while since there are many tests in our repo. "Continuous Run" does not work. If it helps, I'm in a pnpm monorepo, but the tests that I'm trying to use this extension for are all contained to one package (i.e. the test files and the code I am testing are all in the same package, and I'm trying to trigger a re-run by editing code in that same package).

I'll see if I can post a minimal repro later today.

trydofor commented 3 weeks ago

"Continuous Run" does not work.

for me, Start Continuous Run by step 1,2,3 works few time, or only at startup, the toggle of console.log line can be refreshed. and Refresh tests also works but takes long time.

image

watching, but not refresh the test when toggling the line

[INFO 11:15:19 AM] Running 1 file(s) with name pattern: ^\s?map and object json map and obj$
[INFO 11:15:26 AM] Running 1 file(s) with name pattern: ^\s?map and object json map and obj$
[INFO 11:15:28 AM] [RUNNER] Watching test files: layers/common/tests/safe-converter.test.ts with pattern ^\s?map and object
[INFO 11:15:33 AM] Running 1 file(s) with name pattern: ^\s?map and object json map and obj$
[INFO 11:15:37 AM] [RUNNER] Watching test files: layers/common/tests/safe-converter.test.ts with pattern ^\s?map and object
[INFO 11:15:40 AM] Running 1 file(s) with name pattern: ^\s?map and object json map and obj$
sheremet-va commented 2 weeks ago

If you have issues with this, I recommend enabling vitest.logLevel: 'verbose' and posting your "Output" here so I can analyse what goes wrong. I will need the whole Output, not just the part you think is relevant. I validate that the whole output is given by the first line (it prints the version of the extension and path to Node.js). If you think there is sensitive information there, you can replace it with **

trydofor commented 2 weeks ago

If you have issues with this, I recommend enabling vitest.logLevel: 'verbose' and posting your "Output" here so I can analyse what goes wrong. I will need the whole Output, not just the part you think is relevant. I validate that the whole output is given by the first line (it prints the version of the extension and path to Node.js). If you think there is sensitive information there, you can replace it with **

all output are these lines

[INFO 11:17:56 PM] [v1.6.1] Vitest extension is activated because Vitest is installed or there is a Vite/Vitest config file in the workspace.
[INFO 11:18:00 PM] [API] Running Vitest v2.1.3 (common/vitest.config.ts) with Node.js@v20.18.0: ~/.asdf/shims/node 
[INFO 11:18:01 PM] [API] Running Vitest v2.1.3 (mobile/vitest.config.ts) with Node.js@v20.18.0: ~/.asdf/shims/node 
[INFO 11:18:28 PM] [API] Vitest v2.1.3 (mobile/vitest.config.ts) child process 44023 created
[INFO 11:18:28 PM] [API] Vitest v2.1.3 (common/vitest.config.ts) child process 43958 created
[INFO 11:18:29 PM] [VSCODE] Watching professional-razor with pattern **/*
[INFO 11:19:36 PM] [API] Collecting tests: layers/common/tests/safe-converter.test.ts
[INFO 11:19:42 PM] [TEST] <Suspense> is an experimental feature and its API will likely change.

[INFO 11:20:17 PM] Running 1 file(s) with name pattern: ^\s?safeSetArr
[INFO 11:20:32 PM] Running 1 file(s) with name pattern: ^\s?safeSetArr