Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lampewebdev opened this issue Mar 30, 2022 · 17 comments
Closed
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@lampewebdev
Copy link

Hello,

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

image

image

@zxch3n
Copy link
Member

zxch3n commented Mar 30, 2022

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

@lampewebdev
Copy link
Author

@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 :)

@zxch3n
Copy link
Member

zxch3n commented Mar 30, 2022

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.

@lampewebdev
Copy link
Author

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.

@sheremet-va
Copy link
Member

sheremet-va commented Apr 5, 2022

  • 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 👀

@zxch3n zxch3n added the p3-minor-bug An edge case that only affects very specific usage (priority) label May 20, 2022
@Nisgrak
Copy link

Nisgrak commented Jul 8, 2022

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

@TylerOliver
Copy link

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.

@watonyweng
Copy link

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

@unikitty37
Copy link

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

@wadefletch
Copy link

+1

@dreamorosi
Copy link

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.

@langaads
Copy link

langaads commented Jun 8, 2023

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
Copy link

langaads commented Jun 8, 2023

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

@dreamorosi
Copy link

dreamorosi commented Jun 9, 2023

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!

@langaads
Copy link

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.

@vovsemenv
Copy link

Still getting this errors 😢

@sheremet-va
Copy link
Member

sheremet-va commented Mar 15, 2024

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

@github-actions github-actions bot locked and limited conversation to collaborators Mar 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

No branches or pull requests