npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ai-testgen-tool

v1.0.0

Published

AI-powered CLI tool to generate unit, service, integration, and end-to-end tests for service codebases.

Readme

AI-TestGen

AI-TestGen is a CLI tool that leverages AI to automatically generate unit, service, integration, and end-to-end tests for service-oriented codebases (Node.js, TypeScript, etc.).

Purpose

  • Save developer time and effort
  • Improve test coverage and quality
  • Reduce bugs and regressions
  • Standardize testing practices across teams

Features

  • Code analysis and test suggestion
  • Test code generation (unit, service, integration, E2E)
  • Customizable test templates
  • Review and edit interface
  • Integration with code editors and CI/CD
  • Flexible output directory and filename options
  • Overwrite protection and auto-directory creation
  • Dry run mode: Preview what would be generated without writing files
  • Optional LLM/AI-powered test generation: Use GPT (OpenAI) to generate tests if desired, with support for custom endpoints/gateways

Quickstart

  1. Install dependencies:
    npm install
  2. Generate tests for a TypeScript service:
    node src/cli/index.js generate --all src/userService.ts --output tests/generated
  3. Preview what would be generated (dry run):
    node src/cli/index.js generate --all src/userService.ts --output tests/generated --dry-run
  4. Specify custom output directories and filenames:
    node src/cli/index.js generate --all src/userService.ts \
      --unit-output tests/unit --unit-filename userService.unit.test.ts \
      --service-output tests/service --service-filename userService.service.test.ts \
      --integration-output tests/integration --integration-filename userService.integration.test.ts \
      --e2e-output tests/e2e --e2e-filename userService.e2e.test.ts
  5. Overwrite existing files:
    node src/cli/index.js generate --all src/userService.ts --output tests/generated --force

LLM/AI-Powered Test Generation (Optional)

If you want to use OpenAI GPT to generate tests:

  1. Set your API key:
    export OPENAI_API_KEY=sk-...
  2. (Optional) Set a custom OpenAI-compatible base URL (for gateways, Azure, etc.):
    export OPENAI_BASE_URL=https://your-gateway.example.com/v1
    # or use the CLI flag:
    # --openai-base-url https://your-gateway.example.com/v1
  3. Run with the --ai flag:
    node src/cli/index.js generate --all src/userService.ts --output tests/generated --ai
    # or with a custom base URL:
    node src/cli/index.js generate --all src/userService.ts --output tests/generated --ai --openai-base-url https://your-gateway.example.com/v1
  • If no API key is set, or --ai is not used, the tool falls back to static/template-based generation.
  • Each developer must use their own API key. Never share your key.

CLI Usage

Usage: ai-testgen generate [type] <target> [options]

Arguments:
  [type]         Test type: unit | service | integration | e2e (optional if --all is used)
  <target>       Target file or directory

Options:
  -o, --output <dir>           Default output directory (default: "examples")
  --all                        Generate all test types for the target file (omit [type] argument)
  --unit-output <dir>          Unit test output directory
  --unit-filename <name>       Unit test filename
  --service-output <dir>       Service test output directory
  --service-filename <name>    Service test filename
  --integration-output <dir>   Integration test output directory
  --integration-filename <name> Integration test filename
  --e2e-output <dir>           E2E test output directory
  --e2e-filename <name>        E2E test filename
  --force                      Overwrite existing test files
  --dry-run                    Show what would be generated, but do not write files
  --ai                         Use LLM-powered test generation if OPENAI_API_KEY is set
  --openai-base-url <url>      Custom OpenAI-compatible base URL (for gateways, Azure, etc.)

Real-World Examples

Preview all test types with custom locations (dry run, no [type] needed):

node src/cli/index.js generate --all src/userService.ts \
  --unit-output tests/unit --unit-filename userService.unit.test.ts \
  --service-output tests/service --service-filename userService.service.test.ts \
  --integration-output tests/integration --integration-filename userService.integration.test.ts \
  --e2e-output tests/e2e --e2e-filename userService.e2e.test.ts --dry-run

Generate all test types with OpenAI GPT (if API key is set):

export OPENAI_API_KEY=sk-...
node src/cli/index.js generate --all src/userService.ts --output tests/generated --ai

Generate all test types with a custom OpenAI-compatible endpoint:

export OPENAI_API_KEY=sk-...
export OPENAI_BASE_URL=https://your-gateway.example.com/v1
node src/cli/index.js generate --all src/userService.ts --output tests/generated --ai
# or
node src/cli/index.js generate --all src/userService.ts --output tests/generated --ai --openai-base-url https://your-gateway.example.com/v1

Generate only a unit test in a custom location:

node src/cli/index.js generate unit src/userService.ts --unit-output tests/unit --unit-filename userService.unit.test.ts

Overwrite existing files:

node src/cli/index.js generate --all src/userService.ts --output tests/generated --force

Preview (dry run) before generating:

node src/cli/index.js generate --all src/userService.ts --output tests/generated --dry-run

License

MIT