Skip to content

Commit 5cc1d1b

Browse files
committed
Revert "fix: improve support for it.each involving tagged template literals (#701)"
This reverts commit 2341814.
1 parent 0713718 commit 5cc1d1b

8 files changed

+6
-209
lines changed

src/rules/__tests__/consistent-test-it.test.ts

-72
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ ruleTester.run('consistent-test-it with fn=test', rule, {
3232
code: 'xtest("foo")',
3333
options: [{ fn: TestCaseName.test }],
3434
},
35-
{
36-
code: 'test.each([])("foo")',
37-
options: [{ fn: TestCaseName.test }],
38-
},
39-
{
40-
code: 'test.each``("foo")',
41-
options: [{ fn: TestCaseName.test }],
42-
},
4335
{
4436
code: 'describe("suite", () => { test("foo") })',
4537
options: [{ fn: TestCaseName.test }],
@@ -130,34 +122,6 @@ ruleTester.run('consistent-test-it with fn=test', rule, {
130122
},
131123
],
132124
},
133-
{
134-
code: 'it.each([])("foo")',
135-
output: 'test.each([])("foo")',
136-
options: [{ fn: TestCaseName.test }],
137-
errors: [
138-
{
139-
messageId: 'consistentMethod',
140-
data: {
141-
testKeyword: TestCaseName.test,
142-
oppositeTestKeyword: TestCaseName.it,
143-
},
144-
},
145-
],
146-
},
147-
{
148-
code: 'it.each``("foo")',
149-
output: 'test.each``("foo")',
150-
options: [{ fn: TestCaseName.test }],
151-
errors: [
152-
{
153-
messageId: 'consistentMethod',
154-
data: {
155-
testKeyword: TestCaseName.test,
156-
oppositeTestKeyword: TestCaseName.it,
157-
},
158-
},
159-
],
160-
},
161125
{
162126
code: 'describe("suite", () => { it("foo") })',
163127
output: 'describe("suite", () => { test("foo") })',
@@ -201,14 +165,6 @@ ruleTester.run('consistent-test-it with fn=it', rule, {
201165
code: 'it.concurrent("foo")',
202166
options: [{ fn: TestCaseName.it }],
203167
},
204-
{
205-
code: 'it.each([])("foo")',
206-
options: [{ fn: TestCaseName.it }],
207-
},
208-
{
209-
code: 'it.each``("foo")',
210-
options: [{ fn: TestCaseName.it }],
211-
},
212168
{
213169
code: 'describe("suite", () => { it("foo") })',
214170
options: [{ fn: TestCaseName.it }],
@@ -285,34 +241,6 @@ ruleTester.run('consistent-test-it with fn=it', rule, {
285241
},
286242
],
287243
},
288-
{
289-
code: 'test.each([])("foo")',
290-
output: 'it.each([])("foo")',
291-
options: [{ fn: TestCaseName.it }],
292-
errors: [
293-
{
294-
messageId: 'consistentMethod',
295-
data: {
296-
testKeyword: TestCaseName.it,
297-
oppositeTestKeyword: TestCaseName.test,
298-
},
299-
},
300-
],
301-
},
302-
{
303-
code: 'test.each``("foo")',
304-
output: 'it.each``("foo")',
305-
options: [{ fn: TestCaseName.it }],
306-
errors: [
307-
{
308-
messageId: 'consistentMethod',
309-
data: {
310-
testKeyword: TestCaseName.it,
311-
oppositeTestKeyword: TestCaseName.test,
312-
},
313-
},
314-
],
315-
},
316244
{
317245
code: 'describe("suite", () => { test("foo") })',
318246
output: 'describe("suite", () => { it("foo") })',

src/rules/__tests__/no-disabled-tests.test.ts

-33
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ ruleTester.run('no-disabled-tests', rule, {
1616
'it("foo", function () {})',
1717
'describe.only("foo", function () {})',
1818
'it.only("foo", function () {})',
19-
'it.each("foo", () => {})',
2019
'it.concurrent("foo", function () {})',
2120
'test("foo", function () {})',
2221
'test.only("foo", function () {})',
@@ -88,22 +87,6 @@ ruleTester.run('no-disabled-tests', rule, {
8887
code: 'test.skip("foo", function () {})',
8988
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
9089
},
91-
{
92-
code: 'it.skip.each``("foo", function () {})',
93-
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
94-
},
95-
{
96-
code: 'test.skip.each``("foo", function () {})',
97-
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
98-
},
99-
{
100-
code: 'it.skip.each([])("foo", function () {})',
101-
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
102-
},
103-
{
104-
code: 'test.skip.each([])("foo", function () {})',
105-
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
106-
},
10790
{
10891
code: 'test.concurrent.skip("foo", function () {})',
10992
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
@@ -124,22 +107,6 @@ ruleTester.run('no-disabled-tests', rule, {
124107
code: 'xtest("foo", function () {})',
125108
errors: [{ messageId: 'disabledTest', column: 1, line: 1 }],
126109
},
127-
{
128-
code: 'xit.each``("foo", function () {})',
129-
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
130-
},
131-
{
132-
code: 'xtest.each``("foo", function () {})',
133-
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
134-
},
135-
{
136-
code: 'xit.each([])("foo", function () {})',
137-
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
138-
},
139-
{
140-
code: 'xtest.each([])("foo", function () {})',
141-
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
142-
},
143110
{
144111
code: 'it("has title but no callback")',
145112
errors: [{ messageId: 'missingFunction', column: 1, line: 1 }],

src/rules/__tests__/no-standalone-expect.test.ts

-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,6 @@ ruleTester.run('no-standalone-expect', rule, {
5757
},
5858
],
5959
invalid: [
60-
{
61-
code: "(() => {})('testing', () => expect(true))",
62-
errors: [{ endColumn: 41, column: 29, messageId: 'unexpectedExpect' }],
63-
},
6460
{
6561
code: `
6662
describe('scenario', () => {

src/rules/__tests__/no-test-prefixes.test.ts

-60
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,8 @@ ruleTester.run('no-test-prefixes', rule, {
1212
'test.concurrent("foo", function () {})',
1313
'describe.only("foo", function () {})',
1414
'it.only("foo", function () {})',
15-
'it.each()("foo", function () {})',
16-
{
17-
code: 'it.each``("foo", function () {})',
18-
parserOptions: { ecmaVersion: 6 },
19-
},
2015
'it.concurrent.only("foo", function () {})',
2116
'test.only("foo", function () {})',
22-
'test.each()("foo", function () {})',
23-
{
24-
code: 'test.each``("foo", function () {})',
25-
parserOptions: { ecmaVersion: 6 },
26-
},
2717
'test.concurrent.only("foo", function () {})',
2818
'describe.skip("foo", function () {})',
2919
'it.skip("foo", function () {})',
@@ -106,55 +96,5 @@ ruleTester.run('no-test-prefixes', rule, {
10696
},
10797
],
10898
},
109-
{
110-
code: 'xit.each``("foo", function () {})',
111-
output: 'it.skip.each``("foo", function () {})',
112-
parserOptions: { ecmaVersion: 6 },
113-
errors: [
114-
{
115-
messageId: 'usePreferredName',
116-
data: { preferredNodeName: 'it.skip.each' },
117-
column: 1,
118-
line: 1,
119-
},
120-
],
121-
},
122-
{
123-
code: 'xtest.each``("foo", function () {})',
124-
output: 'test.skip.each``("foo", function () {})',
125-
parserOptions: { ecmaVersion: 6 },
126-
errors: [
127-
{
128-
messageId: 'usePreferredName',
129-
data: { preferredNodeName: 'test.skip.each' },
130-
column: 1,
131-
line: 1,
132-
},
133-
],
134-
},
135-
{
136-
code: 'xit.each([])("foo", function () {})',
137-
output: 'it.skip.each([])("foo", function () {})',
138-
errors: [
139-
{
140-
messageId: 'usePreferredName',
141-
data: { preferredNodeName: 'it.skip.each' },
142-
column: 1,
143-
line: 1,
144-
},
145-
],
146-
},
147-
{
148-
code: 'xtest.each([])("foo", function () {})',
149-
output: 'test.skip.each([])("foo", function () {})',
150-
errors: [
151-
{
152-
messageId: 'usePreferredName',
153-
data: { preferredNodeName: 'test.skip.each' },
154-
column: 1,
155-
line: 1,
156-
},
157-
],
158-
},
15999
],
160100
});

src/rules/consistent-test-it.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,6 @@ export default createRule<
8282
describeNestingLevel++;
8383
}
8484

85-
const funcNode =
86-
node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression
87-
? node.callee.tag
88-
: node.callee;
89-
9085
if (
9186
isTestCase(node) &&
9287
describeNestingLevel === 0 &&
@@ -98,7 +93,7 @@ export default createRule<
9893
messageId: 'consistentMethod',
9994
node: node.callee,
10095
data: { testKeyword, oppositeTestKeyword },
101-
fix: buildFixer(funcNode, nodeName, testKeyword),
96+
fix: buildFixer(node.callee, nodeName, testKeyword),
10297
});
10398
}
10499

@@ -115,7 +110,7 @@ export default createRule<
115110
messageId: 'consistentMethodWithinDescribe',
116111
node: node.callee,
117112
data: { testKeywordWithinDescribe, oppositeTestKeyword },
118-
fix: buildFixer(funcNode, nodeName, testKeywordWithinDescribe),
113+
fix: buildFixer(node.callee, nodeName, testKeywordWithinDescribe),
119114
});
120115
}
121116
},

src/rules/no-disabled-tests.ts

-7
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ export default createRule({
3939
CallExpression(node) {
4040
const functionName = getNodeName(node.callee);
4141

42-
// prevent duplicate warnings for it.each()()
43-
if (node.callee.type === 'CallExpression') return;
44-
4542
switch (functionName) {
4643
case 'describe.skip':
4744
context.report({ messageId: 'skippedTestSuite', node });
@@ -51,10 +48,6 @@ export default createRule({
5148
case 'it.concurrent.skip':
5249
case 'test.skip':
5350
case 'test.concurrent.skip':
54-
case 'it.skip.each':
55-
case 'test.skip.each':
56-
case 'xit.each':
57-
case 'xtest.each':
5851
context.report({ messageId: 'skippedTest', node });
5952
break;
6053
}

src/rules/no-test-prefixes.ts

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils';
21
import { createRule, getNodeName, isDescribe, isTestCase } from './utils';
32

43
export default createRule({
@@ -28,17 +27,12 @@ export default createRule({
2827

2928
if (!preferredNodeName) return;
3029

31-
const funcNode =
32-
node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression
33-
? node.callee.tag
34-
: node.callee;
35-
3630
context.report({
3731
messageId: 'usePreferredName',
3832
node: node.callee,
3933
data: { preferredNodeName },
4034
fix(fixer) {
41-
return [fixer.replaceText(funcNode, preferredNodeName)];
35+
return [fixer.replaceText(node.callee, preferredNodeName)];
4236
},
4337
});
4438
},
@@ -49,14 +43,12 @@ export default createRule({
4943
function getPreferredNodeName(nodeName: string) {
5044
const firstChar = nodeName.charAt(0);
5145

52-
const suffix = nodeName.endsWith('.each') ? '.each' : '';
53-
5446
if (firstChar === 'f') {
55-
return `${nodeName.slice(1).replace('.each', '')}.only${suffix}`;
47+
return `${nodeName.slice(1)}.only`;
5648
}
5749

5850
if (firstChar === 'x') {
59-
return `${nodeName.slice(1).replace('.each', '')}.skip${suffix}`;
51+
return `${nodeName.slice(1)}.skip`;
6052
}
6153

6254
return null;

src/rules/utils.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -580,16 +580,10 @@ export interface JestFunctionCallExpressionWithIdentifierCallee<
580580
callee: JestFunctionIdentifier<FunctionName>;
581581
}
582582

583-
interface JestFunctionCallExpressionWithTaggedTemplateCallee
584-
extends TSESTree.CallExpression {
585-
callee: TSESTree.TaggedTemplateExpression;
586-
}
587-
588583
export type JestFunctionCallExpression<
589584
FunctionName extends JestFunctionName = JestFunctionName
590585
> =
591586
| JestFunctionCallExpressionWithMemberExpressionCallee<FunctionName>
592-
| JestFunctionCallExpressionWithTaggedTemplateCallee
593587
| JestFunctionCallExpressionWithIdentifierCallee<FunctionName>;
594588

595589
const joinNames = (a: string | null, b: string | null): string | null =>
@@ -598,8 +592,7 @@ const joinNames = (a: string | null, b: string | null): string | null =>
598592
export function getNodeName(
599593
node:
600594
| JestFunctionMemberExpression<JestFunctionName>
601-
| JestFunctionIdentifier<JestFunctionName>
602-
| TSESTree.TaggedTemplateExpression,
595+
| JestFunctionIdentifier<JestFunctionName>,
603596
): string;
604597
export function getNodeName(node: TSESTree.Node): string | null;
605598
export function getNodeName(node: TSESTree.Node): string | null {
@@ -608,8 +601,6 @@ export function getNodeName(node: TSESTree.Node): string | null {
608601
}
609602

610603
switch (node.type) {
611-
case AST_NODE_TYPES.TaggedTemplateExpression:
612-
return getNodeName(node.tag);
613604
case AST_NODE_TYPES.MemberExpression:
614605
return joinNames(getNodeName(node.object), getNodeName(node.property));
615606
case AST_NODE_TYPES.NewExpression:
@@ -660,11 +651,6 @@ export const isTestCase = (
660651
): node is JestFunctionCallExpression<TestCaseName> =>
661652
(node.callee.type === AST_NODE_TYPES.Identifier &&
662653
TestCaseName.hasOwnProperty(node.callee.name)) ||
663-
// e.g. it.each``()
664-
(node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression &&
665-
node.callee.tag.type === AST_NODE_TYPES.MemberExpression &&
666-
isSupportedAccessor(node.callee.tag.property, TestCaseProperty.each)) ||
667-
// e.g. it.concurrent.{skip,only}
668654
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
669655
node.callee.property.type === AST_NODE_TYPES.Identifier &&
670656
TestCaseProperty.hasOwnProperty(node.callee.property.name) &&

0 commit comments

Comments
 (0)