From f1a767400967bd923512f79e80f283b3b2afa772 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 2 Jan 2022 09:40:00 +1300 Subject: [PATCH] fix(prefer-lowercase-title): ignore `it` and `test` separately (#1011) --- .../__tests__/prefer-lowercase-title.test.ts | 115 +++++++++++++++++- src/rules/prefer-lowercase-title.ts | 8 +- 2 files changed, 117 insertions(+), 6 deletions(-) diff --git a/src/rules/__tests__/prefer-lowercase-title.test.ts b/src/rules/__tests__/prefer-lowercase-title.test.ts index 5c2791388..5ca74e2a8 100644 --- a/src/rules/__tests__/prefer-lowercase-title.test.ts +++ b/src/rules/__tests__/prefer-lowercase-title.test.ts @@ -270,7 +270,34 @@ ruleTester.run('prefer-lowercase-title with ignore=describe', rule, { options: [{ ignore: [DescribeAlias.describe] }], }, ], - invalid: [], + invalid: [ + { + code: "test('Foo', function () {})", + output: "test('foo', function () {})", + options: [{ ignore: [DescribeAlias.describe] }], + errors: [ + { + messageId: 'unexpectedLowercase', + data: { method: TestCaseName.test }, + column: 6, + line: 1, + }, + ], + }, + { + code: "xit('Foo', function () {})", + output: "xit('foo', function () {})", + options: [{ ignore: [DescribeAlias.describe] }], + errors: [ + { + messageId: 'unexpectedLowercase', + data: { method: TestCaseName.xit }, + column: 5, + line: 1, + }, + ], + }, + ], }); ruleTester.run('prefer-lowercase-title with ignore=test', rule, { @@ -296,7 +323,47 @@ ruleTester.run('prefer-lowercase-title with ignore=test', rule, { options: [{ ignore: [TestCaseName.test] }], }, ], - invalid: [], + invalid: [ + { + code: "describe('Foo', function () {})", + output: "describe('foo', function () {})", + options: [{ ignore: [TestCaseName.test] }], + errors: [ + { + messageId: 'unexpectedLowercase', + data: { method: DescribeAlias.describe }, + column: 10, + line: 1, + }, + ], + }, + { + code: "it('Foo', function () {})", + output: "it('foo', function () {})", + options: [{ ignore: [TestCaseName.test] }], + errors: [ + { + messageId: 'unexpectedLowercase', + data: { method: TestCaseName.it }, + column: 4, + line: 1, + }, + ], + }, + { + code: "xit('Foo', function () {})", + output: "xit('foo', function () {})", + options: [{ ignore: [TestCaseName.test] }], + errors: [ + { + messageId: 'unexpectedLowercase', + data: { method: TestCaseName.xit }, + column: 5, + line: 1, + }, + ], + }, + ], }); ruleTester.run('prefer-lowercase-title with ignore=it', rule, { @@ -322,7 +389,47 @@ ruleTester.run('prefer-lowercase-title with ignore=it', rule, { options: [{ ignore: [TestCaseName.it] }], }, ], - invalid: [], + invalid: [ + { + code: "describe('Foo', function () {})", + output: "describe('foo', function () {})", + options: [{ ignore: [TestCaseName.it] }], + errors: [ + { + messageId: 'unexpectedLowercase', + data: { method: DescribeAlias.describe }, + column: 10, + line: 1, + }, + ], + }, + { + code: "test('Foo', function () {})", + output: "test('foo', function () {})", + options: [{ ignore: [TestCaseName.it] }], + errors: [ + { + messageId: 'unexpectedLowercase', + data: { method: TestCaseName.test }, + column: 6, + line: 1, + }, + ], + }, + { + code: "xtest('Foo', function () {})", + output: "xtest('foo', function () {})", + options: [{ ignore: [TestCaseName.it] }], + errors: [ + { + messageId: 'unexpectedLowercase', + data: { method: TestCaseName.xtest }, + column: 7, + line: 1, + }, + ], + }, + ], }); ruleTester.run('prefer-lowercase-title with allowedPrefixes', rule, { @@ -368,7 +475,7 @@ ruleTester.run('prefer-lowercase-title with ignoreTopLevelDescribe', rule, { expect('abc').toBe('abc'); }); }); - + describe('Booleans', () => { it('are booleans', () => { expect(true).toBe(true); diff --git a/src/rules/prefer-lowercase-title.ts b/src/rules/prefer-lowercase-title.ts index f0b9571f1..d316f79c0 100644 --- a/src/rules/prefer-lowercase-title.ts +++ b/src/rules/prefer-lowercase-title.ts @@ -43,10 +43,14 @@ const populateIgnores = (ignore: readonly string[]): string[] => { ignores.push(...Object.keys(DescribeAlias)); } if (ignore.includes(TestCaseName.test)) { - ignores.push(...Object.keys(TestCaseName)); + ignores.push( + ...Object.keys(TestCaseName).filter(k => k.endsWith(TestCaseName.test)), + ); } if (ignore.includes(TestCaseName.it)) { - ignores.push(...Object.keys(TestCaseName)); + ignores.push( + ...Object.keys(TestCaseName).filter(k => k.endsWith(TestCaseName.it)), + ); } return ignores;