Skip to content

Commit

Permalink
feat(adapters): provide filter_dir function
Browse files Browse the repository at this point in the history
See #13
  • Loading branch information
rcarriga committed Sep 12, 2022
1 parent 60b11a2 commit 775e425
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
7 changes: 7 additions & 0 deletions lua/neotest/adapters/interface.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ local NeotestAdapter = {}
---@return string | nil @Absolute root dir of test suite
function NeotestAdapter.root(dir) end

---Filter directories when searching for test files
---@async
---@param name string Name of directory
---@param rel_path string Path to directory, relative to root
---@param root string Root directory of project
function NeotestAdapter.filter_dir(name, rel_path, root) end

---@async
---@param file_path string
---@return boolean
Expand Down
11 changes: 10 additions & 1 deletion lua/neotest/client/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,16 @@ function NeotestClient:_update_positions(path, args)
local root_path = existing_root and existing_root:data().path or path
local files = lib.func_util.filter_list(
adapter.is_test_file,
lib.files.find(path, { filter_dir = config.projects[root_path].discovery.filter_dir })

lib.files.find(path, {
filter_dir = function(...)
return (not adapter.filter_dir or adapter.filter_dir(...))
and (
not config.projects[root_path].discovery.filter_dir
or config.projects[root_path].discovery.filter_dir(...)
)
end,
})
)
local positions = lib.files.parse_dir_from_files(path, files)
logger.debug("Found", positions)
Expand Down
1 change: 0 additions & 1 deletion lua/neotest/lib/file/find.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local M = {}

local ignored = vim.tbl_add_reverse_lookup({
"node_modules",
"venv",
})

--- Find all files under the given directory.
Expand Down

0 comments on commit 775e425

Please sign in to comment.