Skip to content

Commit

Permalink
Revert "fix: improve support for it.each involving tagged template li…
Browse files Browse the repository at this point in the history
…terals (#701)"

This reverts commit 2341814.
  • Loading branch information
SimenB committed Nov 12, 2020
1 parent 0713718 commit 5cc1d1b
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 209 deletions.
72 changes: 0 additions & 72 deletions src/rules/__tests__/consistent-test-it.test.ts
Expand Up @@ -32,14 +32,6 @@ ruleTester.run('consistent-test-it with fn=test', rule, {
code: 'xtest("foo")',
options: [{ fn: TestCaseName.test }],
},
{
code: 'test.each([])("foo")',
options: [{ fn: TestCaseName.test }],
},
{
code: 'test.each``("foo")',
options: [{ fn: TestCaseName.test }],
},
{
code: 'describe("suite", () => { test("foo") })',
options: [{ fn: TestCaseName.test }],
Expand Down Expand Up @@ -130,34 +122,6 @@ ruleTester.run('consistent-test-it with fn=test', rule, {
},
],
},
{
code: 'it.each([])("foo")',
output: 'test.each([])("foo")',
options: [{ fn: TestCaseName.test }],
errors: [
{
messageId: 'consistentMethod',
data: {
testKeyword: TestCaseName.test,
oppositeTestKeyword: TestCaseName.it,
},
},
],
},
{
code: 'it.each``("foo")',
output: 'test.each``("foo")',
options: [{ fn: TestCaseName.test }],
errors: [
{
messageId: 'consistentMethod',
data: {
testKeyword: TestCaseName.test,
oppositeTestKeyword: TestCaseName.it,
},
},
],
},
{
code: 'describe("suite", () => { it("foo") })',
output: 'describe("suite", () => { test("foo") })',
Expand Down Expand Up @@ -201,14 +165,6 @@ ruleTester.run('consistent-test-it with fn=it', rule, {
code: 'it.concurrent("foo")',
options: [{ fn: TestCaseName.it }],
},
{
code: 'it.each([])("foo")',
options: [{ fn: TestCaseName.it }],
},
{
code: 'it.each``("foo")',
options: [{ fn: TestCaseName.it }],
},
{
code: 'describe("suite", () => { it("foo") })',
options: [{ fn: TestCaseName.it }],
Expand Down Expand Up @@ -285,34 +241,6 @@ ruleTester.run('consistent-test-it with fn=it', rule, {
},
],
},
{
code: 'test.each([])("foo")',
output: 'it.each([])("foo")',
options: [{ fn: TestCaseName.it }],
errors: [
{
messageId: 'consistentMethod',
data: {
testKeyword: TestCaseName.it,
oppositeTestKeyword: TestCaseName.test,
},
},
],
},
{
code: 'test.each``("foo")',
output: 'it.each``("foo")',
options: [{ fn: TestCaseName.it }],
errors: [
{
messageId: 'consistentMethod',
data: {
testKeyword: TestCaseName.it,
oppositeTestKeyword: TestCaseName.test,
},
},
],
},
{
code: 'describe("suite", () => { test("foo") })',
output: 'describe("suite", () => { it("foo") })',
Expand Down
33 changes: 0 additions & 33 deletions src/rules/__tests__/no-disabled-tests.test.ts
Expand Up @@ -16,7 +16,6 @@ ruleTester.run('no-disabled-tests', rule, {
'it("foo", function () {})',
'describe.only("foo", function () {})',
'it.only("foo", function () {})',
'it.each("foo", () => {})',
'it.concurrent("foo", function () {})',
'test("foo", function () {})',
'test.only("foo", function () {})',
Expand Down Expand Up @@ -88,22 +87,6 @@ ruleTester.run('no-disabled-tests', rule, {
code: 'test.skip("foo", function () {})',
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
},
{
code: 'it.skip.each``("foo", function () {})',
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
},
{
code: 'test.skip.each``("foo", function () {})',
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
},
{
code: 'it.skip.each([])("foo", function () {})',
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
},
{
code: 'test.skip.each([])("foo", function () {})',
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
},
{
code: 'test.concurrent.skip("foo", function () {})',
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
Expand All @@ -124,22 +107,6 @@ ruleTester.run('no-disabled-tests', rule, {
code: 'xtest("foo", function () {})',
errors: [{ messageId: 'disabledTest', column: 1, line: 1 }],
},
{
code: 'xit.each``("foo", function () {})',
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
},
{
code: 'xtest.each``("foo", function () {})',
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
},
{
code: 'xit.each([])("foo", function () {})',
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
},
{
code: 'xtest.each([])("foo", function () {})',
errors: [{ messageId: 'skippedTest', column: 1, line: 1 }],
},
{
code: 'it("has title but no callback")',
errors: [{ messageId: 'missingFunction', column: 1, line: 1 }],
Expand Down
4 changes: 0 additions & 4 deletions src/rules/__tests__/no-standalone-expect.test.ts
Expand Up @@ -57,10 +57,6 @@ ruleTester.run('no-standalone-expect', rule, {
},
],
invalid: [
{
code: "(() => {})('testing', () => expect(true))",
errors: [{ endColumn: 41, column: 29, messageId: 'unexpectedExpect' }],
},
{
code: `
describe('scenario', () => {
Expand Down
60 changes: 0 additions & 60 deletions src/rules/__tests__/no-test-prefixes.test.ts
Expand Up @@ -12,18 +12,8 @@ ruleTester.run('no-test-prefixes', rule, {
'test.concurrent("foo", function () {})',
'describe.only("foo", function () {})',
'it.only("foo", function () {})',
'it.each()("foo", function () {})',
{
code: 'it.each``("foo", function () {})',
parserOptions: { ecmaVersion: 6 },
},
'it.concurrent.only("foo", function () {})',
'test.only("foo", function () {})',
'test.each()("foo", function () {})',
{
code: 'test.each``("foo", function () {})',
parserOptions: { ecmaVersion: 6 },
},
'test.concurrent.only("foo", function () {})',
'describe.skip("foo", function () {})',
'it.skip("foo", function () {})',
Expand Down Expand Up @@ -106,55 +96,5 @@ ruleTester.run('no-test-prefixes', rule, {
},
],
},
{
code: 'xit.each``("foo", function () {})',
output: 'it.skip.each``("foo", function () {})',
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: 'usePreferredName',
data: { preferredNodeName: 'it.skip.each' },
column: 1,
line: 1,
},
],
},
{
code: 'xtest.each``("foo", function () {})',
output: 'test.skip.each``("foo", function () {})',
parserOptions: { ecmaVersion: 6 },
errors: [
{
messageId: 'usePreferredName',
data: { preferredNodeName: 'test.skip.each' },
column: 1,
line: 1,
},
],
},
{
code: 'xit.each([])("foo", function () {})',
output: 'it.skip.each([])("foo", function () {})',
errors: [
{
messageId: 'usePreferredName',
data: { preferredNodeName: 'it.skip.each' },
column: 1,
line: 1,
},
],
},
{
code: 'xtest.each([])("foo", function () {})',
output: 'test.skip.each([])("foo", function () {})',
errors: [
{
messageId: 'usePreferredName',
data: { preferredNodeName: 'test.skip.each' },
column: 1,
line: 1,
},
],
},
],
});
9 changes: 2 additions & 7 deletions src/rules/consistent-test-it.ts
Expand Up @@ -82,11 +82,6 @@ export default createRule<
describeNestingLevel++;
}

const funcNode =
node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression
? node.callee.tag
: node.callee;

if (
isTestCase(node) &&
describeNestingLevel === 0 &&
Expand All @@ -98,7 +93,7 @@ export default createRule<
messageId: 'consistentMethod',
node: node.callee,
data: { testKeyword, oppositeTestKeyword },
fix: buildFixer(funcNode, nodeName, testKeyword),
fix: buildFixer(node.callee, nodeName, testKeyword),
});
}

Expand All @@ -115,7 +110,7 @@ export default createRule<
messageId: 'consistentMethodWithinDescribe',
node: node.callee,
data: { testKeywordWithinDescribe, oppositeTestKeyword },
fix: buildFixer(funcNode, nodeName, testKeywordWithinDescribe),
fix: buildFixer(node.callee, nodeName, testKeywordWithinDescribe),
});
}
},
Expand Down
7 changes: 0 additions & 7 deletions src/rules/no-disabled-tests.ts
Expand Up @@ -39,9 +39,6 @@ export default createRule({
CallExpression(node) {
const functionName = getNodeName(node.callee);

// prevent duplicate warnings for it.each()()
if (node.callee.type === 'CallExpression') return;

switch (functionName) {
case 'describe.skip':
context.report({ messageId: 'skippedTestSuite', node });
Expand All @@ -51,10 +48,6 @@ export default createRule({
case 'it.concurrent.skip':
case 'test.skip':
case 'test.concurrent.skip':
case 'it.skip.each':
case 'test.skip.each':
case 'xit.each':
case 'xtest.each':
context.report({ messageId: 'skippedTest', node });
break;
}
Expand Down
14 changes: 3 additions & 11 deletions src/rules/no-test-prefixes.ts
@@ -1,4 +1,3 @@
import { AST_NODE_TYPES } from '@typescript-eslint/experimental-utils';
import { createRule, getNodeName, isDescribe, isTestCase } from './utils';

export default createRule({
Expand Down Expand Up @@ -28,17 +27,12 @@ export default createRule({

if (!preferredNodeName) return;

const funcNode =
node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression
? node.callee.tag
: node.callee;

context.report({
messageId: 'usePreferredName',
node: node.callee,
data: { preferredNodeName },
fix(fixer) {
return [fixer.replaceText(funcNode, preferredNodeName)];
return [fixer.replaceText(node.callee, preferredNodeName)];
},
});
},
Expand All @@ -49,14 +43,12 @@ export default createRule({
function getPreferredNodeName(nodeName: string) {
const firstChar = nodeName.charAt(0);

const suffix = nodeName.endsWith('.each') ? '.each' : '';

if (firstChar === 'f') {
return `${nodeName.slice(1).replace('.each', '')}.only${suffix}`;
return `${nodeName.slice(1)}.only`;
}

if (firstChar === 'x') {
return `${nodeName.slice(1).replace('.each', '')}.skip${suffix}`;
return `${nodeName.slice(1)}.skip`;
}

return null;
Expand Down
16 changes: 1 addition & 15 deletions src/rules/utils.ts
Expand Up @@ -580,16 +580,10 @@ export interface JestFunctionCallExpressionWithIdentifierCallee<
callee: JestFunctionIdentifier<FunctionName>;
}

interface JestFunctionCallExpressionWithTaggedTemplateCallee
extends TSESTree.CallExpression {
callee: TSESTree.TaggedTemplateExpression;
}

export type JestFunctionCallExpression<
FunctionName extends JestFunctionName = JestFunctionName
> =
| JestFunctionCallExpressionWithMemberExpressionCallee<FunctionName>
| JestFunctionCallExpressionWithTaggedTemplateCallee
| JestFunctionCallExpressionWithIdentifierCallee<FunctionName>;

const joinNames = (a: string | null, b: string | null): string | null =>
Expand All @@ -598,8 +592,7 @@ const joinNames = (a: string | null, b: string | null): string | null =>
export function getNodeName(
node:
| JestFunctionMemberExpression<JestFunctionName>
| JestFunctionIdentifier<JestFunctionName>
| TSESTree.TaggedTemplateExpression,
| JestFunctionIdentifier<JestFunctionName>,
): string;
export function getNodeName(node: TSESTree.Node): string | null;
export function getNodeName(node: TSESTree.Node): string | null {
Expand All @@ -608,8 +601,6 @@ export function getNodeName(node: TSESTree.Node): string | null {
}

switch (node.type) {
case AST_NODE_TYPES.TaggedTemplateExpression:
return getNodeName(node.tag);
case AST_NODE_TYPES.MemberExpression:
return joinNames(getNodeName(node.object), getNodeName(node.property));
case AST_NODE_TYPES.NewExpression:
Expand Down Expand Up @@ -660,11 +651,6 @@ export const isTestCase = (
): node is JestFunctionCallExpression<TestCaseName> =>
(node.callee.type === AST_NODE_TYPES.Identifier &&
TestCaseName.hasOwnProperty(node.callee.name)) ||
// e.g. it.each``()
(node.callee.type === AST_NODE_TYPES.TaggedTemplateExpression &&
node.callee.tag.type === AST_NODE_TYPES.MemberExpression &&
isSupportedAccessor(node.callee.tag.property, TestCaseProperty.each)) ||
// e.g. it.concurrent.{skip,only}
(node.callee.type === AST_NODE_TYPES.MemberExpression &&
node.callee.property.type === AST_NODE_TYPES.Identifier &&
TestCaseProperty.hasOwnProperty(node.callee.property.name) &&
Expand Down

0 comments on commit 5cc1d1b

Please sign in to comment.