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-test-generator

v0.1.8

Published

AI-powered test generator for JavaScript and TypeScript codebases using Google Gemini

Downloads

77

Readme

AI Test Generator

Command Line Interface

# Will interactively prompt for API key if not provided
ai-test-generator

# Generate tests for a specific file
ai-test-generator --file ./src/utils/helpers.js

# Specify test framework
ai-test-generator --framework jest

# Set output directory
ai-test-generator --output ./custom-tests

# Preview without writing files
ai-test-generator --dry-run

# Use specific Gemini model
ai-test-generator --model gemini-1.5-pro

# Skip interactive prompting
ai-test-generator --non-interactive

# Control API rate limiting (for quota management)
ai-test-generator --request-delay 3000 --batch-size 5 --batch-delay 10000


# Quota-friendly modes - for when you're hitting API limits
ai-test-generator --quota-friendly --file ./src/utils/helpers.js
ai-test-generator --ultra-quota-friendly --file ./src/utils/helpers.js

# Offline mode - generates templates without API calls
ai-test-generator --offline --file ./src/utils/helpers.js

Programmatic API

import AITestGenerator from 'ai-test-generator';

const generator = new AITestGenerator({
  testFramework: 'jest',
  apiKey: 'your_gemini_api_key', // Optional - will prompt if not provided
  outputDir: './tests',
  verbose: true
});

// Generate tests for a file
await generator.generateForFile('./src/utils/helpers.js');

// Generate tests for entire codebase
await generator.generateForCodebase('./src');

Configuration

Environment Variables

Create a .env file in your project root:

GEMINI_API_KEY=your_gemini_api_key_here

Configuration File

Or use a configuration file .ai-test-generator.json:

{
  "apiKey": "your_gemini_api_key_here",
  "testFramework": "jest",
  "outputDir": "./custom-tests-folder"
}

API Options

| Option | Description | Default | |--------|-------------|---------| | testFramework | Testing framework to use (jest, mocha, vitest) | 'jest' | | outputDir | Directory for generated tests | './tests' | | apiKey | Gemini API key | undefined | | interactive | Prompt for API key if not found | true | | aiModel | Gemini model to use | 'gemini-1.5-flash' | | testStyle | Type of tests to generate (unit, integration, both) | 'unit' | | dryRun | Preview without writing files | false | | verbose | Show detailed output | false | | coverage | Target code coverage percentage | 80 | | includeSnapshot | Include snapshot tests | false | | requestDelay | Delay between API requests in ms | 1000 | | batchSize | Number of components to process before pausing | 5 | | batchDelay | Delay between batches in ms | 5000 |

How It Works

AI Test Generator uses a 3-step process:

  1. Analysis: Scans your codebase to find functions, classes, and methods that need tests
  2. AI Generation: Uses Gemini AI to create appropriate test cases for each component
  3. Output: Generates properly formatted test files with your chosen testing framework

The tool intelligently determines which components need tests based on complexity, importance, and other factors.

Examples

Testing a Utility Function

// Original code (utils.js)
export function formatCurrency(amount, currency = 'USD') {
  return new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency
  }).format(amount);
}

// Generated test (utils.test.js)
import { formatCurrency } from './utils';

describe('formatCurrency', () => {
  test('formats USD currency correctly', () => {
    expect(formatCurrency(1000)).toBe('$1,000.00');
  });
  
  test('formats EUR currency correctly', () => {
    expect(formatCurrency(1000, 'EUR')).toBe('€1,000.00');
  });
  
  test('handles zero correctly', () => {
    expect(formatCurrency(0)).toBe('$0.00');
  });
});

Contributing

Contributions are welcome! Feel free to:

  1. Open issues for bugs or feature requests
  2. Submit pull requests
  3. Improve documentation

License

MIT


Created with ❤️ by Kidus

Version License

Features

  • 🤖 Automatically analyzes your code to identify testable components
  • ✨ Generates comprehensive tests using Google's Gemini AI
  • 🧪 Supports Jest, Mocha, and Vitest testing frameworks
  • 🔄 Works with both JavaScript and TypeScript projects
  • 💬 Interactive mode for easy API key setup
  • ⚙️ Customizable test generation options
  • 🛠️ Available as both CLI tool and programmable API

Installation

npm install ai-test-generator

Or globally:

npm install -g ai-test-generator

Requirements

Usage

To use the AI Test Generator, you can run the command-line interface (CLI) provided in the package. Here’s a basic example:

npx ai-test-generator <path-to-your-code>

Replace <path-to-your-code> with the path to the directory containing your codebase. The tool will analyze the code and generate test cases accordingly.

Contributing

Contributions are welcome! If you have suggestions for improvements or new features, please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.