Skip to content

Commit 0eab70d

Browse files
authored
feat: add option to ignore a project root based on file existence (#19)
* Add option to ignore project roots based on files found * Add explanation of root_ignore_files to readme
1 parent c0f398a commit 0eab70d

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ require("neotest-phpunit")({
108108
})
109109
```
110110

111+
If there are projects you don't want discovered, you can instead set `root_ignore_files` to ignore any matching projects.
112+
113+
For example, if your project uses Pest and the appropriate [neotest adapter](https://github.com/V13Axel/neotest-pest), you'll need to set:
114+
115+
```lua
116+
require("neotest-phpunit")({
117+
root_ignore_files = { "tests/Pest.php" }
118+
})
119+
```
120+
111121
### Filtering directories
112122

113123
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:

lua/neotest-phpunit/config.lua

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ M.get_env = function()
88
return {}
99
end
1010

11+
M.get_root_ignore_files = function()
12+
return {}
13+
end
14+
1115
M.get_root_files = function()
1216
return { "composer.json", "phpunit.xml", ".gitignore" }
1317
end

lua/neotest-phpunit/init.lua

+12
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ local NeotestAdapter = { name = "neotest-phpunit" }
5959
function NeotestAdapter.root(dir)
6060
local result = nil
6161

62+
for _, root_ignore_file in ipairs(config.get_root_ignore_files()) do
63+
result = lib.files.match_root_pattern(root_ignore_file)(dir)
64+
if result then return nil end
65+
end
66+
6267
for _, root_file in ipairs(config.get_root_files()) do
6368
result = lib.files.match_root_pattern(root_file)(dir)
6469
if result then break end
@@ -198,6 +203,13 @@ setmetatable(NeotestAdapter, {
198203
return opts.phpunit_cmd
199204
end
200205
end
206+
if is_callable(opts.root_ignore_files) then
207+
config.get_root_ignore_files = opts.root_ignore_files
208+
elseif opts.root_ignore_files then
209+
config.get_root_ignore_files = function()
210+
return opts.root_ignore_files
211+
end
212+
end
201213
if is_callable(opts.root_files) then
202214
config.get_root_files = opts.root_files
203215
elseif opts.root_files then

0 commit comments

Comments
 (0)