Skip to content

Commit

Permalink
Support extra test block IDs (#24)
Browse files Browse the repository at this point in the history
* Add support for extra block identifiers

* Fix typo in README

---------

Co-authored-by: Leo B <[email protected]>
  • Loading branch information
soundmonster and Leo B authored Nov 14, 2023
1 parent 7904f8c commit dfb1646
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ require("neotest").setup({
-- Can be a function to return a dynamic value.
-- Default: {"ExUnit.CLIFormatter"}
extra_formatters = {"ExUnit.CLIFormatter", "ExUnitNotifier"},
-- Extra test block identifiers
-- Can be a function to return a dynamic value.
-- Block identifiers "test", "feature" and "property" are always supported by default.
-- Default: {}
extra_block_identifiers = {"test_with_mock"},
-- Extra arguments to pass to mix test
-- Can be a function that receives the position, to return a dynamic value
-- Default: {}
Expand All @@ -48,7 +53,7 @@ require("neotest").setup({
-- Must be a function that receives the mix command as a table, to return a dynamic value
-- Default: function(cmd) return cmd end
post_process_command = function(cmd)
return vim.tbl_flatten({"env", "FOO=bar"}, cmd})
return vim.tbl_flatten({{"env", "FOO=bar"}, cmd})
end,
-- Delays writes so that results are updated at most every given milliseconds
-- Decreasing this number improves snappiness at the cost of performance
Expand Down
17 changes: 15 additions & 2 deletions lua/neotest-elixir/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ local function get_mix_task_args()
return {}
end

local function get_extra_block_identifiers()
return {}
end
local function get_write_delay()
return 1000
end
Expand Down Expand Up @@ -135,6 +138,11 @@ end
---@async
---@return neotest.Tree | nil
function ElixirNeotestAdapter.discover_positions(path)
local test_block_id_list = vim.tbl_flatten({ { "test", "feature", "property" }, get_extra_block_identifiers() })
for index, value in ipairs(test_block_id_list) do
test_block_id_list[index] = '"' .. value .. '"'
end
local test_block_ids = table.concat(test_block_id_list, " ")
local query = [[
;; query
;; Describe blocks
Expand All @@ -146,7 +154,7 @@ function ElixirNeotestAdapter.discover_positions(path)
;; Test blocks (non-dynamic)
(call
target: (identifier) @_target (#any-of? @_target "test" "feature" "property")
target: (identifier) @_target (#any-of? @_target ]] .. test_block_ids .. [[)
(arguments . [
(string . (quoted_content) @test.name .) ;; Simple string
(sigil . (sigil_name) @_sigil_name . (quoted_content) @test.name .) (#any-of? @_sigil_name "s" "S") ;; Sigil ~s and ~S, no interpolations
Expand All @@ -157,7 +165,7 @@ function ElixirNeotestAdapter.discover_positions(path)
;; Test blocks (dynamic)
(call
target: (identifier) @_target (#any-of? @_target "test" "feature" "property")
target: (identifier) @_target (#any-of? @_target ]] .. test_block_ids .. [[)
(arguments . [
(string (interpolation)) ;; String with interpolations
(identifier) ;; Single variable as name
Expand Down Expand Up @@ -308,6 +316,11 @@ setmetatable(ElixirNeotestAdapter, {
get_extra_formatters = extra_formatters
end

local extra_block_identifiers = callable_opt(opts.extra_block_identifiers)
if extra_block_identifiers then
get_extra_block_identifiers = extra_block_identifiers
end

local args = callable_opt(opts.args)
if args then
get_mix_task_args = args
Expand Down

0 comments on commit dfb1646

Please sign in to comment.