Skip to content

Commit 69bacc6

Browse files
committed
feat(summary): count tests
1 parent 808cc4e commit 69bacc6

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

doc/neotest.txt

+5-3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ Default values:
161161
},
162162
summary = {
163163
animated = true,
164+
count = true,
164165
enabled = true,
165166
expand_errors = true,
166167
follow = true,
@@ -299,6 +300,7 @@ Fields~
299300
window
300301
{open} `(string)` | fun(): integer A command or function to open a window for
301302
the summary
303+
{count} `(boolean)` Display number of tests found beside the adapter name
302304

303305
*neotest.Config.summary.mappings*
304306
Fields~
@@ -1324,9 +1326,9 @@ https://github.com/neovim/neovim/blob/master/runtime/lua/vim/treesitter/language
13241326
Inherits: `neotest.lib.positions.ParseOptions`
13251327

13261328
Fields~
1327-
{fast} `(boolean)` Use faster parsing (Should be unchanged unless injections
1329+
{fast?} `(boolean)` Use faster parsing (Should be unchanged unless injections
13281330
are needed)
1329-
{build_position} `(fun(file_path: string, source: string, captured_nodes:
1331+
{build_position?} `(fun(file_path: string, source: string, captured_nodes:
13301332
table<string, userdata>): neotest.Position|neotest.Position[]|nil)` Builds one
13311333
or more positions from the captured nodes from a query match.
13321334

@@ -1409,7 +1411,7 @@ outputs. Use vim.jobstart instead.
14091411

14101412
Parameters~
14111413
{command} `(string[])`
1412-
{args} `(neotest.lib.process.RunArgs)`
1414+
{args?} `(neotest.lib.process.RunArgs)`
14131415
Return~
14141416
`(integer,neotest.lib.process.RunResult)` Exit code and table containing stdout/stderr keys if requested
14151417

lua/neotest/config/init.lua

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ local js_watch_query = [[
9999
---@field expand_errors boolean Expand all failed positions
100100
---@field mappings neotest.Config.summary.mappings Buffer mappings for summary window
101101
---@field open string | fun(): integer A command or function to open a window for the summary
102+
---@field count boolean Display number of tests found beside the adapter name
102103

103104
---@class neotest.Config.summary.mappings
104105
---@field expand string|string[] Expand currently selected position
@@ -229,6 +230,7 @@ local default_config = {
229230
},
230231
summary = {
231232
enabled = true,
233+
count = true,
232234
animated = true,
233235
follow = true,
234236
expand_errors = true,

lua/neotest/consumers/summary/summary.lua

+11-2
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,25 @@ function Summary:run()
8989
if self._starting then
9090
for _, adapter_id in ipairs(self.client:get_adapters()) do
9191
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
92100
canvas:write(
93-
vim.split(adapter_id, ":", { trimempty = true })[1] .. "\n",
101+
vim.split(adapter_id, ":", { trimempty = true })[1]
102+
.. (count == 0 and "" or string.format(" %d Tests Found", count)) .. "\n",
94103
{ group = config.highlights.adapter_name }
95104
)
96105
if tree:data().path ~= cwd then
97106
local root_dir = nio.fn.fnamemodify(tree:data().path, ":.")
98107
canvas:write(root_dir .. "\n", { group = config.highlights.dir })
99108
end
100109
self.components[adapter_id] = self.components[adapter_id]
101-
or SummaryComponent(self.client, adapter_id)
110+
or SummaryComponent(self.client, adapter_id)
102111
if config.summary.animated then
103112
if self.components[adapter_id]:render(canvas, tree, all_expanded, self.focused) then
104113
self.render_ready.set()

lua/neotest/lib/process/init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ neotest.lib.process = {}
2222
--- outputs. Use vim.jobstart instead.
2323
---@async
2424
---@param command string[]
25-
---@param args neotest.lib.process.RunArgs
25+
---@param args? neotest.lib.process.RunArgs
2626
---@return integer,neotest.lib.process.RunResult Exit code and table containing stdout/stderr keys if requested
2727
function neotest.lib.process.run(command, args)
2828
args = args or {}

lua/neotest/lib/treesitter/init.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ function neotest.lib.treesitter.fast_parse(lang_tree)
9191
end
9292

9393
---@class neotest.lib.treesitter.ParseOptions : neotest.lib.positions.ParseOptions
94-
---@field fast boolean Use faster parsing (Should be unchanged unless injections are needed)
95-
---@field build_position fun(file_path: string, source: string, captured_nodes: table<string, userdata>): neotest.Position|neotest.Position[]|nil Builds one or more positions from the captured nodes from a query match.
94+
---@field fast? boolean Use faster parsing (Should be unchanged unless injections are needed)
95+
---@field build_position? fun(file_path: string, source: string, captured_nodes: table<string, userdata>): neotest.Position|neotest.Position[]|nil Builds one or more positions from the captured nodes from a query match.
9696

9797
--- Build a parsed Query object from a string
9898
---@param lang string

0 commit comments

Comments
 (0)