Skip to content

Commit

Permalink
fix(#47): unable to detect tests using backticks
Browse files Browse the repository at this point in the history
Fixes #47
  • Loading branch information
conermurphy committed Mar 28, 2024
1 parent 0e6e77c commit 76d7569
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions lua/neotest-jest/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -154,30 +154,72 @@ end
function adapter.discover_positions(path)
local query = [[
; -- Namespaces --
; Matches: `describe(`context`, () => {})`
((call_expression
function: (identifier) @func_name (#eq? @func_name "describe")
arguments: (arguments (template_string (string_fragment) @namespace.name) (arrow_function))
)) @namespace.definition
; Matches: `describe('context', () => {})`
((call_expression
function: (identifier) @func_name (#eq? @func_name "describe")
arguments: (arguments (string (string_fragment) @namespace.name) (arrow_function))
)) @namespace.definition
; Matches: `describe(`context`, function() {})`
((call_expression
function: (identifier) @func_name (#eq? @func_name "describe")
arguments: (arguments (template_string (string_fragment) @namespace.name) (function_expression))
)) @namespace.definition
; Matches: `describe('context', function() {})`
((call_expression
function: (identifier) @func_name (#eq? @func_name "describe")
arguments: (arguments (string (string_fragment) @namespace.name) (function_expression))
)) @namespace.definition
; Matches: `describe.only(`context`, () => {})`
((call_expression
function: (member_expression
object: (identifier) @func_name (#any-of? @func_name "describe")
)
arguments: (arguments (template_string (string_fragment) @namespace.name) (arrow_function))
)) @namespace.definition
; Matches: `describe.only('context', () => {})`
((call_expression
function: (member_expression
object: (identifier) @func_name (#any-of? @func_name "describe")
)
arguments: (arguments (string (string_fragment) @namespace.name) (arrow_function))
)) @namespace.definition
; Matches: `describe.only(`context`, function() {})`
((call_expression
function: (member_expression
object: (identifier) @func_name (#any-of? @func_name "describe")
)
arguments: (arguments (template_string (string_fragment) @namespace.name) (function_expression))
)) @namespace.definition
; Matches: `describe.only('context', function() {})`
((call_expression
function: (member_expression
object: (identifier) @func_name (#any-of? @func_name "describe")
)
arguments: (arguments (string (string_fragment) @namespace.name) (function_expression))
)) @namespace.definition
; Matches: `describe.each(['data'])(`context`, () => {})`
((call_expression
function: (call_expression
function: (member_expression
object: (identifier) @func_name (#any-of? @func_name "describe")
)
)
arguments: (arguments (template_string (string_fragment) @namespace.name) (arrow_function))
)) @namespace.definition
; Matches: `describe.each(['data'])('context', () => {})`
((call_expression
function: (call_expression
Expand All @@ -187,6 +229,17 @@ function adapter.discover_positions(path)
)
arguments: (arguments (string (string_fragment) @namespace.name) (arrow_function))
)) @namespace.definition
; Matches: `describe.each(['data'])(`context`, function() {})`
((call_expression
function: (call_expression
function: (member_expression
object: (identifier) @func_name (#any-of? @func_name "describe")
)
)
arguments: (arguments (template_string (string_fragment) @namespace.name) (function_expression))
)) @namespace.definition
; Matches: `describe.each(['data'])('context', function() {})`
((call_expression
function: (call_expression
Expand All @@ -198,18 +251,45 @@ function adapter.discover_positions(path)
)) @namespace.definition
; -- Tests --
; Matches: `test(`test`) / it(`test`)`
((call_expression
function: (identifier) @func_name (#any-of? @func_name "it" "test")
arguments: (arguments (template_string (string_fragment) @test.name) [(arrow_function) (function_expression)])
)) @test.definition
; Matches: `test('test') / it('test')`
((call_expression
function: (identifier) @func_name (#any-of? @func_name "it" "test")
arguments: (arguments (string (string_fragment) @test.name) [(arrow_function) (function_expression)])
)) @test.definition
; Matches: `test.only(`test`) / it.only(`test`)`
((call_expression
function: (member_expression
object: (identifier) @func_name (#any-of? @func_name "test" "it")
)
arguments: (arguments (template_string (string_fragment) @test.name) [(arrow_function) (function_expression)])
)) @test.definition
; Matches: `test.only('test') / it.only('test')`
((call_expression
function: (member_expression
object: (identifier) @func_name (#any-of? @func_name "test" "it")
)
arguments: (arguments (string (string_fragment) @test.name) [(arrow_function) (function_expression)])
)) @test.definition
; Matches: `test.each(['data'])(`test`) / it.each(['data'])(`test`)`
((call_expression
function: (call_expression
function: (member_expression
object: (identifier) @func_name (#any-of? @func_name "it" "test")
property: (property_identifier) @each_property (#eq? @each_property "each")
)
)
arguments: (arguments (template_string (string_fragment) @test.name) [(arrow_function) (function_expression)])
)) @test.definition
; Matches: `test.each(['data'])('test') / it.each(['data'])('test')`
((call_expression
function: (call_expression
Expand Down

0 comments on commit 76d7569

Please sign in to comment.