vscode icon indicating copy to clipboard operation
vscode copied to clipboard

Vitest extension doesn't rerun tests when test files change

Open Igor-Vuk opened this issue 1 year ago • 32 comments

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

Igor-Vuk avatar Sep 30 '24 23:09 Igor-Vuk

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.

olafure avatar Oct 01 '24 17:10 olafure

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

Igor-Vuk avatar Oct 01 '24 17:10 Igor-Vuk

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.

olafure avatar Oct 01 '24 17:10 olafure

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.

neoscrib avatar Oct 01 '24 20:10 neoscrib

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

LaurentMag avatar Oct 02 '24 05:10 LaurentMag

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

sheremet-va avatar Oct 02 '24 07:10 sheremet-va

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.

github-actions[bot] avatar Oct 02 '24 07:10 github-actions[bot]

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 avatar Oct 02 '24 08:10 sheremet-va

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.

sheremet-va avatar Oct 02 '24 08:10 sheremet-va

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.

KirkJohnson avatar Oct 11 '24 19:10 KirkJohnson

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.

ffMathy avatar Oct 12 '24 09:10 ffMathy

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

sheremet-va avatar Oct 12 '24 09:10 sheremet-va

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.

ffMathy avatar Oct 12 '24 10:10 ffMathy

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 avatar Oct 12 '24 11:10 sheremet-va

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 🤔

sheremet-va avatar Oct 12 '24 12:10 sheremet-va

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.

ryaninvents avatar Oct 17 '24 10:10 ryaninvents

"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.

  • pnpm monorepo
  • vitest.explorer 1.6.1
  • vitest 2.1.2
  • vscode 1.94.2

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$

trydofor avatar Oct 24 '24 02:10 trydofor

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 **

sheremet-va avatar Oct 25 '24 15:10 sheremet-va

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 [email protected]: ~/.asdf/shims/node 
[INFO 11:18:01 PM] [API] Running Vitest v2.1.3 (mobile/vitest.config.ts) with [email protected]: ~/.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

trydofor avatar Oct 25 '24 15:10 trydofor

This is my output:

