Skip to content

Commit

Permalink
fix: valid-title false positives when test.extend is used (#584)
Browse files Browse the repository at this point in the history
* Fix `valid-title` false positive when `test.extend` is used

* chore: update

---------

Co-authored-by: Verite Mugabo <mugaboverite@gmail.com>
  • Loading branch information
aryaemami59 and veritem authored Dec 31, 2024
1 parent d832860 commit 9c2670a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/rules/valid-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,16 @@ export default createEslintRule<Options, MESSAGE_IDS>({

if (vitestFnCall?.type !== 'describe' && vitestFnCall?.type !== 'test' && vitestFnCall?.type !== 'it') return


// check if extend keyword have been used
if (vitestFnCall.members.some(m => m.type == AST_NODE_TYPES.Identifier && m.name == 'extend')) return
if (
vitestFnCall.members &&
vitestFnCall.members[0] &&
vitestFnCall.members[0].type === AST_NODE_TYPES.Identifier &&
vitestFnCall.members[0].name === 'extend'
) {
return
}

const [argument] = node.arguments

Expand Down
28 changes: 28 additions & 0 deletions tests/valid-title.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -605,3 +605,31 @@ ruleTester.run(RULE_NAME, rule, {
}
]
})

ruleTester.run(RULE_NAME, rule, {
valid: [
{
code: 'const localTest = test.extend({})',
name: 'does not error when using test.extend'
},
{
code: `import { it } from 'vitest'
const test = it.extend({
fixture: [
async ({}, use) => {
setup()
await use()
teardown()
},
{ auto: true }
],
})
test('', () => {})`,
name: 'does not error when using it.extend'
}
],

invalid: []
})

0 comments on commit 9c2670a

Please sign in to comment.