vitest-dev / vscode

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

Test Case name not fully displaying when space is available #368

Closed charlieforward9 closed 3 months ago

charlieforward9 commented 3 months ago

Describe the bug

When I drag the Navigation Bar out to show more text within the test cases, I see the ellipses. This should show the entire test name.

Screenshot 2024-05-01 at 12 57 52 AM

Reproduction

describe("This is a really long test name that will surpass the length of the VSCode Testing navigator display", () => {
  it("should not show all of this text in the VSCode Testing navigator display because of a Vitest limitation", () => {
     expect(testDescriptorSizeLimit).toBe(undefined);
  });
});

Output

A view similar to the one above with two test items showing something like this

This is a really long test name tha...
   should not show all of this text in...

Version

v0.8.6

Validations

sheremet-va commented 3 months ago

This is how names are reported by Vitest, so they are generated by someone like this.

github-actions[bot] commented 3 months ago

Hello @charlieforward9. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

charlieforward9 commented 3 months ago

@sheremet-va thank you for the response. Is it possible to change this in Vitest, it would be helpful to see the full string in the navigation bar if it were dragged to the respective width.

UPDATE: A reproduction was added to the original Issue description.

sheremet-va commented 3 months ago

Is it possible to change this in Vitest, it would be helpful to see the full string in the navigation bar if it were dragged to the respective width.

Vitest doesn't do anything with the name. This is something done by an external tool before the extension receives the data. I cannot reproduce it with your reproduction:

Screenshot 2024-05-02 at 10 29 05

You can also see that there is no ' symbol which further proves that the name was truncated by someone else. Vitest never stringifies it.

charlieforward9 commented 3 months ago

Im sorry, it seems I misunderstood what you originally said. This seems to be an issue with the vitest-cucumber plugin, or something else I am depending on. Thank you for clarifying.

sheremet-va commented 3 months ago

I managed to reproduce it with this code:

  it.each([{ key: 'should not show all of this text in the VSCode Testing navigator display because of a Vitest limitation' }])("$key", () => {
     expect(undefined).toBe(undefined);
  });

Vitest doesn't expect the full names to be used as properties there as they are treated a bit differently that if it was %s for example (which will just be replaced) - it also intentionally puts ' to signal it as a string. Adding truncateTreshold should help:

export default defineConfig({
  test: {
    chaiConfig: {
      truncateThreshold: Infinity,
    }
  },
})

But I would change how the tests are generated on cucumber side.

charlieforward9 commented 3 months ago

@sheremet-va Thank you for the details. I will see about contributing these findings to give back to the community after getting so much support!

charlieforward9 commented 3 months ago

https://github.com/amiceli/vitest-cucumber/pull/72 is addressing this issue.

amiceli commented 3 months ago

I've improved tests title in vitest-cucumber, long title are more legible now. @sheremet-va tests are sorted alphabetically ? For example When is before Then.

image
charlieforward9 commented 3 months ago

I see this in my own code as well. Changing this to Sort by location does not fix it either.

Screenshot 2024-05-06 at 12 30 56 PM
sheremet-va commented 3 months ago

I need any kind of reproduction that uses vitest-cucumber. From what I remember, the extension sorts by location by default.

Ideally, for frameworks built on top of Vitest, I would recommend using suite.task method to define your own tasks.

github-actions[bot] commented 3 months ago

Hello @charlieforward9. Please provide a minimal reproduction using a GitHub repository or StackBlitz (you can also use examples). Issues marked with needs reproduction will be closed if they have no activity within 3 days.

amiceli commented 3 months ago

I'm creating an example repository. I finish it and give you its link.

amiceli commented 3 months ago

@sheremet-va You can check vitest-cucumber-example project. When I use vitest on vscode, I see Then before When for example ;).

Say me if you need more examples inside this project.

sheremet-va commented 3 months ago

It doesn't have information about the location (you would've seen the green arrow in this case), so it's sorted by default. I don't think this is the extension's fault.

I will fix the sorting by modifying the sortText string, but I would recommend using the official custom API for this instead of wrapping test function.

sheremet-va commented 3 months ago

Fixed by https://github.com/vitest-dev/vscode/commit/f282283a1273d370b479a85d184c0d95db7e42f1

amiceli commented 3 months ago

@sheremet-va Yes, it works on example projet ;).