Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(#47): unable to detect tests using backticks #112

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading