Improve runnable detection for JavaScript files (#21246)

Closes #21242

![Screenshot 2024-11-27 at 18 52
51](https://github.com/user-attachments/assets/d096197c-33d2-41b9-963d-3e1a9bbdc035)
![Screenshot 2024-11-27 at 18 53
08](https://github.com/user-attachments/assets/b3202b00-3f68-4d9d-acc2-1b86c081fc34)

Release Notes:

- Improved runnable detection for JavaScript/Typescript files.
This commit is contained in:
Remco Smits 2024-11-28 00:54:01 +01:00 committed by GitHub
parent 66ba9d5b4b
commit 04ff9f060c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 79 additions and 34 deletions

View file

@ -62,12 +62,20 @@
name: (_) @name) @item
; Add support for (node:test, bun:test and Jest) runnable
(call_expression
function: (_) @context
(#any-of? @context "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @name
(
(call_expression
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]* @context
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string (string_fragment) @name)
)
)
) @item

View file

@ -2,13 +2,20 @@
; Function expression that has `it`, `test` or `describe` as the function name
(
(call_expression
function: (_) @_name
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @run
)
arguments . (string (string_fragment) @run)
)
) @_js-test
(#set! tag js-test)
)

View file

@ -70,12 +70,20 @@
name: (_) @name) @item
; Add support for (node:test, bun:test and Jest) runnable
(call_expression
function: (_) @context
(#any-of? @context "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @name
(
(call_expression
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]* @context
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string (string_fragment) @name)
)
)
) @item

View file

@ -2,13 +2,20 @@
; Function expression that has `it`, `test` or `describe` as the function name
(
(call_expression
function: (_) @_name
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @run
)
arguments . (string (string_fragment) @run)
)
) @_tsx-test
(#set! tag tsx-test)
) @_js-test
(#set! tag js-test)
)

View file

@ -70,12 +70,20 @@
name: (_) @name) @item
; Add support for (node:test, bun:test and Jest) runnable
(call_expression
function: (_) @context
(#any-of? @context "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @name
(
(call_expression
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]* @context
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string (string_fragment) @name)
)
)
) @item

View file

@ -2,13 +2,20 @@
; Function expression that has `it`, `test` or `describe` as the function name
(
(call_expression
function: (_) @_name
function: [
(identifier) @_name
(member_expression
object: [
(identifier) @_name
(member_expression object: (identifier) @_name)
]*
)
]
(#any-of? @_name "it" "test" "describe")
arguments: (
arguments . (string
(string_fragment) @run
)
arguments . (string (string_fragment) @run)
)
) @_ts-test
(#set! tag ts-test)
) @_js-test
(#set! tag js-test)
)