@@ -48,7 +48,7 @@ declare_oxc_lint!(
4848 /// ```
4949 WarnTodo ,
5050 vitest,
51- correctness
51+ correctness,
5252) ;
5353
5454impl Rule for WarnTodo {
@@ -98,28 +98,53 @@ impl WarnTodo {
9898fn test ( ) {
9999 use crate :: tester:: Tester ;
100100
101+ /*
102+ * Currently the responsible to set what frameworks are active or not is not `with_vitest_plugin` or oxlint config.
103+ * The code that set what test framewors are active is ContextHost::sniff_for_frameworks, and the current detection lead to a
104+ * a false negative. To detect if the current source code belongs to vitest is based if a `vitest` import exist, if not, assumes
105+ * we are on a possible jest test. On top of that, the method `frameworks::is_jestlike_file` most of the times is going to be true, at least in
106+ * our current situation. So this lead that the ContextHost can have jest and vitest active **at same time**.
107+ *
108+ * This detection isn't compatible on how `parse_general_jest_fn_call` handle if a node is valid or not. To make it simple:
109+ *
110+ * - Jest file: ctx.frameworks().is_jest() is true && ctx.frameworks().is_vitest() is false
111+ * - Vitest file: ctx.frameworks().is_jest() is true && ctx.frameworks().is_vitest is true
112+ *
113+ * And if you are dealing with non compatible modifiers or methods, that only exists in vitest, it will fail as in jest doesn't exist.
114+ *
115+ * In case of dealing with syntax that only exists in vitest, add an import of `vitest` to force the ContextHost to detect we are dealing with vitest.
116+ * This probably will allow reuse allow of the methods that rely on this false negative detection.
117+ */
118+ macro_rules! vitest_context {
119+ ( $test: literal) => {
120+ concat!( "import * as vi from 'vitest'\n \n " , $test)
121+ } ;
122+ }
123+
101124 let pass = vec ! [
102- ( "describe('foo', function () {})" , None ) ,
103- ( "it('foo', function () {})" , None ) ,
104- ( "it.concurrent('foo', function () {})" , None ) ,
105- ( "test('foo', function () {})" , None ) ,
106- ( "test.concurrent('foo', function () {})" , None ) ,
107- ( "describe.only('foo', function () {})" , None ) ,
108- ( "it.only('foo', function () {})" , None ) ,
109- ( "it.each()('foo', function () {})" , None ) ,
125+ ( vitest_context! ( "describe('foo', function () {})" ) , None ) ,
126+ ( vitest_context! ( "it('foo', function () {})" ) , None ) ,
127+ ( vitest_context! ( "it.concurrent('foo', function () {})" ) , None ) ,
128+ ( vitest_context! ( "test('foo', function () {})" ) , None ) ,
129+ ( vitest_context! ( "test.concurrent('foo', function () {})" ) , None ) ,
130+ ( vitest_context! ( "describe.only('foo', function () {})" ) , None ) ,
131+ ( vitest_context! ( "it.only('foo', function () {})" ) , None ) ,
132+ ( vitest_context! ( "it.each()('foo', function () {})" ) , None ) ,
110133 ] ;
111134
112135 let fail = vec ! [
113- ( "describe.todo('foo', function () {})" , None ) ,
114- ( "it.todo('foo', function () {})" , None ) ,
115- ( "test.todo('foo', function () {})" , None ) ,
116- ( "describe.todo.each([])('foo', function () {})" , None ) ,
117- ( "it.todo.each([])('foo', function () {})" , None ) ,
118- ( "test.todo.each([])('foo', function () {})" , None ) ,
119- ( "describe.only.todo('foo', function () {})" , None ) ,
120- ( "it.only.todo('foo', function () {})" , None ) ,
121- ( "test.only.todo('foo', function () {})" , None ) ,
136+ ( vitest_context! ( "describe.todo('foo', function () {})" ) , None ) ,
137+ ( vitest_context! ( "it.todo('foo', function () {})" ) , None ) ,
138+ ( vitest_context! ( "test.todo('foo', function () {})" ) , None ) ,
139+ ( vitest_context! ( "describe.todo.each([])('foo', function () {})" ) , None ) ,
140+ ( vitest_context! ( "it.todo.each([])('foo', function () {})" ) , None ) ,
141+ ( vitest_context! ( "test.todo.each([])('foo', function () {})" ) , None ) ,
142+ ( vitest_context! ( "describe.only.todo('foo', function () {})" ) , None ) ,
143+ ( vitest_context! ( "it.only.todo('foo', function () {})" ) , None ) ,
144+ ( vitest_context! ( "test.only.todo('foo', function () {})" ) , None ) ,
122145 ] ;
123146
124- Tester :: new ( WarnTodo :: NAME , WarnTodo :: PLUGIN , pass, fail) . test_and_snapshot ( ) ;
147+ Tester :: new ( WarnTodo :: NAME , WarnTodo :: PLUGIN , pass, fail)
148+ . with_vitest_plugin ( true )
149+ . test_and_snapshot ( ) ;
125150}
0 commit comments