diff --git a/.config/nvim/lua/plugins/neotest.lua b/.config/nvim/lua/plugins/neotest.lua index 6f80987..32610d0 100644 --- a/.config/nvim/lua/plugins/neotest.lua +++ b/.config/nvim/lua/plugins/neotest.lua @@ -1,6 +1,5 @@ return { "nvim-neotest/neotest", - commit = '52fca6717ef972113ddd6ca223e30ad0abb2800c', event = "VeryLazy", dependencies = { "nvim-lua/plenary.nvim", @@ -13,16 +12,60 @@ return { }, config = function() local neotest = require("neotest") - local keymap = vim.keymap + -- Docker service management for PHP tests + local current_service = "app-fpm" + local phpunit_adapter = nil + + local function get_phpunit_cmd(service) + service = service or current_service + return { "docker", "compose", "exec", service, "./vendor/bin/phpunit" } + end + + local function switch_service() + local services = { "app-fpm", "fpm", "subscription-fpm" } + vim.ui.select(services, { + prompt = "Select Docker service for PHPUnit:", + format_item = function(item) + return item .. (item == current_service and " (current)" or "") + end, + }, function(choice) + if choice then + current_service = choice + vim.notify("PHPUnit service switched to: " .. choice, vim.log.levels.INFO) + + -- Recreate the adapter with new service + phpunit_adapter = require("neotest-phpunit")({ + root_files = { "phpunit.xml", "composer.json" }, + phpunit_cmd = get_phpunit_cmd(choice), + filter_dirs = { "vendor" }, + mapped_docker_dir = "/var/www", + append_to_cwd = "/api", + }) + + -- Reinitialize neotest with the new adapter + vim.notify("Restart Neovim for service change to take full effect", vim.log.levels.WARN) + end + end) + end + + -- Environment setup + vim.env.PROJECT_ROOT = vim.fn.getcwd() .. "/backend/" + vim.env.ENV_PATH = vim.fn.getcwd() .. "/backend/.env" + + -- Test running keymaps keymap.set("n", "tr", function() neotest.run.run() - end, { desc = "Run neotest on current function" }) + end, { desc = "Run nearest test" }) + + keymap.set("n", "tf", function() + neotest.run.run(vim.fn.expand("%")) + end, { desc = "Run all tests in file" }) keymap.set("n", "tR", function() neotest.run.run_last() - end, { desc = "Run neotest on most recent test" }) + end, { desc = "Run last test" }) keymap.set("n", "tS", function() neotest.run.stop() @@ -30,26 +73,45 @@ return { keymap.set("n", "ta", function() neotest.run.attach() - end, { desc = "Attach to the currently running test" }) + end, { desc = "Attach to running test" }) + + -- Watch mode + keymap.set("n", "tw", function() + neotest.watch.toggle(vim.fn.expand("%")) + end, { desc = "Toggle watch mode for file" }) + -- Output keymaps keymap.set("n", "to", function() - neotest.output.open() - end, { desc = "Open the output of the test" }) + neotest.output.open({ enter = true, short = false }) + end, { desc = "Open test output" }) + keymap.set("n", "tO", function() + neotest.output_panel.toggle() + end, { desc = "Toggle output panel" }) + + -- UI keymaps keymap.set("n", "ts", function() neotest.summary.toggle() - end, { desc = "Toggle neotest summary pane" }) + end, { desc = "Toggle summary pane" }) - vim.env.PROJECT_ROOT = vim.fn.getcwd() .. "/backend/" - vim.env.ENV_PATH = vim.fn.getcwd() .. "/backend/.env" + -- Navigation keymaps + keymap.set("n", "[t", function() + neotest.jump.prev({ status = "failed" }) + end, { desc = "Jump to previous failed test" }) + keymap.set("n", "]t", function() + neotest.jump.next({ status = "failed" }) + end, { desc = "Jump to next failed test" }) + + -- Service switching keymap + keymap.set("n", "tc", switch_service, { desc = "Change PHPUnit docker service" }) + + -- Setup neotest neotest.setup({ adapters = { require("neotest-phpunit")({ root_files = { "phpunit.xml", "composer.json" }, - -- phpunit_cmd = { "docker", "compose", "exec", "fpm", "./vendor/bin/phpunit" }, - phpunit_cmd = { "docker", "compose", "exec", "app-fpm", "./vendor/bin/phpunit" }, - -- phpunit_cmd = { "docker", "compose", "exec", "subscription-fpm", "./vendor/bin/phpunit" }, + phpunit_cmd = get_phpunit_cmd(), filter_dirs = { "vendor" }, mapped_docker_dir = "/var/www", append_to_cwd = "/api", @@ -63,13 +125,35 @@ return { }, args = { "-count=1", "-timeout=60s" }, }), - -- require('neotest-jest')({ - -- jestCommand = "npm test --", - -- env = { CI = true }, - -- cwd = function(path) - -- return vim.fn.getcwd() - -- end, - -- }), + }, + output = { + enabled = true, + open_on_run = false, + }, + output_panel = { + enabled = true, + open = "botright split | resize 15", + }, + quickfix = { + enabled = true, + open = false, + }, + status = { + enabled = true, + virtual_text = true, + signs = true, + }, + icons = { + passed = "", + running = "", + failed = "", + unknown = "", + skipped = "", + }, + floating = { + border = "rounded", + max_height = 0.8, + max_width = 0.9, }, }) end,