vscode
vscode copied to clipboard
describe.each and test.each are shown as 'test result not found'
Hello,
when usuing .each
the extension can not find the tests.


.each
is not supported yet. I'll find a way to make it work
@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 :)
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.
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.
- 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 👀
Maybe this is working now? In my repo the test shows the actual results
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.
Hi @lampewebdev, the latest version of vitest
already supports describe.each
and test.each
, does the test command still prompt test result not found
?
Using the example from the describe.each documentation, I'm still only seeing placeholders rather than the expanded tests.
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
+1
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.
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
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.
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
}
);
});
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!
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.
Still getting this errors 😢
This is now supported in pre-release 0.5.0 and higher. Note that the extension now requires Vitest 1.4.0 or higher.