Skip to content

Commit

Permalink
feat(output): open output for last test run (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelbeumer authored Oct 27, 2022
1 parent 7e73ba5 commit 0be9899
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions doc/neotest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ window will be used
{short} `(boolean)` Show shortened output
{enter} `(boolean)` Enter output window
{quiet} `(boolean)` Suppress warnings of no output
{last_run} `(boolean)` Open output for last test run
{position_id} `(string)` Open output for position with this ID, opens nearest
position if not given
{adapter} `(string)` Adapter ID, defaults to first found with matching position
Expand Down Expand Up @@ -423,6 +424,12 @@ neotest.run.adapters() *neotest.run.adapters()*
`neotest.run.adapters`()
Get the list of all known adapter IDs.

neotest.run.get_last_run() *neotest.run.get_last_run()*
`neotest.run.get_last_run`()
Get last test run tree and adapter id.
Return~
`(string)` | nil, table | nil Position id and last args table


==============================================================================
neotest.status *neotest.status*
Expand Down
12 changes: 11 additions & 1 deletion lua/neotest/consumers/output.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ end
---@field short boolean Show shortened output
---@field enter boolean Enter output window
---@field quiet boolean Suppress warnings of no output
---@field last_run boolean Open output for last test run
---@field position_id string Open output for position with this ID, opens nearest
--- position if not given
---@field adapter string Adapter ID, defaults to first found with matching position
Expand All @@ -171,7 +172,16 @@ function neotest.output.open(opts)
end
async.run(function()
local tree, adapter_id
if not opts.position_id then
if opts.last_run then
local position_id, last_args = require("neotest").run.get_last_run()
if position_id and last_args then
tree, adapter_id = client:get_position(position_id, last_args)
end
if not tree then
lib.notify("Last test run no longer exists")
return
end
elseif not opts.position_id then
local file_path = vim.fn.expand("%:p")
local row = vim.fn.getbufinfo(file_path)[1].lnum - 1
tree, adapter_id = client:get_nearest(file_path, row, opts)
Expand Down
9 changes: 9 additions & 0 deletions lua/neotest/consumers/run.lua
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ function neotest.run.adapters()
return client:get_adapters()
end

--- Get last test run tree and adapter id.
---@return string | nil, table | nil Position id and last args table
function neotest.run.get_last_run()
if not last_run then
return nil, nil
end
return unpack(last_run)
end

neotest.run = setmetatable(neotest.run, {
__call = function(_, client_)
client = client_
Expand Down

0 comments on commit 0be9899

Please sign in to comment.