Skip to content

Commit

Permalink
feat(no-disabled-tests): make error ranges smaller (#278)
Browse files Browse the repository at this point in the history
* test(no-disabled-tests): add failing tests for error ranges

* feat(no-disabled-tests): make error ranges smaller

Fixes #270.

* feat: updated format

---------

Co-authored-by: Verite Mugabo <mugaboverite@gmail.com>
  • Loading branch information
lydell and veritem authored Oct 22, 2023
1 parent e772f8e commit 8793664
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/rules/no-disabled-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ export default createEslintRule<Options, MESSAGE_ID>({
}
}

if (vitestFnCall.name.startsWith('x') || vitestFnCall.members.some(s => getAccessorValue(s) === 'skip')) {
const skipMember = vitestFnCall.members.find(s => getAccessorValue(s) === 'skip')
if (vitestFnCall.name.startsWith('x') || skipMember !== undefined) {
context.report({
messageId: vitestFnCall.type === 'describe' ? 'disabledSuite' : 'disabledTest',
node
node: skipMember ?? vitestFnCall.head.node
})
}
},
Expand Down
94 changes: 85 additions & 9 deletions tests/no-disabled-tests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,121 @@ ruleTester.run(RULE_NAME, rule, {
code: 'describe.skip("foo", function () {})',
errors: [
{
column: 10,
endColumn: 14,
endLine: 1,
line: 1,
messageId: 'disabledSuite'
}
]
},
{
code: 'it("contains a call to pending", function () { pending() })',
errors: [{ messageId: 'pendingTest', column: 48, line: 1 }]
errors: [
{
column: 48,
endColumn: 57,
endLine: 1,
line: 1,
messageId: 'pendingTest'
}
]
},
{
code: 'xtest("foo", function () {})',
errors: [{ messageId: 'disabledTest', column: 1, line: 1 }]
errors: [
{
column: 1,
endColumn: 6,
endLine: 1,
line: 1,
messageId: 'disabledTest'
}
]
},
{
code: 'xit.each``("foo", function () {})',
errors: [{ messageId: 'disabledTest', column: 1, line: 1 }]
errors: [
{
column: 1,
endColumn: 4,
endLine: 1,
line: 1,
messageId: 'disabledTest'
}
]
},
{
code: 'xtest.each``("foo", function () {})',
errors: [{ messageId: 'disabledTest', column: 1, line: 1 }]
errors: [
{
column: 1,
endColumn: 6,
endLine: 1,
line: 1,
messageId: 'disabledTest'
}
]
},
{
code: 'xit.each([])("foo", function () {})',
errors: [{ messageId: 'disabledTest', column: 1, line: 1 }]
errors: [
{
column: 1,
endColumn: 4,
endLine: 1,
line: 1,
messageId: 'disabledTest'
}
]
},
{
code: 'it("has title but no callback")',
errors: [{ messageId: 'missingFunction', column: 1, line: 1 }]
errors: [
{
column: 1,
endColumn: 32,
endLine: 1,
line: 1,
messageId: 'missingFunction'
}
]
},
{
code: 'test("has title but no callback")',
errors: [{ messageId: 'missingFunction', column: 1, line: 1 }]
errors: [
{
column: 1,
endColumn: 34,
endLine: 1,
line: 1,
messageId: 'missingFunction'
}
]
},
{
code: 'it("contains a call to pending", function () { pending() })',
errors: [{ messageId: 'pendingTest', column: 48, line: 1 }]
errors: [
{
column: 48,
endColumn: 57,
endLine: 1,
line: 1,
messageId: 'pendingTest'
}
]
},
{
code: 'pending();',
errors: [{ messageId: 'pending', column: 1, line: 1 }]
errors: [
{
column: 1,
endColumn: 10,
endLine: 1,
line: 1,
messageId: 'pending'
}
]
}
]
})
2 changes: 1 addition & 1 deletion tests/prefer-lowercase-title.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ ruleTester.run(RULE_NAME, rule, {
}
}
]
},
}
]
})

0 comments on commit 8793664

Please sign in to comment.