Skip to content

Commit

Permalink
fix(client): use args env/cwd
Browse files Browse the repository at this point in the history
See #34
  • Loading branch information
rcarriga committed Jul 15, 2022
1 parent 703a297 commit c6f80b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lua/neotest/client/runner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ function TestRunner:_run_tree(tree, args, adapter)
else
spec.strategy =
vim.tbl_extend("force", spec.strategy or {}, config.strategies[args.strategy] or {})

spec.env = vim.tbl_extend("force", spec.env or {}, args.env or {})
spec.cwd = args.cwd or spec.cwd
if vim.tbl_isempty(spec.env or {}) then
spec.env = nil
end
Expand Down
18 changes: 17 additions & 1 deletion tests/unit/client/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ end
describe("neotest client", function()
---@type neotest.InternalClient
local client
local mock_adapter, mock_strategy, attached, stopped, exit_test
local mock_adapter, mock_strategy, attached, stopped, exit_test, provided_spec
local dir = async.fn.getcwd()
local files
local dirs = { dir }
Expand Down Expand Up @@ -83,6 +83,7 @@ describe("neotest client", function()
end,
}
mock_strategy = function(spec)
provided_spec = spec
return {
is_complete = function()
return true
Expand Down Expand Up @@ -183,6 +184,21 @@ describe("neotest client", function()
end)

describe("running tests", function()
describe("using args", function()
a.it("provides env", function()
local tree = client:get_position(dir)
exit_test()
client:run_tree(tree, { strategy = mock_strategy, env = { TEST = "test" } })
assert.equal(provided_spec.env.TEST, "test")
end)

a.it("provides cwd", function()
local tree = client:get_position(dir)
exit_test()
client:run_tree(tree, { strategy = mock_strategy, cwd = "new_cwd" })
assert.equal(provided_spec.cwd, "new_cwd")
end)
end)
describe("with unsupported roots", function()
a.it("breaks up directories to files", function()
local positions_run = {}
Expand Down

0 comments on commit c6f80b9

Please sign in to comment.