[9:41:19 PM] [VSCODE] File changed: src\routes.db.test.ts
[INFO 9:41:19 PM] [Worker] Collecting tests due to file changes: src/routes.db.test.t
[9:41:19 PM] Not starting the runner because tests are being collected for src/routes.db.test.ts
[9:41:20 PM] Initiating deferred test run
[INFO 9:41:20 PM] Running 1 file(s) with name pattern: ^\s?POST /files should successfully upload a small file$
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\query_engine-windows.dll.node.tmp35616
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\index.d.ts
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\default.d.ts
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\default.js
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\edge.d.ts
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\edge.js
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\index-browser.js
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\index.js
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\package.json
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\wasm.d.ts
[9:41:21 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\wasm.js
[9:41:22 PM] There is no test run for "routes.db.test.ts [database]"
[9:41:22 PM] The runner is starting because tests src/routes.db.test.ts were started due to a file change
[9:41:22 PM] Enqueuing "should successfully upload a small file"
[9:41:22 PM] Ending test run src/routes.db.test.ts
[9:41:22 PM] [VSCODE] Ignoring file: node_modules\.vite\vitest\results.json
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\query_engine-windows.dll.node.tmp32152
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\index.js
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\default.d.ts
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\default.js
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\edge.d.ts
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\edge.js
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\index-browser.js
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\index.d.ts
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\package.json
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\wasm.d.ts
[9:41:24 PM] [VSCODE] Ignoring file: node_modules\.pnpm\@[email protected][email protected]\node_modules\.prisma\client\wasm.js
[9:41:26 PM] There is no test run for "routes.db.test.ts [database]"
[9:41:26 PM] There is no test run for "POST /files"
[9:41:26 PM] There is no test run for "should successfully upload a small file"
[9:41:26 PM] There is no test run for "should successfully upload a small file"
[9:41:27 PM] There is no test run for "should successfully upload a small file"
[9:41:27 PM] There is no test run for "POST /files"
[9:41:27 PM] There is no test run for "routes.db.test.ts [database]"
[9:41:27 PM] No test run to finish for src/routes.db.test.ts
[9:41:27 PM] [VSCODE] Ignoring file: node_modules\.vite\vitest\results.json
[9:41:27 PM] [VSCODE] Ignoring file: node_modules\.vite\vitest\results.json

hornta avatar Dec 04 '24 20:12 hornta

This is my output

Your output just confirms that your tests are reruning

sheremet-va avatar Dec 05 '24 08:12 sheremet-va

This is my output

Your output just confirms that your tests are reruning

Yes but I never observed the test run. No test results were shown and the test icon never changed to this yellow icon one normally gets when rerunning tests. I always have to wait around 4~ seconds after changing the file to trigger a test rerun.

hornta avatar Dec 05 '24 17:12 hornta

This is still happening on 1.14.3 Initially the extension works fine. If I change any test code and then try re-running the tests I see: Collecting tests due to file changes: path/to/changed_file

ShirajG avatar Feb 20 '25 21:02 ShirajG

This is still happening on 1.14.3 Initially the extension works fine. If I change any test code and then try re-running the tests I see: Collecting tests due to file changes: path/to/changed_file

Did you enable continuous run? The extension doesn't rerun tests automatically, you need to start watcher manually by clicking on the "eye" icon.

sheremet-va avatar Feb 21 '25 08:02 sheremet-va

I've been seeing the described behaviour (Continuous Run enabled, but tests not re-running on save) when I've had the Mocha Test Explorer extension enabled at the same time (a situation I ended up in working in a monorepo and trying to get relevant tests all working at the same time).

area avatar Mar 05 '25 17:03 area

I'm experiencing this issue too, it is making it hard to use the test runner over the command line. At least with command line I can focus on 1-2 files at a time during major refactors.

pzuraq avatar Mar 24 '25 15:03 pzuraq

Having the same problem here, too. Despite enabling Continuous Run, updating tests does not trigger a rerun. I'm on macOS.

ffxsam avatar Mar 24 '25 22:03 ffxsam

Not having the same problem here!

Provide more info:

  • logs
  • what you expect to happen
  • what you actually did
  • reproduction steps
  • what Node you are using
  • a screen recording
  • screenshots
  • do you have continues run enabled
  • reproduction repos

Percieved bug might be a different bug. Just adding "+1" does not help fix the issue. It is insane that people expect this issue to be fixed without providing any help.

I am unsubscribing from this thread and coming back in several weeks. No help = no fix, I am not a magician. If someone else wants to step in, be my guest.

sheremet-va avatar Mar 25 '25 06:03 sheremet-va

As a fellow open source maintainer, I get the frustration there and appreciate the effort. I will point out that +1s do not necessarily help diagnose, but they do help us figure out where things are broken the most - if it's got a lot of people reporting it, that's a higher priority. But again, I truly do understand the frustration, especially when it comes to heisenbugs like this.

I normally would provide more context, but am currently knee deep in trying to get some things shipped so didn't have time to dig in. If/when I have a chance I'll circle back and do some more digging. That's part of why I left the comment also, so I'll be reminded if others run into this.

pzuraq avatar Mar 25 '25 12:03 pzuraq

Expected: test to re run when file changed, and reflect with pass or fail icons in the editor. What actually happened: No passing icons showed, or changed, not matter fixing the test or making it fail.

minimal repo: https://github.com/fazulk/vitest-watch-bug

    OS: macOS 14.6.1
    CPU: (12) arm64 Apple M3 Pro
    Memory: 271.44 MB / 36.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.14.0 - ~/.local/state/fnm_multishells/26611_1744910863682/bin/node
    Yarn: 1.22.22 - ~/.local/state/fnm_multishells/26611_1744910863682/bin/yarn
    npm: 10.9.2 - ~/.local/state/fnm_multishells/26611_1744910863682/bin/npm
    pnpm: 10.6.3 - /opt/homebrew/bin/pnpm
    bun: 1.1.4 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 135.0.7049.85
    Edge: 133.0.3065.92
    Safari: 18.3

vitest output:

[INFO 10:42:39 AM] [Worker] Collecting tests due to file changes: src/dummy.test.ts
[10:42:39 AM] Not starting the runner because tests are being collected for src/dummy.test.ts
[10:42:39 AM] There is no test run for "dummy.test.ts"
[10:42:39 AM] There is no test run for "dummy.test.ts"
[10:42:39 AM] No test run to finish for src/dummy.test.ts
[10:42:39 AM] [VSCODE] Ignoring file: node_modules/.vite/results.json

Image

Image

@sheremet-va

fazulk avatar Apr 17 '25 17:04 fazulk