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

feature: ginkgo support #204

Open
2 of 5 tasks
hown3d opened this issue Oct 13, 2024 · 4 comments
Open
2 of 5 tasks

feature: ginkgo support #204

hown3d opened this issue Oct 13, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@hown3d
Copy link
Contributor

hown3d commented Oct 13, 2024

Did you check docs and existing issues?

Is your feature request related to a problem? Please describe.

Ginkgo does have it's own structure on how test cases are build: https://onsi.github.io/ginkgo/#writing-specs

Some places where ginkgo is used:

Requirements to support ginkgo

  • tree-sitter query
  • test command
  • Parse output from ginkgo

Describe the solution you'd like to see.

Add a tree-sitter query to capture tests written with Ginkgo

Describe alternatives you've considered.

Ginkgo has the possibility to print it's outline with ginkgo outline --format=json $PACKAGE in their own data structure.
For example the
Parsing this into neotest.positions would be possible, but using native treesitter seems to be the easier option.

Additional context

Bildschirmfoto 2024-10-14 um 01 29 22

I would be happy to implement support since we use ginkgo a lot in our code base 😃

@hown3d hown3d added the enhancement New feature or request label Oct 13, 2024
@fredrikaverpil
Copy link
Owner

Hey @hown3d,

I haven't used ginkgo and I don't plan on adding this support myself but I'm absolutely open for PRs here and I'll be happy to provide guideance.

I'm curious what steps you took to get the tests to be detected in your screenshot, and if you only got the test summary to show the tests - but not being able to run them, for example.

Have you looked at how the optional testify feature was implemented?
I feel we might want to do something similar here, which you would opt-in to.

After having quickly skimmed the ginkgo link you provided over morning coffee, it looks like the test output will be go test output, which means you can piggy back on the current test output processing, which is neat. But what about the test invocation itself, would you want to use another command than go test to invoke test(s)?

I'm looking into potentially supporting custom test runners in #189 which perhaps could be interesting here, in case it would help to use ginkgo to execute tests. You can see how I've configured gotestsum, which piggybacks on the runspecs and test output processing implemented for go test, but implements its own test invocation command: https://github.com/fredrikaverpil/neotest-golang/pull/189/files#diff-59de0e930211d324b35ad4beccf973061d9ab55415ebfaec0d9ee3c265f96746R63

@hown3d
Copy link
Contributor Author

hown3d commented Oct 15, 2024

Happy to participate!

I've been playing around to get support for Ginkgo tests. The tests from the screenshot are done using this Tree-sitter query:

[[
    ; query for ginkgo tests
    (call_expression
      function: (identifier) @ginkgo_spec  (#match? @ginkgo_spec "^(Describe|Context|It)$")
        arguments: (argument_list
          (interpreted_string_literal) @test.name
      ) @test.definition
    )
]]

Test execution

I was thinking about using the focus flag from ginkgo which focuses on a dedicated Spec with regex. This is only suitable though when actually targeting a ginkgo Spec.

Using the tests from the screenshot as an example:
Running the test
Books -> Categorizing Books -> with more than 300 pages -> should be a novel
could be achieved by using

ginkgo run --focus "Books Categorizing Books with more than 300 pages should be a novel"

This focus "regex" does differ though from the go test regex. So if using ginkgo as the runner, we would need to distinguish between standard go tests and Ginkgo specs, which is not possible (correct me if I'm wrong) not possible from the same adapter.

Test parsing

Unfortunately Ginkgo does not use the default test output from go json instead it uses it's own data structure for reports.

Conclusion

My idea was to create a second adapter that is only used to parse Ginkgo specs. There we can adapt to different regex invocation and result parsing.

@fredrikaverpil
Copy link
Owner

Given if I merge in something like #189 you could actually implement all this here in this adapter. But it sounds like you won't benefit much from doing that in case everything differs (treesitter query, execution command, test output parsing). Then maybe it's better you take ownership of this and build a separate adapter, as you wouldn't be "trapped" in my repo and in the way I structure the code etc.

@iamralch
Copy link

@hown3d Slowly I have been working on that https://github.com/nvim-contrib/nvim-ginkgo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants