Skip to content

Commit 36bb392

Browse files
committed
feat(summary): status counts
1 parent 86395d4 commit 36bb392

File tree

4 files changed

+54
-22
lines changed

4 files changed

+54
-22
lines changed

lua/neotest/config/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ local default_config = {
193193
child_indent = "",
194194
final_child_indent = " ",
195195
watching = "",
196+
test = "",
196197
notify = "",
197198
},
198199
highlights = {

lua/neotest/consumers/summary/component.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ local async_func = function(f)
3939
end
4040
end
4141

42-
---@param canvas Canvas
42+
---@param canvas neotest.summary.Canvas
4343
---@param tree neotest.Tree
4444
function SummaryComponent:render(canvas, tree, expanded, focused, indent)
4545
self.renders = self.renders + 1

lua/neotest/consumers/summary/summary.lua

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local lib = require("neotest.lib")
2+
local types = require("neotest.types")
23
local logger = require("neotest.logging")
34
local config = require("neotest.config")
45
local Canvas = require("neotest.consumers.summary.canvas")
@@ -52,6 +53,54 @@ end
5253

5354
local all_expanded = {}
5455

56+
---@param canvas neotest.summary.Canvas
57+
---@param adapter_id string
58+
function Summary:_write_header(canvas, adapter_id, tree)
59+
canvas:write(
60+
vim.split(adapter_id, ":", { trimempty = true })[1] .. " ",
61+
{ group = config.highlights.adapter_name }
62+
)
63+
64+
if config.summary.count then
65+
local status_counts = {
66+
test = 0,
67+
running = 0,
68+
passed = 0,
69+
failed = 0,
70+
skipped = 0,
71+
}
72+
local results = self.client:get_results(adapter_id)
73+
74+
for _, pos in tree:iter() do
75+
if pos.type == "test" then
76+
status_counts.test = status_counts.test + 1
77+
78+
local result = results[pos.id]
79+
80+
if self.client:is_running(pos.id, { adapter = adapter_id }) then
81+
status_counts.running = status_counts.running + 1
82+
elseif result and status_counts[result.status] ~= nil then
83+
status_counts[result.status] = status_counts[result.status] + 1
84+
end
85+
end
86+
end
87+
88+
for _, status in ipairs({ "test", "passed", "failed", "running", "skipped" }) do
89+
canvas:write(
90+
config.icons[status] .. " " .. tostring(status_counts[status]) .. " ",
91+
{ group = config.highlights[status] or config.highlights.namespace }
92+
)
93+
end
94+
end
95+
canvas:write("\n")
96+
97+
local cwd = vim.loop.cwd()
98+
if tree:data().path ~= cwd then
99+
local root_dir = nio.fn.fnamemodify(tree:data().path, ":.")
100+
canvas:write(root_dir .. "\n", { group = config.highlights.dir })
101+
end
102+
end
103+
55104
function Summary:render(expanded)
56105
if not self.win:is_open() then
57106
return
@@ -85,28 +134,10 @@ function Summary:run()
85134
self.render_ready.wait()
86135
self.render_ready.clear()
87136
local canvas = Canvas.new(config.summary)
88-
local cwd = vim.loop.cwd()
89137
if self._starting then
90138
for _, adapter_id in ipairs(self.client:get_adapters()) do
91139
local tree = assert(self.client:get_position(nil, { adapter = adapter_id }))
92-
local count = 0
93-
if config.summary.count then
94-
for _, pos in tree:iter() do
95-
if pos.type == "test" then
96-
count = count + 1
97-
end
98-
end
99-
end
100-
canvas:write(
101-
vim.split(adapter_id, ":", { trimempty = true })[1]
102-
.. (count == 0 and "" or string.format(" %d Tests Found", count))
103-
.. "\n",
104-
{ group = config.highlights.adapter_name }
105-
)
106-
if tree:data().path ~= cwd then
107-
local root_dir = nio.fn.fnamemodify(tree:data().path, ":.")
108-
canvas:write(root_dir .. "\n", { group = config.highlights.dir })
109-
end
140+
self:_write_header(canvas, adapter_id, tree)
110141
self.components[adapter_id] = self.components[adapter_id]
111142
or SummaryComponent(self.client, adapter_id)
112143
if config.summary.animated then
@@ -136,7 +167,7 @@ function Summary:run()
136167
if not rendered then
137168
logger.error("Couldn't render buffer", err)
138169
end
139-
nio.api.nvim_exec("redraw", false)
170+
nio.api.nvim_exec2("redraw", {})
140171
nio.sleep(100)
141172
end
142173
end, function(msg)

lua/neotest/types/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ M.ResultStatus = {
6161
---@field cwd? string
6262
---@field context? table Arbitrary data to preserve state between running and result collection
6363
---@field strategy? table|neotest.Strategy Arguments for strategy or override for chosen strategy
64-
---@field stream fun(output_stream: fun(): string[]): fun(): table<string, neotest.Result>
64+
---@field stream? fun(output_stream: fun(): string[]): fun(): table<string, neotest.Result>
6565

6666
M.Tree = require("neotest.types.tree")
6767
M.FanoutAccum = require("neotest.types.fanout_accum")

0 commit comments

Comments
 (0)