Browse Source

fix: neotest

master
Tovi Jaeschke-Rogers 24 hours ago
parent
commit
48a3441102
1 changed files with 77 additions and 89 deletions
  1. +77
    -89
      .config/nvim/lua/plugins/neotest.lua

+ 77
- 89
.config/nvim/lua/plugins/neotest.lua View File

@ -7,53 +7,21 @@ return {
"antoinemadec/FixCursorHold.nvim", "antoinemadec/FixCursorHold.nvim",
"nvim-neotest/nvim-nio", "nvim-neotest/nvim-nio",
-- Adapters -- Adapters
"tovijaeschke/neotest-phpunit",
"olimorris/neotest-phpunit",
"praem90/neotest-docker-phpunit.nvim",
"nvim-neotest/neotest-go", "nvim-neotest/neotest-go",
}, },
config = function() config = function()
local neotest = require("neotest") local neotest = require("neotest")
local keymap = vim.keymap 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 -- Environment setup
vim.env.PROJECT_ROOT = vim.fn.getcwd() .. "/backend/" vim.env.PROJECT_ROOT = vim.fn.getcwd() .. "/backend/"
vim.env.ENV_PATH = vim.fn.getcwd() .. "/backend/.env" vim.env.ENV_PATH = vim.fn.getcwd() .. "/backend/.env"
-- Container toggle state
local current_container = "app-fpm"
-- Test running keymaps -- Test running keymaps
keymap.set("n", "<leader>tr", function() keymap.set("n", "<leader>tr", function()
neotest.run.run() neotest.run.run()
@ -103,58 +71,78 @@ return {
neotest.jump.next({ status = "failed" }) neotest.jump.next({ status = "failed" })
end, { desc = "Jump to next failed test" }) end, { desc = "Jump to next failed test" })
-- Service switching keymap
keymap.set("n", "<leader>tc", switch_service, { desc = "Change PHPUnit docker service" })
-- Setup neotest
neotest.setup({
adapters = {
require("neotest-phpunit")({
root_files = { "phpunit.xml", "composer.json" },
phpunit_cmd = get_phpunit_cmd(),
filter_dirs = { "vendor" },
mapped_docker_dir = "/var/www",
append_to_cwd = "/api",
}),
require("neotest-go")({
root = function()
return './backend'
end,
experimental = {
test_table = true,
},
args = { "-count=1", "-timeout=60s" },
}),
},
output = {
enabled = true,
open_on_run = false,
},
output_panel = {
enabled = true,
open = "botright split | resize 15",
},
quickfix = {
enabled = true,
open = false,
-- Setup neotest function
local cwd = vim.fn.getcwd()
local app_path = cwd .. "/app/api"
local subscription_path = cwd .. "/subscription/api"
-- Config table that we can modify
local docker_config = {
default = {
container = current_container,
volume = (current_container == "subscription-fpm" and subscription_path or app_path) .. ":/var/www",
standalone = 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,
},
})
}
local function setup_neotest()
neotest.setup({
adapters = {
require("neotest-docker-phpunit").setup({
phpunit_cmd = "neotest-docker-phpunit",
docker_phpunit = docker_config,
}),
require("neotest-go")({
root = function()
return './backend'
end,
experimental = {
test_table = true,
},
args = { "-count=1", "-timeout=60s" },
}),
},
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,
},
floating = {
border = "rounded",
max_height = 0.8,
max_width = 0.9,
},
})
end
-- Initial setup
setup_neotest()
-- Container toggle keybind
keymap.set("n", "<leader>tc", function()
if current_container == "app-fpm" then
current_container = "subscription-fpm"
else
current_container = "app-fpm"
end
-- Update the config table directly
docker_config.default.container = current_container
docker_config.default.volume = (current_container == "subscription-fpm" and subscription_path or app_path) .. ":/var/www"
vim.notify("Switched to container: " .. current_container, vim.log.levels.INFO)
end, { desc = "Toggle container (app/subscription)" })
end, end,
} }

Loading…
Cancel
Save