mirror of
https://github.com/pnx/neotest-phpunit
synced 2026-06-16 03:54:55 +02:00
wip
This commit is contained in:
parent
d12585b5b8
commit
4a1cde9121
3 changed files with 47 additions and 37 deletions
|
|
@ -1,21 +1,14 @@
|
|||
local logger = require('neotest.logging')
|
||||
|
||||
local is_callable = function(obj)
|
||||
return type(obj) == "function" or (type(obj) == "table" and obj.__call)
|
||||
end
|
||||
|
||||
local M = {}
|
||||
|
||||
M.opts = {}
|
||||
|
||||
M.available_opts = {
|
||||
"enable_sail",
|
||||
"pest_cmd",
|
||||
"root_ignore_files",
|
||||
"root_files",
|
||||
"filter_dirs",
|
||||
"env",
|
||||
local M = {
|
||||
opts = {},
|
||||
}
|
||||
|
||||
M.get = function(key)
|
||||
function M.get(key)
|
||||
if M.opts[key] then
|
||||
if is_callable(M.opts[key]) then
|
||||
return M.opts[key]()
|
||||
|
|
@ -24,18 +17,31 @@ M.get = function(key)
|
|||
return M.opts[key]
|
||||
end
|
||||
|
||||
if M[key] then
|
||||
return M[key]()
|
||||
return M[key]()
|
||||
end
|
||||
|
||||
function M.enable_sail()
|
||||
if vim.fn.filereadable("vendor/bin/sail") ~= 1 then
|
||||
logger.error("Sail executable not found")
|
||||
return false
|
||||
end
|
||||
|
||||
return {}
|
||||
logger.debug("Attempting to check if sail is running")
|
||||
local sail_ps_output = vim.fn.system("vendor/bin/sail ps | wc -l")
|
||||
|
||||
logger.debug("Sail ps output:", sail_ps_output)
|
||||
|
||||
if sail_ps_output > 1 then
|
||||
logger.debug("Sail is running")
|
||||
return true
|
||||
end
|
||||
|
||||
logger.debug("Sail is not running")
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
M.enable_sail = function()
|
||||
return vim.fn.filereadable("vendor/bin/sail") == 1
|
||||
end
|
||||
|
||||
M.pest_cmd = function()
|
||||
function M.pest_cmd()
|
||||
local binary = "pest"
|
||||
|
||||
if vim.fn.filereadable("vendor/bin/pest") == 1 then
|
||||
|
|
@ -45,20 +51,20 @@ M.pest_cmd = function()
|
|||
return binary
|
||||
end
|
||||
|
||||
M.env = function()
|
||||
function M.env()
|
||||
return {}
|
||||
end
|
||||
|
||||
M.root_ignore_files = function()
|
||||
function M.root_ignore_files()
|
||||
return {}
|
||||
end
|
||||
|
||||
M.root_files = function()
|
||||
function M.root_files()
|
||||
return { "tests/Pest.php" }
|
||||
end
|
||||
|
||||
M.filter_dirs = function()
|
||||
return { ".git", "node_modules", "vendor" }
|
||||
function M.filter_dirs()
|
||||
return { "tests" }
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -16,31 +16,31 @@ local NeotestAdapter = { name = "neotest-pest" }
|
|||
function NeotestAdapter.root(dir)
|
||||
local result = nil
|
||||
|
||||
logger.info("Finding root...")
|
||||
logger.debug("Finding root...")
|
||||
|
||||
for _, root_ignore_file in ipairs(config.get("root_ignore_files")) do
|
||||
logger.info("Checking root ignore file", root_ignore_file)
|
||||
logger.debug("Checking root ignore file", root_ignore_file)
|
||||
|
||||
result = lib.files.match_root_pattern(root_ignore_file)(dir)
|
||||
|
||||
if result then
|
||||
logger.info("Ignoring root because file", root_ignore_file)
|
||||
logger.debug("Ignoring root because file", root_ignore_file)
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
for _, root_file in ipairs(config.get("root_files")) do
|
||||
logger.info("Checking root file", root_file)
|
||||
logger.debug("Checking root file", root_file)
|
||||
|
||||
result = lib.files.match_root_pattern(root_file)(dir)
|
||||
|
||||
if result then
|
||||
logger.info("Found root", result)
|
||||
logger.debug("Found root", result)
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
logger.info("Root not found")
|
||||
logger.debug("Root not found")
|
||||
|
||||
return result
|
||||
end
|
||||
|
|
@ -52,7 +52,11 @@ end
|
|||
---@param root string Root directory of project
|
||||
---@return boolean True when matching
|
||||
function NeotestAdapter.filter_dir(name, rel_path, root)
|
||||
return vim.startswith(rel_path, "tests")
|
||||
for _, filter_dir in ipairs(config.get("filter_dirs")) do
|
||||
if vim.startswith(rel_path, filter_dir) then return true end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
---@async
|
||||
|
|
|
|||
|
|
@ -15,8 +15,8 @@ M.make_test_id = function(position)
|
|||
local path = string.sub(position.path, string.len(vim.loop.cwd()) + 2)
|
||||
|
||||
local id = path .. separator .. position.name
|
||||
logger.info("Path to test file:", { position.path })
|
||||
logger.info("Treesitter id:", { id })
|
||||
logger.debug("Path to test file:", { position.path })
|
||||
logger.debug("Treesitter id:", { id })
|
||||
|
||||
return id
|
||||
end
|
||||
|
|
@ -65,14 +65,14 @@ end
|
|||
---@param output_file string
|
||||
---@return table
|
||||
local function make_outputs(test, output_file)
|
||||
logger.info("Pre-output test:", test)
|
||||
logger.debug("Pre-output test:", test)
|
||||
local test_attr = test["_attr"] or test[1]["_attr"]
|
||||
local name = string.gsub(test_attr.name, "it (.*)", "%1")
|
||||
|
||||
-- Difference to neotest-phpunit as of PHPUnit 10:
|
||||
-- Pest's test IDs are in the format "path/to/test/file::test name"
|
||||
local test_id = string.gsub(test_attr.file, "(.*)::(.*)", "%1") .. separator .. name
|
||||
logger.info("Pest id:", { test_id })
|
||||
logger.debug("Pest id:", { test_id })
|
||||
|
||||
local test_output = {
|
||||
status = "passed",
|
||||
|
|
@ -83,7 +83,7 @@ local function make_outputs(test, output_file)
|
|||
local test_failed, errors, fails = errors_or_fails(test)
|
||||
|
||||
if test_failed then
|
||||
logger.info("test_failed:", { test_failed, errors, fails })
|
||||
logger.debug("test_failed:", { test_failed, errors, fails })
|
||||
test_output.status = "failed"
|
||||
|
||||
if #errors > 0 then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue