Skip to content

Commit

Permalink
fix(no-identical-title): improved internal error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
veritem committed Dec 16, 2023
1 parent 7382c42 commit 6f332c5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/rules/no-identical-title.ts
Expand Up @@ -57,13 +57,13 @@ export default createEslintRule<Options, MESSAGE_ID>({
const title = getStringValue(argument)

if (vitestFnCall.type === 'test') {
if (currentStack.testTitles.includes(title)) {
if (currentStack?.testTitles.includes(title)) {
context.report({
node,
messageId: 'multipleTestTitle'
})
}
currentStack.testTitles.push(title)
currentStack?.testTitles.push(title)
}

if (vitestFnCall.type !== 'describe')
Expand Down
3 changes: 0 additions & 3 deletions src/utils/validVitestFnCallChains.ts
Expand Up @@ -1005,9 +1005,6 @@ export const ValidVitestFnCallChains = new Set([
'describe.runIf.sequential.each',
'describe.runIf.shuffle.each',
'describe.runIf.todo.each',

// Call chains that are not supported by Vitest, but were in the original list
// TODO(@veritem): Remove the use of these call chains in the test suite
'xtest',
'xtest.each',
'xit',
Expand Down
35 changes: 24 additions & 11 deletions tests/no-identical-title.test.ts
Expand Up @@ -2,21 +2,34 @@ import rule, { RULE_NAME } from '../src/rules/no-identical-title'
import { ruleTester } from './ruleTester'

ruleTester.run(RULE_NAME, rule, {
valid: ['it(); it();', 'test("two", () => {});'],
invalid: [
{
code: `describe('foo', () => {
valid: [
'it(); it();',
'test("two", () => {});',
`fdescribe('a describe', () => {
test('a test', () => {
expect(true).toBe(true);
});
});
fdescribe('another describe', () => {
test('a test', () => {
expect(true).toBe(true);
});
});`
],
invalid: [
{
code: `describe('foo', () => {
it('works', () => {});
it('works', () => {});
});`,
errors: [{ messageId: 'multipleTestTitle' }]
},
{
code: `xdescribe('foo', () => {
errors: [{ messageId: 'multipleTestTitle' }]
},
{
code: `xdescribe('foo', () => {
it('works', () => {});
it('works', () => {});
});`,
errors: [{ messageId: 'multipleTestTitle' }]
}
]
errors: [{ messageId: 'multipleTestTitle' }]
}
]
})

0 comments on commit 6f332c5

Please sign in to comment.