diff --git a/README.md b/README.md index f8cc6bd..0b7c01b 100644 --- a/README.md +++ b/README.md @@ -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: {} @@ -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 diff --git a/lua/neotest-elixir/init.lua b/lua/neotest-elixir/init.lua index 1e6155d..d80b312 100644 --- a/lua/neotest-elixir/init.lua +++ b/lua/neotest-elixir/init.lua @@ -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 @@ -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 @@ -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 @@ -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 @@ -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