Skip to content

Commit

Permalink
fix: pending tests, single/double quotes, logger
Browse files Browse the repository at this point in the history
  • Loading branch information
YaroSpace committed Nov 28, 2024
1 parent 507cc60 commit ae216f3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lua/neotest-busted/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ function BustedNeotestAdapter.create_test_command(paths, options)
else
vim.list_extend(arguments, paths)
end

return {
---@diagnostic disable-next-line: undefined-field
nvim_command = compat.loop.exepath(),
Expand Down Expand Up @@ -380,6 +379,12 @@ function BustedNeotestAdapter.discover_positions(path)
arguments: (arguments (_) @test.name (function_definition))
) (#match? @func_name "^it$")) @test.definition
;; pending blocks
((function_call
name: (identifier) @func_name
arguments: (arguments (_) @test.name (function_definition))
) (#match? @func_name "^pending$")) @test.definition
;; custom async blocks
((function_call
name: (identifier) @func_name
Expand Down
1 change: 1 addition & 0 deletions lua/neotest-busted/logging.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local function log(level, context, message, ...)
local args = { ... }

vim.schedule(function()
if not unpack(args) then return end
local formatted_message = message:format(unpack(args))

logger[level](formatted_message, context)
Expand Down
15 changes: 14 additions & 1 deletion lua/neotest-busted/output_handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ return function(options)
os.exit(1)
end

for _, test in ipairs(handler.pendings) do
test.element.attributes.default_fn = nil -- functions cannot be encoded into json
end

local test_results = {
pendings = handler.pendings,
successes = handler.successes,
Expand All @@ -59,14 +63,23 @@ return function(options)
duration = handler.getDuration(),
}

local ok, result = pcall(json.encode, test_results)
local ok, result = pcall(json.encode, test_results, {
exception = function(reason, value, state, default_reason)
local state_short = table.concat(state.buffer, "")
state_short = "..."
.. state_short:sub(#state_short - 100)
.. tostring(state.exception)
io.stderr:write(default_reason .. "(" .. state_short .. ")")
end,
})

if ok then
file:write(result)
file:close()
else
io_write("Failed to encode test results to json: " .. result .. "\n")
io_flush()
os.exit(1)
end

return nil, true
Expand Down
2 changes: 1 addition & 1 deletion lua/neotest-busted/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local lib = require("neotest.lib")
---@param value string
---@return string
function util.trim_quotes(value)
return vim.fn.trim(value, '"')
return vim.fn.trim(value, [["']])
end

---@param ... string
Expand Down

0 comments on commit ae216f3

Please sign in to comment.