Skip to content

Commit 187979a

Browse files
KJ7LNWEric Wheeler
andauthored
feat: add test declarations support in typescript tree-sitter queries (#1899)
Add parsing support for: - Jest describe/test/it blocks - npm test exports This enables proper identification of test definitions in TypeScript files: ``` // File: multi-search-replace.test.ts (192 definitions) │| 2 - 1565 ||describe("MultiSearchReplaceDiffStrategy", () => { │| 3 - 632 || describe("exact matching", () => { │| 10 - 28 || it("should replace matching content", async () => { || ||---- │| 30 - 48 || it("should match content with different surrounding whitespace", async () => { || ||---- │| 50 - 68 || it("should match content with different indentation in search block", async () => { || ||---- │| 70 - 88 || it("should handle tab-based indentation", async () => { || ||---- ``` Signed-off-by: Eric Wheeler <[email protected]> Co-authored-by: Eric Wheeler <[email protected]>
1 parent 15338ed commit 187979a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/services/tree-sitter/queries/typescript.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,19 @@ export default `
2929
3030
(class_declaration
3131
name: (type_identifier) @name.definition.class) @definition.class
32+
33+
(call_expression
34+
function: (identifier) @func_name
35+
arguments: (arguments
36+
(string) @name
37+
[(arrow_function) (function_expression)]) @definition.test)
38+
(#match? @func_name "^(describe|test|it)$")
39+
40+
(assignment_expression
41+
left: (member_expression
42+
object: (identifier) @obj
43+
property: (property_identifier) @prop)
44+
right: [(arrow_function) (function_expression)]) @definition.test
45+
(#eq? @obj "exports")
46+
(#eq? @prop "test")
3247
`

0 commit comments

Comments
 (0)