Skip to content

Commit 70440f5

Browse files
committed
improve test file filtering
1 parent 3376e7c commit 70440f5

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

lua/neotest-vstest/init.lua

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,20 @@ function DotnetNeotestAdapter.root(path)
4040
end
4141

4242
function DotnetNeotestAdapter.is_test_file(file_path)
43-
return (
44-
(vim.endswith(file_path, ".csproj") or vim.endswith(file_path, ".fsproj"))
45-
and test_discovery.discover_tests(file_path)
46-
)
47-
or (
48-
(vim.endswith(file_path, ".cs") or vim.endswith(file_path, ".fs"))
49-
and test_discovery.discover_tests(file_path)
50-
)
43+
local isTestFile = (vim.endswith(file_path, ".csproj") or vim.endswith(file_path, ".fsproj"))
44+
or (vim.endswith(file_path, ".cs") or vim.endswith(file_path, ".fs"))
45+
46+
if not isTestFile then
47+
return false
48+
end
49+
50+
local tests = test_discovery.discover_tests(file_path)
51+
local n = 0
52+
if tests then
53+
n = #vim.tbl_values(tests)
54+
end
55+
56+
return tests and n > 0
5157
end
5258

5359
function DotnetNeotestAdapter.filter_dir(name)

spec/test_detection_spec.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,6 @@ describe("Test test detection", function()
9999

100100
local project_file = dir .. "/src/CSharpTest/CSharpTest.csproj"
101101

102-
assert.is_false(plugin.is_test_file(project_file))
102+
assert.is_falsy(plugin.is_test_file(project_file))
103103
end)
104104
end)

0 commit comments

Comments
 (0)