V13Axel / neotest-pest

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

Docker is not running error #1

Closed joshstobbs closed 5 months ago

joshstobbs commented 5 months ago

Apologies for the somewhat light bug report, I've just setup this fork after finding in the other neotest-pest repo - the setup went quite smoothly though when looking to run tests I'm getting a Docker is not running. error. I'm a bit new to testing in Neovim so maybe this is outside the bounds of this plugin but any help would be appreciated!

Running tests through the artisan cli seems to work just fine. Also I see you've added support for Sail, in this particular instance I am running Herd as opposed to Sail for my dev environment.

Anyway, thanks much for taking on the maintenance burden of this plugin!

CleanShot 2024-02-13 at 13 38 55

V13Axel commented 5 months ago

Ohh, interesting! I do all of my development on Linux and as such have no experience with Herd, though I am aware of it through colleagues.

I'd say it's definitely within the bounds of what I'm trying to achieve with this adapter, so no worries there!

Few questions:

  1. When you run your tests, what command(s) do you run to make that happen?
  2. Does Herd create any special binaries or configuration within the project? sail creates vendor/bin/sail, which makes it pretty easy to detect. Just trying to think about how to detect a Herd project.
  3. If not 2, any other ideas for detecting a project running with Herd?
joshstobbs commented 5 months ago

Ahh yes that makes sense! So for Herd, it's essentially (or at least the marketing says) a wrapper around Valet, meaning that there aren't really any in project cues as to what makes the project run with Herd. To answer your questions explicitly though:

  1. Just plain old php artisan test
  2. Not as far as I'm aware no.
  3. I would imagine that you could detect if there is an absence of the vendor/bin/sail directory and adjust based on that? Herd doesn't stage a development environment in the same way sail does as far as I can tell. This is in effect a "vanilla" Laravel project.

Let me know if I can offer any other thoughts, and thanks for everything so far!

V13Axel commented 5 months ago

Oh, I see! To me that sounds like it might be wrongly thinking sail exists - Curious to hear, are you able to run vendor/bin/pest directly?

joshstobbs commented 5 months ago

Hey! Yep, I can run the pest binary directly.

V13Axel commented 5 months ago

Hmm, that sounds super strange - though I did just make a bunch of changes yesterday (with a bunch of configurability!) that may have fixed it. Can you try with the latest version of the adapter?

joshstobbs commented 5 months ago

Okay! We're getting somewhere, aha!

The Docker error is no longer showing up but I'm getting this when I try to run a test function/file. Any thoughts?

Also thank you for all the help so far, it's very appreciated!

CleanShot 2024-02-21 at 08 20 10

V13Axel commented 5 months ago

Whoops! Had some leftover calls to vim-notify from debugging, but I've just pushed their removal. Try again? :grin:

joshstobbs commented 5 months ago

No worries! Seriously, really appreciate all the help here - we are still moving somewhere! Here's the new error...it's looking for junit for some reason?

*edit: reading through the new docs and noticing this might be a me problem! Will report back. ✨

CleanShot 2024-02-21 at 10 01 01

V13Axel commented 5 months ago

Hmm, "No test output file found!" typically means the test process crashed midway and wasn't able to create the XML output file that the adapter parses to determine test results. The junit bit is expected[^1]

That said, the relative path you have there (storage/app/...) gets set when the adapter detects the presence of sail. I'm tinkering with detecting whether sail is actually running, but for now it's just enabled by default if the file vendor/bin/sail is present. It sounds to me like your project has sail installed, but you don't use it? If that's the case, you'll just need to override sail_enabled to false in your config:

require('neotest').setup({
    adapters = {
        require('neotest-pest')({
            sail_enabled = false
        }),
    }
})

If it's still crashing after that, here's how you can nail that down:

  1. Add log_level = vim.log.levels.DEBUG to your require('neotest').setup({})
  2. Try running your test(s) again
  3. Check the neotest log (I don't know where that will be on mac, but mine is at ~/.local/state/nvim/neotest.log), looking for a debug log entry of Command: and it should show you the exact command being run. Here's an example of mine when running with sail:
{ "vendor/bin/sail", "bin", "pest", "/var/www/html/tests/Feature/LocationAgnosticJobListTest.php", "--log-junit=storage/app/junit-20240222-091915", "--filter", "can change departments quickly" }

versus without:

{ "vendor/bin/pest", "/home/axel/Git/neotest-pest/tests/Feature/UserTest.php", "--log-junit=/tmp/nvim.axel/isXpIm/3", "--filter", "class constructor" }
  1. If it's not sail, try running that command directly, see what happens? ... if it is still sail with sail_enabled = false, let me know! Would be a weird edge case I think.

[^1]: Pest uses PHPUnit under the hood, which involves junit somewhere along the line. The flag for setting that filename is --log-junit, which is why it's named that, but honestly I should probably change the default filename format to pest-[date] instead.

joshstobbs commented 5 months ago

Wow! Thanks for the detailed response - so after doing some testing here's what I've come to:

  1. You were right sail was installed in the repo, in fact it seems like sail is automatically installed when using the Laravel installer.
  2. I set sail_enabled to false and the plugin still seemed to look for the sail binary: a. my command output: { "vendor/bin/sail", "bin", "pest", "/var/www/html/tests/Unit/UserTest.php", "--log-junit=storage/app/junit-20240222-115735", "--filter", "a designer sees their projects" }
  3. Removing sail from my project and unsetting sail_enabled = false in my config seems to have done the trick and now I am able to run tests.

Maybe this is just a comedy of errors on my part...or like you say, perhaps a weird edge case. Regardless things are working on my end, and quite well, thank you! I'm happy to do anymore debugging if you need it!

V13Axel commented 5 months ago

Glad you're up and running with it!

I've yet to really dive into the testing setup around the adapter itself (besides getting it to work), but I plan to create multiple test projects with and without sail installed, and add tests for the various configs I've added like sail_enabled - I've a hunch that setting that flag in the plugin config isn't working properly somehow.

I think you've given me a couple further test cases to keep in mind when I get to that, but I'll keep you in mind if I have any further questions for sure. In either case, glad to hear it's working for you now! :grinning:

lizhineng commented 5 months ago

I have encountered similar issues when testing a Laravel project since Sail is automatically installed with a new installation. Setting the sail_enabled config to false does not turn the feature off. Instead, configuring it with a function resolves the issue. As a newcomer to Lua, I am not familiar with the problem. Perhaps the issue relates to type conversion since one is a function and the other is a boolean value?

require('neotest-pest')({
  sail_enabled = function ()
    return false
  end
})
V13Axel commented 5 months ago

Well, the way I've written the config should support either callable or non-callable values. I'll tinker with that, but glad to hear setting it to a function solved it for you =]