diff --git a/src/utils/parseVitestFnCall.ts b/src/utils/parseVitestFnCall.ts index 4ab2c4b..5177747 100644 --- a/src/utils/parseVitestFnCall.ts +++ b/src/utils/parseVitestFnCall.ts @@ -1,66 +1,13 @@ import { AST_NODE_TYPES, TSESLint, TSESTree } from '@typescript-eslint/utils' import { DescribeAlias, HookName, ModifierName, TestCaseName } from './types' +import { ValidVitestFnCallChains } from './validVitestFnCallChains' import { AccessorNode, getAccessorValue, getStringValue, isIdentifier, isStringNode, isSupportedAccessor } from '.' -const ValidVitestFnCallChains = [ - 'afterAll', - 'afterEach', - 'beforeAll', - 'beforeEach', - 'bench', - 'describe', - 'describe.each', - 'describe.only', - 'describe.only.each', - 'describe.skip', - 'describe.skip.each', - 'fdescribe', - 'fdescribe.each', - 'xdescribe', - 'xdescribe.each', - 'it', - 'it.concurrent', - 'it.concurrent.each', - 'it.concurrent.only.each', - 'it.concurrent.skip.each', - 'it.each', - 'it.failing', - 'it.only', - 'it.only.each', - 'it.only.failing', - 'it.skip', - 'it.skip.each', - 'it.skip.failing', - 'it.todo', - 'fit', - 'fit.each', - 'fit.failing', - 'xit', - 'xit.each', - 'xit.failing', - 'test', - 'test.concurrent', - 'test.concurrent.each', - 'test.concurrent.only.each', - 'test.concurrent.skip.each', - 'test.each', - 'test.failing', - 'test.only', - 'test.only.each', - 'test.only.failing', - 'test.skip', - 'test.skip.each', - 'test.skip.failing', - 'test.todo', - 'xtest', - 'xtest.each', - 'xtest.failing' -] - export type VitestFnType = | 'test' | 'it' | 'describe' + | 'bench' | 'expect' | 'unknown' | 'hook' diff --git a/src/utils/validVitestFnCallChains.ts b/src/utils/validVitestFnCallChains.ts new file mode 100644 index 0000000..bf3be47 --- /dev/null +++ b/src/utils/validVitestFnCallChains.ts @@ -0,0 +1,377 @@ +export const ValidVitestFnCallChains = [ + 'beforeEach', + 'beforeAll', + 'afterEach', + 'afterAll', + 'it', + 'it.extend', + 'it.skip', + 'it.skipIf', + 'it.runIf', + 'it.only', + 'it.concurrent', + 'it.todo', + 'it.fails', + 'it.each', + 'it.extend.skip', + 'it.extend.skipIf', + 'it.extend.runIf', + 'it.extend.only', + 'it.extend.concurrent', + 'it.extend.todo', + 'it.extend.fails', + 'it.extend.each', + 'it.skip.skipIf', + 'it.skip.runIf', + 'it.skip.only', + 'it.skip.concurrent', + 'it.skip.todo', + 'it.skip.fails', + 'it.skip.each', + 'it.skipIf.runIf', + 'it.skipIf.only', + 'it.skipIf.concurrent', + 'it.skipIf.todo', + 'it.skipIf.fails', + 'it.skipIf.each', + 'it.runIf.only', + 'it.runIf.concurrent', + 'it.runIf.todo', + 'it.runIf.fails', + 'it.runIf.each', + 'it.only.concurrent', + 'it.only.todo', + 'it.only.fails', + 'it.only.each', + 'it.concurrent.todo', + 'it.concurrent.fails', + 'it.concurrent.each', + 'it.todo.fails', + 'it.todo.each', + 'it.fails.each', + 'it.extend.skip.skipIf', + 'it.extend.skip.runIf', + 'it.extend.skip.only', + 'it.extend.skip.concurrent', + 'it.extend.skip.todo', + 'it.extend.skip.fails', + 'it.extend.skip.each', + 'it.extend.skipIf.runIf', + 'it.extend.skipIf.only', + 'it.extend.skipIf.concurrent', + 'it.extend.skipIf.todo', + 'it.extend.skipIf.fails', + 'it.extend.skipIf.each', + 'it.extend.runIf.only', + 'it.extend.runIf.concurrent', + 'it.extend.runIf.todo', + 'it.extend.runIf.fails', + 'it.extend.runIf.each', + 'it.extend.only.concurrent', + 'it.extend.only.todo', + 'it.extend.only.fails', + 'it.extend.only.each', + 'it.extend.concurrent.todo', + 'it.extend.concurrent.fails', + 'it.extend.concurrent.each', + 'it.extend.todo.fails', + 'it.extend.todo.each', + 'it.extend.fails.each', + 'it.skip.skipIf.runIf', + 'it.skip.skipIf.only', + 'it.skip.skipIf.concurrent', + 'it.skip.skipIf.todo', + 'it.skip.skipIf.fails', + 'it.skip.skipIf.each', + 'it.skip.runIf.only', + 'it.skip.runIf.concurrent', + 'it.skip.runIf.todo', + 'it.skip.runIf.fails', + 'it.skip.runIf.each', + 'it.skip.only.concurrent', + 'it.skip.only.todo', + 'it.skip.only.fails', + 'it.skip.only.each', + 'it.skip.concurrent.todo', + 'it.skip.concurrent.fails', + 'it.skip.concurrent.each', + 'it.skip.todo.fails', + 'it.skip.todo.each', + 'it.skip.fails.each', + 'it.skipIf.runIf.only', + 'it.skipIf.runIf.concurrent', + 'it.skipIf.runIf.todo', + 'it.skipIf.runIf.fails', + 'it.skipIf.runIf.each', + 'it.skipIf.only.concurrent', + 'it.skipIf.only.todo', + 'it.skipIf.only.fails', + 'it.skipIf.only.each', + 'it.skipIf.concurrent.todo', + 'it.skipIf.concurrent.fails', + 'it.skipIf.concurrent.each', + 'it.skipIf.todo.fails', + 'it.skipIf.todo.each', + 'it.skipIf.fails.each', + 'it.runIf.only.concurrent', + 'it.runIf.only.todo', + 'it.runIf.only.fails', + 'it.runIf.only.each', + 'it.runIf.concurrent.todo', + 'it.runIf.concurrent.fails', + 'it.runIf.concurrent.each', + 'it.runIf.todo.fails', + 'it.runIf.todo.each', + 'it.runIf.fails.each', + 'it.only.concurrent.todo', + 'it.only.concurrent.fails', + 'it.only.concurrent.each', + 'it.only.todo.fails', + 'it.only.todo.each', + 'it.only.fails.each', + 'it.concurrent.todo.fails', + 'it.concurrent.todo.each', + 'it.concurrent.fails.each', + 'it.todo.fails.each', + 'test', + 'test.extend', + 'test.skip', + 'test.skipIf', + 'test.runIf', + 'test.only', + 'test.concurrent', + 'test.todo', + 'test.fails', + 'test.each', + 'test.extend.skip', + 'test.extend.skipIf', + 'test.extend.runIf', + 'test.extend.only', + 'test.extend.concurrent', + 'test.extend.todo', + 'test.extend.fails', + 'test.extend.each', + 'test.skip.skipIf', + 'test.skip.runIf', + 'test.skip.only', + 'test.skip.concurrent', + 'test.skip.todo', + 'test.skip.fails', + 'test.skip.each', + 'test.skipIf.runIf', + 'test.skipIf.only', + 'test.skipIf.concurrent', + 'test.skipIf.todo', + 'test.skipIf.fails', + 'test.skipIf.each', + 'test.runIf.only', + 'test.runIf.concurrent', + 'test.runIf.todo', + 'test.runIf.fails', + 'test.runIf.each', + 'test.only.concurrent', + 'test.only.todo', + 'test.only.fails', + 'test.only.each', + 'test.concurrent.todo', + 'test.concurrent.fails', + 'test.concurrent.each', + 'test.todo.fails', + 'test.todo.each', + 'test.fails.each', + 'test.extend.skip.skipIf', + 'test.extend.skip.runIf', + 'test.extend.skip.only', + 'test.extend.skip.concurrent', + 'test.extend.skip.todo', + 'test.extend.skip.fails', + 'test.extend.skip.each', + 'test.extend.skipIf.runIf', + 'test.extend.skipIf.only', + 'test.extend.skipIf.concurrent', + 'test.extend.skipIf.todo', + 'test.extend.skipIf.fails', + 'test.extend.skipIf.each', + 'test.extend.runIf.only', + 'test.extend.runIf.concurrent', + 'test.extend.runIf.todo', + 'test.extend.runIf.fails', + 'test.extend.runIf.each', + 'test.extend.only.concurrent', + 'test.extend.only.todo', + 'test.extend.only.fails', + 'test.extend.only.each', + 'test.extend.concurrent.todo', + 'test.extend.concurrent.fails', + 'test.extend.concurrent.each', + 'test.extend.todo.fails', + 'test.extend.todo.each', + 'test.extend.fails.each', + 'test.skip.skipIf.runIf', + 'test.skip.skipIf.only', + 'test.skip.skipIf.concurrent', + 'test.skip.skipIf.todo', + 'test.skip.skipIf.fails', + 'test.skip.skipIf.each', + 'test.skip.runIf.only', + 'test.skip.runIf.concurrent', + 'test.skip.runIf.todo', + 'test.skip.runIf.fails', + 'test.skip.runIf.each', + 'test.skip.only.concurrent', + 'test.skip.only.todo', + 'test.skip.only.fails', + 'test.skip.only.each', + 'test.skip.concurrent.todo', + 'test.skip.concurrent.fails', + 'test.skip.concurrent.each', + 'test.skip.todo.fails', + 'test.skip.todo.each', + 'test.skip.fails.each', + 'test.skipIf.runIf.only', + 'test.skipIf.runIf.concurrent', + 'test.skipIf.runIf.todo', + 'test.skipIf.runIf.fails', + 'test.skipIf.runIf.each', + 'test.skipIf.only.concurrent', + 'test.skipIf.only.todo', + 'test.skipIf.only.fails', + 'test.skipIf.only.each', + 'test.skipIf.concurrent.todo', + 'test.skipIf.concurrent.fails', + 'test.skipIf.concurrent.each', + 'test.skipIf.todo.fails', + 'test.skipIf.todo.each', + 'test.skipIf.fails.each', + 'test.runIf.only.concurrent', + 'test.runIf.only.todo', + 'test.runIf.only.fails', + 'test.runIf.only.each', + 'test.runIf.concurrent.todo', + 'test.runIf.concurrent.fails', + 'test.runIf.concurrent.each', + 'test.runIf.todo.fails', + 'test.runIf.todo.each', + 'test.runIf.fails.each', + 'test.only.concurrent.todo', + 'test.only.concurrent.fails', + 'test.only.concurrent.each', + 'test.only.todo.fails', + 'test.only.todo.each', + 'test.only.fails.each', + 'test.concurrent.todo.fails', + 'test.concurrent.todo.each', + 'test.concurrent.fails.each', + 'test.todo.fails.each', + 'bench', + 'bench.skip', + 'bench.only', + 'bench.todo', + 'bench.skip.only', + 'bench.skip.todo', + 'bench.only.todo', + 'bench.skip.only.todo', + 'describe', + 'describe.skip', + 'describe.skipIf', + 'describe.only', + 'describe.concurrent', + 'describe.sequential', + 'describe.shuffle', + 'describe.todo', + 'describe.each', + 'describe.skip.skipIf', + 'describe.skip.only', + 'describe.skip.concurrent', + 'describe.skip.sequential', + 'describe.skip.shuffle', + 'describe.skip.todo', + 'describe.skip.each', + 'describe.skipIf.only', + 'describe.skipIf.concurrent', + 'describe.skipIf.sequential', + 'describe.skipIf.shuffle', + 'describe.skipIf.todo', + 'describe.skipIf.each', + 'describe.only.concurrent', + 'describe.only.sequential', + 'describe.only.shuffle', + 'describe.only.todo', + 'describe.only.each', + 'describe.concurrent.sequential', + 'describe.concurrent.shuffle', + 'describe.concurrent.todo', + 'describe.concurrent.each', + 'describe.sequential.shuffle', + 'describe.sequential.todo', + 'describe.sequential.each', + 'describe.shuffle.todo', + 'describe.shuffle.each', + 'describe.todo.each', + 'describe.skip.skipIf.only', + 'describe.skip.skipIf.concurrent', + 'describe.skip.skipIf.sequential', + 'describe.skip.skipIf.shuffle', + 'describe.skip.skipIf.todo', + 'describe.skip.skipIf.each', + 'describe.skip.only.concurrent', + 'describe.skip.only.sequential', + 'describe.skip.only.shuffle', + 'describe.skip.only.todo', + 'describe.skip.only.each', + 'describe.skip.concurrent.sequential', + 'describe.skip.concurrent.shuffle', + 'describe.skip.concurrent.todo', + 'describe.skip.concurrent.each', + 'describe.skip.sequential.shuffle', + 'describe.skip.sequential.todo', + 'describe.skip.sequential.each', + 'describe.skip.shuffle.todo', + 'describe.skip.shuffle.each', + 'describe.skip.todo.each', + 'describe.skipIf.only.concurrent', + 'describe.skipIf.only.sequential', + 'describe.skipIf.only.shuffle', + 'describe.skipIf.only.todo', + 'describe.skipIf.only.each', + 'describe.skipIf.concurrent.sequential', + 'describe.skipIf.concurrent.shuffle', + 'describe.skipIf.concurrent.todo', + 'describe.skipIf.concurrent.each', + 'describe.skipIf.sequential.shuffle', + 'describe.skipIf.sequential.todo', + 'describe.skipIf.sequential.each', + 'describe.skipIf.shuffle.todo', + 'describe.skipIf.shuffle.each', + 'describe.skipIf.todo.each', + 'describe.only.concurrent.sequential', + 'describe.only.concurrent.shuffle', + 'describe.only.concurrent.todo', + 'describe.only.concurrent.each', + 'describe.only.sequential.shuffle', + 'describe.only.sequential.todo', + 'describe.only.sequential.each', + 'describe.only.shuffle.todo', + 'describe.only.shuffle.each', + 'describe.only.todo.each', + 'describe.concurrent.sequential.shuffle', + 'describe.concurrent.sequential.todo', + 'describe.concurrent.sequential.each', + 'describe.concurrent.shuffle.todo', + 'describe.concurrent.shuffle.each', + 'describe.concurrent.todo.each', + 'describe.sequential.shuffle.todo', + 'describe.sequential.shuffle.each', + 'describe.sequential.todo.each', + 'describe.shuffle.todo.each', + + // Call chains that are not supported by Vitest, but were in the original list + 'xtest', + 'xtest.each', + 'xit', + 'xit.each', + 'fit', + 'xdescribe', + 'xdescribe.each', + 'fdescribe' +] diff --git a/tests/no-standalone-expect.test.ts b/tests/no-standalone-expect.test.ts index 023e8f2..8c7fdf7 100644 --- a/tests/no-standalone-expect.test.ts +++ b/tests/no-standalone-expect.test.ts @@ -3,6 +3,7 @@ import { ruleTester } from './ruleTester' ruleTester.run(RULE_NAME, rule, { valid: [ + 'beforeEach(() => { doSomething(); });', 'expect.any(String)', 'expect.extend({})', 'describe("a test", () => { it("an it", () => {expect(1).toBe(1); }); });', @@ -10,7 +11,15 @@ ruleTester.run(RULE_NAME, rule, { 'describe("a test", () => { const func = () => { expect(1).toBe(1); }; });', 'describe("a test", () => { function func() { expect(1).toBe(1); }; });', 'describe("a test", () => { const func = function(){ expect(1).toBe(1); }; });', + 'describe.only.concurrent.todo("a test", () => { const func = function(){ expect(1).toBe(1); }; });', + 'bench("a bench", () => expect(1).toBe(1))', 'it("an it", () => expect(1).toBe(1))', + 'it.only("an it", () => expect(1).toBe(1))', + 'it.concurrent("an it", () => expect(1).toBe(1))', + 'it.extend.skip("an it", () => expect(1).toBe(1))', + 'test("a test", () => expect(1).toBe(1))', + 'test.skip("a skipped test", () => expect(1).toBe(1))', + 'test.fails("a failing test", () => expect(1).toBe(1))', 'const func = function(){ expect(1).toBe(1); };', 'const func = () => expect(1).toBe(1);', '{}',