vitest-dev / vscode

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

extension breaks after changing a test file #393

Closed jd1378 closed 1 month ago

jd1378 commented 1 month ago

Describe the bug

In Testing panel of vscode vitest throws AssertionError [ERR_ASSERTION]: root directory is required to serve files after saving a file. extension works correctly when vscode is opened for the first time and nothing is changed in files yet.

I wish I could create a reproduction, but I can't

the only thing I'm noticing is in the logs it's missing the last letter of the path: test/client.test.t

Reproduction

Output

[Worker] Collecting tests due to file changes: test/client.test.t
[INFO 9:08:19 AM] [TEST] WARNING: NODE_ENV value of 'test' did not match any deployment config file names.

[INFO 9:08:19 AM] [TEST] WARNING: See https://github.com/node-config/node-config/wiki/Strict-Mode

[INFO 9:08:19 AM] [TEST] WARNING: No configurations found in configuration directory:C:\Users\MY User\AppData\Local\Programs\Microsoft VS Code\config

[INFO 9:08:19 AM] [TEST] WARNING: To disable this warning set SUPPRESS_NO_CONFIG_WARNING in the environment.

Version

v0.10.7

Validations

jd1378 commented 1 month ago

Well It seems the error is happening in my source code somewhere when it's running app.use(serveStatic(app.get('public'))), which seems to get some config, and that config is not loaded

and it seems the reason is that the working directory of the extension is not at the project, but somewhere in vscode folder in appdata

what can I do to set working directory to my project ?

hornta commented 1 month ago

I'm getting the same problem. This happens because you are rerunning the tests too quickly after changing the test file. You'll have to wait a bit, 5 seconds or so, after changing the file. I can reproduce this everytime if rerunning quickly after changing test files.

This might be a Windows only issue though.

jd1378 commented 1 month ago

This might be windows only, but the problem is not being too quickly, it outright crashes, because the working directory is set to somewhere other than the project

hornta commented 1 month ago

Yes I've also observed the cwd being incorrect which caused my test suite to fail. I could bypass that issue by finding the correct project folder by traversing backwards from __dirname but it's not elegant. For me, when I rerun the tests quickly after changing the test file, the test looks like they are running because a small loader appears in the top of the test explorer pane, but no test actually runs I think, because no console logs are recorded. I've never had vscode outright crash on me though.

gerhardcit commented 1 month ago

I would suggest this is not a minor bug. The same thing happens while running pnpm dev in sveltekit project and when hmr reloads a file eg: src/routes/api/someroute/[id]/+page.server.ts

The extension crashes with an error saying: 'src/routes/api/someroute/[id]/+page.server.ts' is not available. Then it just hangs. No way of resetting or restarting. The only way is to close vscode and reopen. It's very annoying, and basically makes the extension unusable. So hence my suggestion this is NOT a minor bug.

You end up being stuck with spinner and "Resolving Vitest" and no way to "hard reset" or do something. Surely that must be an option?

Full output of the error:

Error: ENOENT: no such file or directory, open 'src/routes/app/someroute/[id]/+page.server.ts'
    at Object.readFileSync (node:fs:453:20)
    at createProxy (file:///project/node_modules/.pnpm/@sveltejs+kit@2.5.10_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.17_vite@5.2.12_@types+node_kksg7dl7df63ve4rt7ijxpt6ti/node_modules/@sveltejs/kit/src/core/sync/write_types/index.js:519:31)
    at ensureProxies (file:///project/node_modules/.pnpm/@sveltejs+kit@2.5.10_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.17_vite@5.2.12_@types+node_kksg7dl7df63ve4rt7ijxpt6ti/node_modules/@sveltejs/kit/src/core/sync/write_types/index.js:505:20)
    at process_node (file:///project/node_modules/.pnpm/@sveltejs+kit@2.5.10_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.17_vite@5.2.12_@types+node_kksg7dl7df63ve4rt7ijxpt6ti/node_modules/@sveltejs/kit/src/core/sync/write_types/index.js:380:2)
    at update_types (file:///project/node_modules/.pnpm/@sveltejs+kit@2.5.10_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.17_vite@5.2.12_@types+node_kksg7dl7df63ve4rt7ijxpt6ti/node_modules/@sveltejs/kit/src/core/sync/write_types/index.js:250:7)
    at write_types (file:///project/node_modules/.pnpm/@sveltejs+kit@2.5.10_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.17_vite@5.2.12_@types+node_kksg7dl7df63ve4rt7ijxpt6ti/node_modules/@sveltejs/kit/src/core/sync/write_types/index.js:150:2)
    at Module.update (file:///project/node_modules/.pnpm/@sveltejs+kit@2.5.10_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.17_vite@5.2.12_@types+node_kksg7dl7df63ve4rt7ijxpt6ti/node_modules/@sveltejs/kit/src/core/sync/sync.js:48:8)
    at file:///project/node_modules/.pnpm/@sveltejs+kit@2.5.10_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.17_vite@5.2.12_@types+node_kksg7dl7df63ve4rt7ijxpt6ti/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:317:8
    at FSWatcher.<anonymous> (file:///project/node_modules/.pnpm/@sveltejs+kit@2.5.10_@sveltejs+vite-plugin-svelte@3.1.1_svelte@4.2.17_vite@5.2.12_@types+node_kksg7dl7df63ve4rt7ijxpt6ti/node_modules/@sveltejs/kit/src/exports/vite/dev/index.js:291:5)
    at FSWatcher.emit (node:events:530:35) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'src/routes/app/someroute/[id]/+page.server.ts'
}
sheremet-va commented 1 month ago

I need some kind of reproduction that I can install and run to see the error by myself.

sheremet-va commented 1 month ago

Then it just hangs. No way of resetting or restarting. The only way is to close vscode and reopen.

There is a "Refresh" button that should work:

Screenshot 2024-06-05 at 10 32 48

If it doesn't, I will need a reproduction to see why.

sheremet-va commented 1 month ago

The potential fix is released in v0.11.0 - this is a pre-release version and you might need to enable it manually:

Screenshot 2024-06-05 at 10 48 25

Please let me know if it fixes your issue.

jd1378 commented 1 month ago

thanks a lot for the quick fix it seems to be working for me

sheremet-va commented 1 month ago

This should be fixed for everyone in 0.12.0.