diff --git a/docs/rules/no-done-callback.md b/docs/rules/no-done-callback.md index 3cc1531..7e50e76 100644 --- a/docs/rules/no-done-callback.md +++ b/docs/rules/no-done-callback.md @@ -56,4 +56,18 @@ test('foo', async () => { resolve() }, 1000)) }) + +test.concurrent('foo', ({ expect }) => { + expect(1).toMatchSnapshot(); +}); + +test.concurrent('foo', (context) => { + context.expect(1).toBe(1); +}); + +describe.concurrent('foo', () => { + test('foo', ({ expect }) => { + expect(1).toBe(1); + }); +}); ``` diff --git a/src/rules/no-done-callback.ts b/src/rules/no-done-callback.ts index 168729c..2c0f33b 100644 --- a/src/rules/no-done-callback.ts +++ b/src/rules/no-done-callback.ts @@ -1,6 +1,6 @@ import { TSESLint, AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils' -import { createEslintRule, getNodeName, isFunction } from '../utils' -import { parseVitestFnCall } from '../utils/parseVitestFnCall' +import { createEslintRule, getNodeName, isFunction, isSupportedAccessor } from '../utils' +import { isTypeOfVitestFnCall, parseVitestFnCall } from '../utils/parseVitestFnCall' export const RULE_NAME = 'no-done-callback' export type MessageIds = 'noDoneCallback' | 'suggestWrappingInPromise' | 'useAwaitInsteadOfCallback'; @@ -46,8 +46,20 @@ export default createEslintRule({ if (isVitestEach && node.callee.type !== AST_NODE_TYPES.TaggedTemplateExpression) return - const isVitestConcurrent = getNodeName(node.callee)?.endsWith('.concurrent') ?? false - if (isVitestConcurrent) return + const isInsideConcurrentTestOrDescribe = context.getAncestors().some((ancestor) => { + if (ancestor.type !== AST_NODE_TYPES.CallExpression) return false + + const isNotInsideDescribeOrTest = !isTypeOfVitestFnCall(ancestor, context, ['describe', 'test']) + if (isNotInsideDescribeOrTest) return false + + const isTestRunningConcurrently = + ancestor.callee.type === AST_NODE_TYPES.MemberExpression && + isSupportedAccessor(ancestor.callee.property, 'concurrent') + + return isTestRunningConcurrently + }) + + if (isInsideConcurrentTestOrDescribe) return; const callback = findCallbackArg(node, isVitestEach, context) const callbackArgIndex = Number(isVitestEach) diff --git a/tests/no-done-callback.test.ts b/tests/no-done-callback.test.ts index 5362719..6d44dca 100644 --- a/tests/no-done-callback.test.ts +++ b/tests/no-done-callback.test.ts @@ -21,7 +21,9 @@ ruleTester.run(RULE_NAME, rule, { 'beforeAll(async () => {})', 'afterAll(() => {})', 'afterAll(async function () {})', - 'afterAll(async function () {}, 5)' + 'afterAll(async function () {}, 5)', + 'describe.concurrent("something", () => { it("something", ({ expect }) => { }) })', + 'describe.concurrent("something", () => { it("something", context => { }) })' ], invalid: [ {