You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

148 lines
4.9 KiB

return {
"nvim-neotest/neotest",
event = "VeryLazy",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
"antoinemadec/FixCursorHold.nvim",
"nvim-neotest/nvim-nio",
-- Adapters
"olimorris/neotest-phpunit",
"praem90/neotest-docker-phpunit.nvim",
"nvim-neotest/neotest-go",
},
config = function()
local neotest = require("neotest")
local keymap = vim.keymap
-- Environment setup
vim.env.PROJECT_ROOT = vim.fn.getcwd() .. "/backend/"
vim.env.ENV_PATH = vim.fn.getcwd() .. "/backend/.env"
-- Container toggle state
local current_container = "app-fpm"
-- Test running keymaps
keymap.set("n", "<leader>tr", function()
neotest.run.run()
end, { desc = "Run nearest test" })
keymap.set("n", "<leader>tf", function()
neotest.run.run(vim.fn.expand("%"))
end, { desc = "Run all tests in file" })
keymap.set("n", "<leader>tR", function()
neotest.run.run_last()
end, { desc = "Run last test" })
keymap.set("n", "<leader>tS", function()
neotest.run.stop()
end, { desc = "Stop running tests" })
keymap.set("n", "<leader>ta", function()
neotest.run.attach()
end, { desc = "Attach to running test" })
-- Watch mode
keymap.set("n", "<leader>tw", function()
neotest.watch.toggle(vim.fn.expand("%"))
end, { desc = "Toggle watch mode for file" })
-- Output keymaps
keymap.set("n", "<leader>to", function()
neotest.output.open({ enter = true, short = false })
end, { desc = "Open test output" })
keymap.set("n", "<leader>tO", function()
neotest.output_panel.toggle()
end, { desc = "Toggle output panel" })
-- UI keymaps
keymap.set("n", "<leader>ts", function()
neotest.summary.toggle()
end, { desc = "Toggle summary pane" })
-- 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" })
-- 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,
},
}
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,
}