Closed itpropro closed 2 years ago
I was getting this issue on Windows. I solved it by adding "vitest.commandLine": "npx vitest"
to my VSCode's workspace settings.
I was able to solve this by updating vscode-js-debug
to Nightly as the latest vscode-js-debug
did not support node
installed via fnm
and there was a node versioning issue of some kind.
Open the extensions view (ctrl+shift+x) and search for @builtin @id:ms-vscode.js-debug
Right click on the JavaScript Debugger extension and Disable it.
Search for @id:ms-vscode.js-debug-nightly in the extensions view.
Install that extension.
And for debugging, make sure you setup the launch.json
as described by Vitest https://vitest.dev/guide/debugging.html
This issue should be reopened as it is far from resolved. This makes using vitest
not as appealing as it looks initially. Downgrading as solution looks bad.
I solved the issue Reloading VsCode
Ctrl + P > "Reload Window"
I keep receiving the error but test do start, so I do receive both error output and correct output. That Vitest had out-of-box working debug for VSCode was the sale point when I considered switching from Jest to Vitest.
Fixed it in my mono-repo by creating vitest.workspace.ts
in the root:
export default ['backend', 'frontend'];
See https://vitest.dev/guide/workspace.html
Update: Additionally I run into https://github.com/vitest-dev/vscode/issues/183 which seems to produce the "Test result not found"
issue sporadically.
After struggling for too long, I realised that, if there is a TypeScript compilation error, it will say "Test result not found"
Make sure to:
npx vitest [path-to-your-test]
... because it will tell you the real error
I was struggling with the same issue and finally I found a solution for my problem. I want to share my solution in case helpful for someone.
I want to create a test file like this:
describe("Test", () => {
it("Render Banners", () => {
render(<Component />);
expect(true).toBe(true);
});
});
This code reproduce this error for me:
Test result not found.
If you set `vitest.commandLine` please check:
Did you set `vitest.commandLine` to `run` mode? (This extension requires `watch` mode to get the results from Vitest api)
Does it have the ability to append extra arguments? (For example it should be `yarn test --` rather than `yarn test`)
Are there tests with the same name?
Can you run vitest successfully on this file? Does it need custom option to run?
After hours of trying I noticed something in the terminal: It says there is a problem with some packages. So I tried to mock these packages in case solve the issue.
vi.mock("@uiw/react-color", () => ({
default: vi.fn(),
}));
describe("Test", () => {
it("Render Banners", () => {
render(<Component />);
expect(true).toBe(true);
});
});
It worked. I just mocked that package and the errors disappeared.
I also head-scratched for a while until I tried to remove a yarn linked dependency. I had this error in the vscode output:
TypeError: vue.createApp is not a function
❯ Object.<anonymous> ../../path-of-a-linked-dependency
So I ran yarn unlink [my-dependency]
and yarn install --force
, and the issue was solved.
It may have been a problem on top of the others, as I kept all the previous workarounds in this thread.
For me it was because vitest in vscode could reslove my custom set in my tsconfig.json, the CLI yarn test
worked fine but vscode sidebar did not.
Oddly vitest doesnt offer any kind of hint that this was the issue.
...
resolve: {
alias: {
'@utils': resolve(__dirname, './src/utils'),
'@test': resolve(__dirname, './test'),
'@src': resolve(__dirname, './src'),
},
},
...
To match my tconfig
...
"paths": {
"@test/*": ["../test/*"],
"@utils/*": ["./utils/*"],
"@src/*": ["./*"]
}
...
@gregpalaci was it because you were using them like import utils from "@utils"
?
In my case, I am using a monorepo with pnpm. It was firstly not even seeing the tests. Then I have set the vitest.workspace.ts
and installed vitest
to the root of the monorepo. It started working in the workspace but it also started throwing this error with svelte
.
Edit: I have found that I can just open VS Code at the workspace directory and it just works! The initial configurations from Svelte Kit setup is enough for my case. This might be annoying for some that is working in multiple workspaces at the same time but enough for my use case.
This the link to the workspace in the monorepo in case anyone wants to take a look: https://github.com/cozemble/breezbook/tree/main/apps/booking
The other issue I found was you can't use variables as descriptions as mentioned https://github.com/vitest-dev/vscode/issues/47#issuecomment-1159322679
You can start with a string and add a variable in a template literal but not vice versa
it(`should ${something}`)
is ok but
t(`${something} should`)
is not ok
Im in a monorepo and found a possible solution: Adding an additional vitest.config.ts
in root.
Here is my structure:
├── packages
│ ├── core
│ ├── vitest.config.ts // These are not enough
│ ├── ui
│ ├── etc
├── vitest.config.ts // <----- Add this
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
},
})
And we are green ✅
I have the same problem as in this already closed issue https://github.com/vitest-dev/vscode/issues/8,the tests are working fine on the terminal (separate or VSCode integrated) but the tests are all failing in the extension:
From testing around I found that without any configuration, the result is this
And with
"vitest.commandLine": "yarn test"
, it actually runs the test, but still displays everything as failed (probably because of the bottom part):System
vite.config.js
There is also an issue in the vitest repo: https://github.com/vitest-dev/vitest/issues/1407