vscode: "Test result not found" for all tests

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

  • Windows 11 21H2
  • VSCode 1.67.2
  • Extension v0.2.12
  • TypeScript 4.7.3

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

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 64 (12 by maintainers)

Most upvoted comments

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 have the same issue. Such a shame. Have no idea why. Super simple setup. CLI works. VS Code Extension fails:

image

image

v0.2.20, Yarn. Changing this setting fixed me, from @leonbloy above:

"vitest.commandLine" : "npx vitest"

I’m facing the same issue but I assume the reason is that we use a monorepo for our frontend and backend. I open vscode with the root directory so there is no package.json or any of the config files in the root directory but instead in one directory deeper (./frontend/package.json etc.)

When I open the project directly in the frontend directory it properly recognizes that there is vitest in place and the tests also run as expected (without the result not found error). I noticed however that it didn’t use the excluded files defined in the vitest.config.ts file so it shows some other test files for playwright as well…

I think it would be nice to be able to configure this in the workspace (e.g. rootDir: “./frontend”) or maybe let the extension check sub directories? (I’m not familiar with how extensions work or if this is even feasible)

Not working in monorepo

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?


Vitest output:

 DEV  v0.23.4 /workspaces/123
      API started at http://127.0.0.1:43211

 ❯ apps/proxy/src/websites/website.test.ts  (0 test)

same issue, and I found if u run the test again will be ok, hence every time I changed test file need to run test twice?

@btmnk mono repo is not supported yet #6 #13 . As a workaround, you can use it with VSCode workspaces now, thanks to @evanandrewrose .

There’s a common error when running with a nested multi-root workspace (i.e. root and root/package/a are both entrypoints in your VS Code workspace). The Vitest runner will try to run your test with a root CWD, and a root/package/a CWD simultaneously. In root/package/a, it’ll pick up your config properly & run the test correctly, but in root it’ll miss your config, and if your test depends on that it will fail.

The extension then picks up on a successful & a failing/misconfigured test result, and gets confused. You can see this if you go to the Vitest section in the Output tab.

The fix is simple (in your .code-workspace file):

"vitest.disabledWorkspaceFolders": ["root"]

Then restart VS Code. The extension doesn’t pick up on config changes until you do. @zxch3n I think this is the source of most of the errors of this kind, just judging by what people are reporting.

I am getting the same error. I will swich back to Jest until this is fixed

I have this error even though I’m not in a mono repo. Restarting VS Code fix it sometimes. No problems in terminal. package.json has script "test": "vitest" and this is my vitest.config.js:

import { defineConfig } from 'vitest/config'

export default defineConfig({
  test: {
    globals: true,
  },
})

@juananmuxed Can you switch to the pre-release version (v0.2.18) to test it again?

@xon52 dynamic test name is not supported yet

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 was getting this issue on Windows. I solved it by adding "vitest.commandLine": "npx vitest" to my VSCode’s workspace settings.

image

I’m having the same issue,but I solved it!

My global node version is 14. In my project, I temporarily changed the version under the project to 16 by nvm. The extension don’t work.

Then I changed the global node version to be consistent with my project version, and with "vitest.commandLine": "npx vitest",it worked fine.

I’m having the same issue as @abarke but downgrading vite to 3.2.6 seems to do nothing. Only VS Code Extension fails.

OK I found the issue and it works for me now. Seems vitest does not like vite v4.x.x

Try forcing it to use v3.x.x

image

Thanks, @Pustinyak! I added some extra error messages for the situations you listed.

I don’t know why this issue was closed,

I’ve updated to the latests versions (vitest .16.0, vitest extension: 0.2.19 ) and to find the right combination of settings that make this work is a torture.

I would help a lot that the extension has some debug mode or something that spits info to help debugging.

Apart from the versions, there seems to be these factors into play:

  1. OS Windows/Mac/Linux

  2. vitest.commandLine setting

  3. npm/yarn

  4. node in nvm yes/no

  5. vs code terminal (cmd/powershell/bash)

In my case, I have Windows, node with nvm, npm. I start with powershell

I have in my my package json

