Browse Source

fix: neotest config

master
Tovi Jaeschke-Rogers 1 day ago
parent
commit
39fed8ce19
1 changed files with 104 additions and 20 deletions
  1. +104
    -20
      .config/nvim/lua/plugins/neotest.lua

+ 104
- 20
.config/nvim/lua/plugins/neotest.lua View File

@ -1,6 +1,5 @@
return { return {
"nvim-neotest/neotest", "nvim-neotest/neotest",
commit = '52fca6717ef972113ddd6ca223e30ad0abb2800c',
event = "VeryLazy", event = "VeryLazy",
dependencies = { dependencies = {
"nvim-lua/plenary.nvim", "nvim-lua/plenary.nvim",
@ -13,16 +12,60 @@ return {
}, },
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
vim.env.PROJECT_ROOT = vim.fn.getcwd() .. "/backend/"
vim.env.ENV_PATH = vim.fn.getcwd() .. "/backend/.env"
-- Test running keymaps
keymap.set("n", "<leader>tr", function() keymap.set("n", "<leader>tr", function()
neotest.run.run() neotest.run.run()
end, { desc = "Run neotest on current function" })
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() keymap.set("n", "<leader>tR", function()
neotest.run.run_last() neotest.run.run_last()
end, { desc = "Run neotest on most recent test" })
end, { desc = "Run last test" })
keymap.set("n", "<leader>tS", function() keymap.set("n", "<leader>tS", function()
neotest.run.stop() neotest.run.stop()
@ -30,26 +73,45 @@ return {
keymap.set("n", "<leader>ta", function() keymap.set("n", "<leader>ta", function()
neotest.run.attach() neotest.run.attach()
end, { desc = "Attach to the currently running test" })
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() keymap.set("n", "<leader>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", "<leader>tO", function()
neotest.output_panel.toggle()
end, { desc = "Toggle output panel" })
-- UI keymaps
keymap.set("n", "<leader>ts", function() keymap.set("n", "<leader>ts", function()
neotest.summary.toggle() 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", "<leader>tc", switch_service, { desc = "Change PHPUnit docker service" })
-- Setup neotest
neotest.setup({ neotest.setup({
adapters = { adapters = {
require("neotest-phpunit")({ require("neotest-phpunit")({
root_files = { "phpunit.xml", "composer.json" }, 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" }, filter_dirs = { "vendor" },
mapped_docker_dir = "/var/www", mapped_docker_dir = "/var/www",
append_to_cwd = "/api", append_to_cwd = "/api",
@ -63,13 +125,35 @@ return {
}, },
args = { "-count=1", "-timeout=60s" }, 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, end,


Loading…
Cancel
Save