Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation comment test like Rust #6004

Closed
4 tasks done
aprosail opened this issue Jun 30, 2024 · 1 comment
Closed
4 tasks done

Documentation comment test like Rust #6004

aprosail opened this issue Jun 30, 2024 · 1 comment
Labels
duplicate This issue or pull request already exists

Comments

@aprosail
Copy link

Clear and concise description of the problem

Rust's documentation comment test, aka doctest, is really good for guaranteeing documentation accuracy and improving code maintainabilities. And I suggest to introduce such features into vitest.

Suggested solution

For example:

/*
 * ```ts
 * import {it, expect} from 'vitest'
 * import {add} from 'xxx'
 * 
 * it('add', () => {
 *   expect(add()).toBe(0)
 *   expect(add(1)).toBe(1)
 *   expect(add(1, 2, 3)).toBe(6)
 * })
 * ```
 */
export function add(...args: number[]) {
  return args.reduce((a, b) => a + b, 0)
}

And when running vitest, it will test all code inside the documentation. In that case, the accuracy of the code example inside documentation comments will be guaranteed, and once reading the doc, people can easily understand how the function works, according to the example code rather than unnecessary descriptions written in natural languages (such as English).

Alternative

No response

Additional context

No response

Validations

@sheremet-va
Copy link
Member

sheremet-va commented Jun 30, 2024

The team already gave our thoughts on this feature here: #3035 (comment)

@sheremet-va sheremet-va closed this as not planned Won't fix, can't repro, duplicate, stale Jun 30, 2024
@sheremet-va sheremet-va added duplicate This issue or pull request already exists and removed enhancement: pending triage labels Jun 30, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants