Skip to content

no-done-callback and no-test-return-statement should support Vitest options object callbacks #899

Description

@nami8824

Summary

no-done-callback and no-test-return-statement currently miss test callbacks declared with Vitest's options object:

test('example', { timeout: 1000 }, (done) => {
  done()
})

test('example', { retry: 2 }, () => {
  return Promise.resolve()
})

These forms are currently not reported.

Vitest supports the test(name, options, fn) signature, so these rules should treat the third argument as the test callback when the second argument is an options object.

Reproduction

Add the following cases to the invalid section of each rule test file.
tests/no-done-callback.test.ts

{
  code: "test('uses done', { timeout: 1000 }, (done) => { done() })",
  errors: [{ messageId: 'noDoneCallback' }],
}

tests/no-test-return-statement.test.ts

{
  code: "test('returns', { retry: 2 }, () => { return Promise.resolve() })",
  errors: [{ messageId: 'noTestReturnStatement' }],
}

Then run:

pnpm test tests/no-done-callback.test.ts tests/no-test-return-statement.test.ts

Currently, these cases fail because the rules only inspect the second argument as the test callback and do not recognize the callback in test(name, options, fn).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions