diff --git a/lua/neotest-busted/init.lua b/lua/neotest-busted/init.lua index 4e720d8..b40a704 100644 --- a/lua/neotest-busted/init.lua +++ b/lua/neotest-busted/init.lua @@ -380,23 +380,11 @@ function BustedNeotestAdapter.discover_positions(path) arguments: (arguments (_) @test.name (function_definition)) ) (#match? @func_name "^it$")) @test.definition - ;; pending blocks constrained to have a describe as a parent + ;; pending blocks ((function_call - name: (identifier) @func_name1 (#match? @func_name1 "^describe$") - arguments: (arguments - (_) @namespace.name - (function_definition - parameters: (parameters) - body: (block - ((function_call - name: (identifier) @func_name2 - arguments: (arguments (_) @test.name (function_definition)?) - ) (#match? @func_name2 "^pending$") - ) @test.definition - ) - ) - ) - )) @namespace.definition + name: (identifier) @func_name + arguments: (arguments (string) @test.name) + ) (#match? @func_name "^pending$")) @test.definition ;; custom async blocks ((function_call diff --git a/test_files/expected_pending_tree.lua b/test_files/expected_pending_tree.lua new file mode 100644 index 0000000..d6eb421 --- /dev/null +++ b/test_files/expected_pending_tree.lua @@ -0,0 +1,74 @@ +local path = "./test_files/pending_spec.lua" + +return { + { + id = path, + name = "pending_spec.lua", + path = path, + range = { 0, 0, 14, 0 }, + type = "file", + }, + { + { + id = path .. '::"top-level pending"', + name = '"top-level pending"', + path = path, + range = { 0, 0, 0, 28 }, + type = "test", + }, + }, + { + { + id = path .. '::"pending tests"', + name = '"pending tests"', + path = path, + range = { 2, 0, 13, 4 }, + type = "namespace", + }, + { + { + id = path .. '::"pending tests"::"pending 1"', + name = '"pending 1"', + path = path, + range = { 3, 4, 5, 8 }, + type = "test", + }, + { + { + id = path .. '::"pending tests"::"pending 1"::"finish this test later"', + name = '"finish this test later"', + path = path, + range = { 4, 8, 4, 41 }, + type = "test", + }, + }, + }, + { + { + id = path .. '::"pending tests"::"pending 2"', + name = '"pending 2"', + path = path, + range = { 7, 4, 10, 8 }, + type = "test", + }, + { + { + id = path .. '::"pending tests"::"pending 2"::"this test does not run"', + name = '"this test does not run"', + path = path, + range = { 8, 8, 9, 12 }, + type = "test", + }, + }, + }, + { + { + id = path .. '::"pending tests"::"pending 3"', + name = '"pending 3"', + path = path, + range = { 12, 4, 12, 24 }, + type = "test", + }, + }, + }, +} diff --git a/test_files/pending_spec.lua b/test_files/pending_spec.lua index 3d30b24..2497058 100644 --- a/test_files/pending_spec.lua +++ b/test_files/pending_spec.lua @@ -1,12 +1,12 @@ +pending("top-level pending") + describe("pending tests", function() it("pending 1", function() pending("finish this test later") - error("this should not run") end) pending("pending 2", function() it("this test does not run", function() - error("this should not run") end) end) diff --git a/tests/adapter_discover_positions_spec.lua b/tests/adapter_discover_positions_spec.lua index f68570c..787d822 100644 --- a/tests/adapter_discover_positions_spec.lua +++ b/tests/adapter_discover_positions_spec.lua @@ -28,6 +28,18 @@ describe("adapter.discover_positions", function() assert.are.same(cache:size(), 0) end) + async.it("discovers pending tests", function() + local positions = adapter.discover_positions("./test_files/pending_spec.lua"):to_list() + + local expected_tree = require("./test_files/expected_pending_tree") + assert.are.same(positions, expected_tree) + + ---@diagnostic disable-next-line: undefined-field + local cache = adapter.get_parametric_test_cache() + + assert.are.same(cache:size(), 0) + end) + async.it("discovers parametric test positions", function() local path = "./test_files/parametric_tests_spec.lua"