From 6f332c57495d88c0560ae4c7472be7e5c08b20df Mon Sep 17 00:00:00 2001 From: Verite Mugabo Date: Sat, 16 Dec 2023 07:51:35 -0500 Subject: [PATCH] fix(no-identical-title): improved internal error handling --- src/rules/no-identical-title.ts | 4 ++-- src/utils/validVitestFnCallChains.ts | 3 --- tests/no-identical-title.test.ts | 35 +++++++++++++++++++--------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/src/rules/no-identical-title.ts b/src/rules/no-identical-title.ts index 67c8011..5b86064 100644 --- a/src/rules/no-identical-title.ts +++ b/src/rules/no-identical-title.ts @@ -57,13 +57,13 @@ export default createEslintRule({ 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') diff --git a/src/utils/validVitestFnCallChains.ts b/src/utils/validVitestFnCallChains.ts index a8f04cf..aa99f4b 100644 --- a/src/utils/validVitestFnCallChains.ts +++ b/src/utils/validVitestFnCallChains.ts @@ -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', diff --git a/tests/no-identical-title.test.ts b/tests/no-identical-title.test.ts index c44f933..7eb6a07 100644 --- a/tests/no-identical-title.test.ts +++ b/tests/no-identical-title.test.ts @@ -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' }] + } + ] })