vscode icon indicating copy to clipboard operation
vscode copied to clipboard

describe.each and test.each are shown as 'test result not found'

Open lampewebdev opened this issue 2 years ago • 8 comments

Hello,

when usuing .each the extension can not find the tests.

image image

lampewebdev avatar Mar 30 '22 08:03 lampewebdev

.each is not supported yet. I'll find a way to make it work

zxch3n avatar Mar 30 '22 08:03 zxch3n

@zxch3n thanks for the info.

Are you accepting PR's?

If you could just point me to the right file, I could take a look at it :)

lampewebdev avatar Mar 30 '22 08:03 lampewebdev

PRs are welcome! But I'm afraid this might not be an easy fix. Because we cannot infer the dynamic test name with 100% correctness from the static text content (which is how this plugin works right now).

There are two options left

  • Only register the dynamic tests' ancestors, and aggregate the test results to them
  • Start a Vitest server and communicate with it

I'll work on the latter in a week or two, which can also provide watch mode #4

If you are interested you can take a look at discover.ts and the VSCode testing API document.

zxch3n avatar Mar 30 '22 08:03 zxch3n

Thanks for the info, I have investigated this a little and looked into the vitest/ui package because there it works.

They are basically connecting to the server like this: https://github.com/vitest-dev/vitest/blob/main/packages/ui/client/composables/client.ts

When I have more time, I can investigate this a little more.

lampewebdev avatar Mar 30 '22 14:03 lampewebdev

  • Start a Vitest server and communicate with it

Yeah, I think Vitest has an api to communicate with --ui? Can you use that?


Edit:

They are basically connecting to the server like this:

Oh, I should have read the next comment 👀 Sorry for ping 👀

sheremet-va avatar Apr 05 '22 08:04 sheremet-va

Maybe this is working now? In my repo the test shows the actual results

Nisgrak avatar Jul 08 '22 15:07 Nisgrak

I was still seeing an issue today where the last entry in the each array was undefined when being processed

it.each([ 1, "1", true, {}, [] ])("should be true when value is truthy", (value) => {
  expect(required(value)).toBe(true);
  // 1 -> true
  // "1" -> true
  // true -> true
  // {} -> true
  // undefined
})

It didn't matter which value was the last, that value would always become undefined.

TylerOliver avatar Jul 21 '22 17:07 TylerOliver

Hi @lampewebdev, the latest version of vitest already supports describe.each and test.each, does the test command still prompt test result not found?

watonyweng avatar Sep 14 '22 10:09 watonyweng

Using the example from the describe.each documentation, I'm still only seeing placeholders rather than the expanded tests.

image

Version: 1.76.1 Commit: 5e805b79fcb6ba4c2d23712967df89a089da575b Date: 2023-03-08T16:48:08.231Z Electron: 19.1.11 Chromium: 102.0.5005.196 Node.js: 16.14.2 V8: 10.2.154.26-electron.0 OS: Darwin arm64 21.6.0 Sandboxed: No

Vitest extension v0.2.39

unikitty37 avatar Mar 14 '23 16:03 unikitty37

+1

wadefletch avatar Apr 07 '23 17:04 wadefletch

In my case the it.each tests are running and being detected fine however all the ones afterwards fail/hang.

Would be great to find a way to either support the feature or find a compromise that at least allows to "skip" the test cases containing .each while making the rest of the suites running and being detected normally.

dreamorosi avatar May 17 '23 14:05 dreamorosi

Similar to @dreamorosi i'm trying to use describe.each, it works fince once, and hangs afterwards.

Playing around, modifying, saving, stop/start watch, eventually unhangs it and it works well again.

i was able to capture this output

image

langaads avatar Jun 08 '23 22:06 langaads

I was able to make it work consistenly without hanging by prefixing the describe with "%s"

My guess is that the extension hangs if multiple describes with the same title are found, by adding the %s each describe becomes unique and it works.

image

langaads avatar Jun 08 '23 23:06 langaads

In my case, I'm using the each for it instead of describe.

If I do like suggested by @langaads, now the extension skips the tests entirely. (EDIT: this happens when clicking "run" on the specific test - when running the parent, it works normally).

For reference, this is my test before the change suggested (it hangs):

describe('getRequestPaths', () => {
  it.each([{ type: 'point' }, { type: 'range' }])(
    'it creates the correct request path',
    async ({ type }) => {
      // do thests
    }
  );
});

this is my test applying the suggestion (it skips it):

describe('getRequestPaths', () => {
  it.each([['point', { type: 'point' }], ['range', { type: 'range' }]])(
    'it creates the correct request path for %s',
    async (name, { type }) => {
      // do thests
    }
  );
});

image

EDIT:

When running or debugging a test that contains a template, the test is skipped. When doing so in the parent it works as expected. At least for now this is an acceptable workaround for me (although it'd still be nice if it worked consistently). Thank you @langaads for the suggestion!

dreamorosi avatar Jun 09 '23 15:06 dreamorosi

There is a gotcha. If the first iteraction of the ".each" succeeds but the others don't, the extension will mark tests as passed and won't highlight failures. The footer still points that a test failed but the test results won't.

langaads avatar Jun 10 '23 19:06 langaads

Still getting this errors 😢

vovsemenv avatar Feb 28 '24 05:02 vovsemenv

This is now supported in pre-release 0.5.0 and higher. Note that the extension now requires Vitest 1.4.0 or higher.

sheremet-va avatar Mar 15 '24 17:03 sheremet-va