Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to _ignore_ a project root based on file existence #19

Merged
merged 2 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ require("neotest-phpunit")({
})
```

If there are projects you don't want discovered, you can instead set `root_ignore_files` to ignore any matching projects.

For example, if your project uses Pest and the appropriate [neotest adapter](https://github.com/V13Axel/neotest-pest), you'll need to set:

```lua
require("neotest-phpunit")({
root_ignore_files = { "tests/Pest.php" }
})
```

### Filtering directories

By default, the adapter will search test files in all dirs in the root with the exception of `node_modules` and `.git`. You can change this with:
Expand Down
4 changes: 4 additions & 0 deletions lua/neotest-phpunit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ M.get_env = function()
return {}
end

M.get_root_ignore_files = function()
return {}
end

M.get_root_files = function()
return { "composer.json", "phpunit.xml", ".gitignore" }
end
Expand Down
12 changes: 12 additions & 0 deletions lua/neotest-phpunit/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ local NeotestAdapter = { name = "neotest-phpunit" }
function NeotestAdapter.root(dir)
local result = nil

for _, root_ignore_file in ipairs(config.get_root_ignore_files()) do
result = lib.files.match_root_pattern(root_ignore_file)(dir)
if result then return nil end
end

for _, root_file in ipairs(config.get_root_files()) do
result = lib.files.match_root_pattern(root_file)(dir)
if result then break end
Expand Down Expand Up @@ -198,6 +203,13 @@ setmetatable(NeotestAdapter, {
return opts.phpunit_cmd
end
end
if is_callable(opts.root_ignore_files) then
config.get_root_ignore_files = opts.root_ignore_files
elseif opts.root_ignore_files then
config.get_root_ignore_files = function()
return opts.root_ignore_files
end
end
if is_callable(opts.root_files) then
config.get_root_files = opts.root_files
elseif opts.root_files then
Expand Down
Loading