vitest-dev / vscode

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

"Test result not found" for all tests #47

Closed itpropro closed 2 years ago

itpropro commented 2 years ago

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:

image

From testing around I found that without any configuration, the result is this

 RUN  v0.14.1 E:/repos/project

⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/code.test.ts [ test/code.test.ts ]
Error: No test suite found in file E:/repos/project/test/code.test.ts
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

Test Files  1 failed (1)
     Tests  no tests
      Time  1.84s (in thread 0ms, Infinity%)

And with "vitest.commandLine": "yarn test", it actually runs the test, but still displays everything as failed (probably because of the bottom part):

 RUN  v0.14.1 E:/repos/project

⎯⎯⎯⎯⎯⎯ Failed Suites 1 ⎯⎯⎯⎯⎯⎯⎯

 FAIL  test/code.test.ts [ test/code.test.ts ]
TypeError: params.map is not a function
...

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/1]⎯

Test Files  1 failed (1)
     Tests  no tests
      Time  1.70s (in thread 0ms, Infinity%)

JSON report written to C:/Users/xxx/AppData/Local/Temp/vitest-report-2v2t12.json
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Cannot find test file:///e%3A/repos/project/test/code.test.ts/function01 given no parameters should be defined@2Cannot find test file:///e%3A/repos/project/test/code.test.ts/function01 given no parameters should instantiate@3Cannot find test file:///e%3A/repos/project/test/code.test.ts/function01 given parameters should be defined@5Cannot find test file:///e%3A/repos/project/test/code.test.ts/function01 given parameters should work with parameters@6Cannot find test file:///e%3A/repos/project/test/code.test.ts/function02 should be defined@9Cannot find test file:///e%3A/repos/project/test/code.test.ts/function03 should be defined@11

System

vite.config.js

import { defineConfig } from 'vite'

export default defineConfig({})

There is also an issue in the vitest repo: https://github.com/vitest-dev/vitest/issues/1407

RishikeshVedpathak commented 1 year ago

I was getting this issue on Windows. I solved it by adding "vitest.commandLine": "npx vitest" to my VSCode's workspace settings.

image

drewbitt commented 1 year ago

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

selfrefactor commented 1 year ago

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.

ngxCoder commented 1 year ago

I solved the issue Reloading VsCode Ctrl + P > "Reload Window"

image
selfrefactor commented 1 year ago

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.

jzillmann commented 12 months ago

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.

andrerpena commented 11 months ago

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

Polcsi commented 11 months ago

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: image 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.

mathieucivel commented 11 months ago

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.

gregpalaci commented 9 months ago

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/*": ["./*"]
    }
...
Metehan-Altuntekin commented 8 months ago

@gregpalaci was it because you were using them like import utils from "@utils"?

Metehan-Altuntekin commented 8 months ago

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

gregpalaci commented 8 months ago

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

ajthinking commented 7 months ago

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 ✅