V13Axel / neotest-pest

Neotest adapter for Pest 2.0
MIT License
14 stars 5 forks source link

Support PHPUnit tests? #10

Open calebdw opened 2 months ago

calebdw commented 2 months ago

Hello!

First off, thanks for this awesome adapter! I've been looking to switch to Neotest from vim-test but haven't because it wouldn't work with Docker/Sai---everything JustWorks™ with this adapter :smile:

I work on a large codebase with a mix of PHPUnit and Pest tests, Pest supports executing PHPUnit tests and we've been gradually converting them over but there's a lot of them. However, neotest-phpunit still doesn't work with Sail (at least, not like this plugin) and I can only run whole files with vim-test (executing :TestNearest runs the entire file instead of filtering the individual test case for some reason).

It would be awesome to only have to install a single adapter that works out of the box with Sail!

Thanks!

V13Axel commented 1 month ago

While I'd love to make this happen, at the moment I'm just not sure it's feasible due to the way test position discovery is done; I'm trying to get my head wrapped around some of the finer details of tree-sitter queries so I can implement parameterized tests and a few other small fixes (like supporting tests whose names are defined via double-quotes).

That said, I'm also not super sure what it looks like to have a project with both Pest and PHPUnit tests in one. If you can create a repo with a minimal reproduction of the type of setup you have, I'll gladly give it a shot!

calebdw commented 1 month ago

If you can create a repo with a minimal reproduction of the type of setup you have, I'll gladly give it a shot!

I can create a repo if you really need it, but you can just drop any PHPUnit test (say the example test) into the Pest test suite and Pest will run it without any additional configuration (Pest is really just a wrapper around PHPUnit).

V13Axel commented 1 month ago

I was aware it's a wrapper around PHPUnit, but I can't say I've seen a mixed setup between the two; Sounds like it should be pretty straightforward though, so I'll poke around at it later on.

V13Axel commented 1 month ago

Spent some time last night and this morning looking into this a bit, and I've written up my thoughts so far in the PR where I'm exploring this in case you're curious.

Short answer is that so far it seems within reach, just needs navigating through.

calebdw commented 1 month ago

Awesome! I'll take a look :smile:

V13Axel commented 1 month ago

Ok so @calebdw - I spent some further time yesterday playing around with ideas for resolving the differences between the logged PHPUnit test results and Pest test results, and as of this morning I think I may have it solved at this point. That said, I don't have a project setup with both Pest and PHPUnit at the moment.

I made some assumptions in it for now, just to prove out the concept (such as the tests existing in a tests folder), so it may break in unexpected ways at the moment.

I'll look at upgrading a PHPUnit project that I have later today, but for the moment feel free to update your package config to pull in the PHPUnit_Test_Support branch and let me know if/how it blows up for you =]

calebdw commented 1 month ago

Sweet! It seems to be working pretty good when using function test*() methods. It does run the @test/#[Test] methods, but marks them as failed since it can't match up the results.

I did notice that it's not picking up failures in tests defined on the parent class (when I run the whole file)---granted I'm not sure how well you can detect this: image

V13Axel commented 1 month ago

Hmm. Yeah that's a tricky ask, I'm actually not even 100% sure where to start with handling that one. That might have to come after the initial test*() method support

calebdw commented 1 month ago

You might be able to look in the results for that classname and if any tests fail that are associated with it then mark the file as failed?

V13Axel commented 1 month ago

To clarify: It's my knowledge of neotest that breaks down here - I can think of several potential approaches, but I have no idea whether any of those approaches are reasonable to accomplish in the context of neotest; Maybe this will nerd-snipe me as the push I need to roll my sleeves up and just go dig through how neotest actually works under the hood a bit.

That's the problem with stepping in as the maintainer on an existing project that just needed some minor internal reworking: I know enough to do simple wrangling, but not enough (yet) to do more advanced stuff! ha.

V13Axel commented 1 week ago

So @calebdw I mentioned this over in #3 - But it looks like there's a --list-tests option I can pass to pest that might be useful both in solving parameterized tests and PHPUnit tests! Maybe!

I'm planning to take a look at it this weekend, but I'm hopeful it'll be useful.