scripts {
 "test": "vitest run",
 "testw": "vitest",
}

so that running in my terminal

 > npm run test test src/__test__/trivial.test.js
 > npm run testw test src/__test__/trivial.test.js

runs the test as expected (the latter in watch mode)

However the setting

"vitest.commandLine" : "npm run test" fails with “Test result not found… (etc)” in spite of the test terminal showing the expected output:

> vitest run "W:/wk/myp/src/__test__/trivial.test.js" "testOk" "52580"
Doing my global setup
 RUN  v0.16.0 W:/wk/myp
stdout | unknown test
trivialTests before all
stdout | src/__test__/trivial.test.js > testOk
test Ok  1656439421059
stdout | unknown test
trivialTests after all
 ✓ src/__test__/trivial.test.js  (2 tests | 1 skipped) 4ms
Test Files  1 passed (1)
     Tests  1 passed | 1 skipped (2)
      Time  4.25s (in thread 4ms, 106351.64%)
Done my global tear down
> Test run finished at 28/06/2022, 15:03:41 <

(it’s strange the stdout | unknown test bit)

and the setting

"vitest.commandLine" : "npm run testw"

(in watch mode) simply hangs everythiong. The test ouptut terminal shows

     Test Files  1 passed (1)
     Tests  1 passed | 1 skipped (2)
     Time  4.18s (in thread 4ms, 104430.55%)
 PASS  Waiting for file changes...
       press h to show help, press q to quit

and the inprogres indicators (spinner, “Running tests messages”) go forever. Restart required.

I try instead

"vitest.commandLine" : "npx vitest"

… and now it works. Don’t know why

Ok. Now I want to switch to my preferred terminal: bash from git in windows.

I follow the recipe here https://stackoverflow.com/questions/42606837/how-do-i-use-bash-on-windows-from-the-visual-studio-code-integrated-terminal/72517865#72517865

And now I’m back to the “Test result not found” error

Test result not found. 
Are there tests with the same name?
Can you run vitest successfully on this file? Does it need custom option to run?

Vitest output:
Doing my global setup

 DEV  v0.16.0 W:/wk/myp
      API started at http://localhost:52928
stdout | unknown test
trivialTests before all
stdout | src/__test__/trivial.test.js > testOk
test Ok  1656439952028
 ✓ src/__test__/trivial.test.js  (2 tests | 1 skipped) 6ms
stdout | unknown test
trivialTests after all

Maybe works if I add “global”: true ?

imagen

@itpropro I published a new version to pre-release (v0.2.15) that fixed the run forever issue. Can you check whether it works now?

Thanks. I’ll look into it

Unfortunately, moving my main project from yarn to pnpm didn’t fix the problem, I still get the same "Test not found’ error, but now I get this one in addition from time to time:

FATAL ERROR: v8::FromJust Maybe value is Nothing.
 1: 00007FF7AA5E79CF v8::internal::CodeObjectRegistry::~CodeObjectRegistry+114207
 2: 00007FF7AA576096 DSA_meth_get_flags+65542
 3: 00007FF7AA576F4D node::OnFatalError+301
 4: 00007FF7AAE95BF5 v8::V8::FromJustIsNothing+53
 5: 00007FF7AA55F083 v8::base::CPU::has_sse+31507
 6: 00007FF7AA64A947 uv_timer_stop+1207
 7: 00007FF7AA646EDB uv_async_send+331
 8: 00007FF7AA64666C uv_loop_init+1292
 9: 00007FF7AA64680A uv_run+202
10: 00007FF7AA615675 node::SpinEventLoop+309
11: 00007FF7AA4AE6F0 v8::internal::interpreter::BytecodeLabel::bind+35712
12: 00007FF7AA4A9D48 v8::internal::interpreter::BytecodeLabel::bind+16856
13: 00007FF7AA636EDD uv_poll_stop+557
14: 00007FF7AB450120 v8::internal::compiler::RepresentationChanger::Uint32OverflowOperatorFor+146416
15: 00007FFAFFD754E0 BaseThreadInitThunk+16
16: 00007FFB00CA485B RtlUserThreadStart+43