Skip to content

Commit

Permalink
Merge pull request #97 from amcoder/fix-xunit-fact-query
Browse files Browse the repository at this point in the history
fix(xunit): TS query for Fact attribute
  • Loading branch information
Issafalcon authored Apr 13, 2024
2 parents 15943dd + 8f8ab91 commit b747113
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lua/neotest-dotnet/xunit/ts-queries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ function M.get_queries(custom_attributes)
(string_literal_fragment) @display_name
)
)
)*
)?
)
)+
)
name: (identifier) @test.name
) @test.definition
Expand Down
51 changes: 51 additions & 0 deletions tests/xunit/discover_positions/fact_attribute_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,57 @@ describe("discover_positions", function()
DotnetUtils.get_test_full_names:revert()
end)

async.it("should discover Fact tests when not the only attribute", function()
local spec_file = "./tests/xunit/specs/fact_and_trait.cs"
local spec_file_name = "fact_and_trait.cs"
local positions = plugin.discover_positions(spec_file):to_list()

local expected_positions = {
{
id = spec_file,
name = spec_file_name,
path = spec_file,
range = { 0, 0, 11, 0 },
type = "file",
},
{
{
framework = "xunit",
id = spec_file .. "::xunit.testproj1",
is_class = false,
name = "xunit.testproj1",
path = spec_file,
range = { 0, 0, 10, 1 },
type = "namespace",
},
{
{
framework = "xunit",
id = spec_file .. "::xunit.testproj1::UnitTest1",
is_class = true,
name = "UnitTest1",
path = spec_file,
range = { 2, 0, 10, 1 },
type = "namespace",
},
{
{
framework = "xunit",
id = spec_file .. "::xunit.testproj1::UnitTest1::Test1",
is_class = false,
name = "Test1",
path = spec_file,
range = { 4, 1, 9, 2 },
type = "test",
},
},
},
},
}

assert.same(positions, expected_positions)
end)

async.it("should discover single tests in sub-class", function()
local spec_file = "./tests/xunit/specs/nested_class.cs"
local spec_file_name = "nested_class.cs"
Expand Down
11 changes: 11 additions & 0 deletions tests/xunit/specs/fact_and_trait.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace xunit.testproj1;

public class UnitTest1
{
[Fact]
[Trait("Category", "Integration")]
public void Test1()
{
Assert.Equal(1, 1);
}
}

0 comments on commit b747113

Please sign in to comment.