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

autotest-ai

v1.0.0

Published

AI-powered test generator. Generate unit tests from your code using Claude or OpenAI.

Downloads

101

Readme

autotest-ai

AI-powered test generator. Generate unit tests from your code using Claude or OpenAI.

Stop writing tests manually. Let AI analyze your code and generate comprehensive unit tests.

npm version License: MIT TypeScript


Features

  • AI-Powered: Uses Claude or OpenAI to understand your code and generate meaningful tests
  • Multiple Frameworks: Supports Jest, Vitest, Node.js test runner, and Mocha
  • Edge Cases: Automatically generates tests for edge cases (null, undefined, empty values)
  • TypeScript Support: Generates TypeScript or JavaScript tests
  • CLI & API: Use from command line or programmatically
  • Batch Processing: Generate tests for entire directories

Installation

npm install -g autotest-ai

Or use with npx:

npx autotest-ai src/utils.ts

Quick Start

1. Set your API key

# For Claude (recommended)
export ANTHROPIC_API_KEY=your-api-key

# For OpenAI
export OPENAI_API_KEY=your-api-key

2. Generate tests

# Generate tests for a file
autotest src/utils.ts

# Generate tests for all files in a directory
autotest src/

3. Run your tests

npm test

CLI Usage

autotest <file|directory> [options]

Options

| Option | Description | |--------|-------------| | -p, --provider <claude\|openai> | AI provider (default: claude) | | -m, --model <model> | Model to use | | -f, --framework <framework> | Test framework: jest, vitest, node, mocha | | -o, --output <dir> | Output directory (default: tests) | | --no-edge-cases | Skip edge case tests | | --js | Generate JavaScript instead of TypeScript | | --dry-run | Print tests without writing files | | -h, --help | Show help |

Examples

# Generate Jest tests (default)
autotest src/utils.ts

# Generate Vitest tests
autotest src/utils.ts --framework vitest

# Use OpenAI instead of Claude
autotest src/utils.ts --provider openai

# Preview generated tests without writing
autotest src/utils.ts --dry-run

# Generate tests for entire src directory
autotest src/

# Generate JavaScript tests
autotest src/utils.js --js

Programmatic API

import { generateTests, generateAndWriteTests } from 'autotest-ai';

// Generate tests (returns test code)
const result = await generateTests('src/utils.ts', {
  provider: 'claude',
  framework: 'jest',
  edgeCases: true,
});

console.log(result.testCode);
console.log(`Functions tested: ${result.functions.join(', ')}`);

// Generate and write tests to file
const written = await generateAndWriteTests('src/utils.ts', {
  framework: 'vitest',
  outputDir: '__tests__',
});

console.log(`Test file created: ${written.testFile}`);

API Reference

generateTests(filePath, config?)

Generates tests for a file and returns the result.

interface GenerateResult {
  sourceFile: string;      // Original source file path
  testFile: string;        // Generated test file path
  testCode: string;        // Generated test code
  functions: string[];     // Functions that were tested
  tokensUsed?: number;     // API tokens used
}

generateAndWriteTests(filePath, config?)

Generates tests and writes them to a file.

generateTestsForDirectory(dirPath, config?)

Generates tests for all source files in a directory.

Config Options

interface AutoTestConfig {
  provider?: 'claude' | 'openai';  // AI provider
  apiKey?: string;                  // API key (or use env var)
  model?: string;                   // Model to use
  framework?: 'jest' | 'vitest' | 'node' | 'mocha';
  outputDir?: string;               // Output directory
  edgeCases?: boolean;              // Include edge cases
  typescript?: boolean;             // Generate TypeScript
}

Example Output

Input: src/math.ts

export function add(a: number, b: number): number {
  return a + b;
}

export function divide(a: number, b: number): number {
  if (b === 0) throw new Error('Division by zero');
  return a / b;
}

Generated: __tests__/math.test.ts

import { describe, it, expect } from '@jest/globals';
import { add, divide } from '../src/math';

describe('add', () => {
  it('should add two positive numbers', () => {
    expect(add(2, 3)).toBe(5);
  });

  it('should add negative numbers', () => {
    expect(add(-1, -1)).toBe(-2);
  });

  it('should handle zero', () => {
    expect(add(0, 5)).toBe(5);
    expect(add(5, 0)).toBe(5);
  });
});

describe('divide', () => {
  it('should divide two numbers', () => {
    expect(divide(10, 2)).toBe(5);
  });

  it('should handle decimal results', () => {
    expect(divide(5, 2)).toBe(2.5);
  });

  it('should throw error for division by zero', () => {
    expect(() => divide(10, 0)).toThrow('Division by zero');
  });
});

Supported Test Frameworks

| Framework | Command | |-----------|---------| | Jest | autotest file.ts --framework jest | | Vitest | autotest file.ts --framework vitest | | Node.js | autotest file.ts --framework node | | Mocha | autotest file.ts --framework mocha |


Environment Variables

| Variable | Description | |----------|-------------| | ANTHROPIC_API_KEY | API key for Claude | | OPENAI_API_KEY | API key for OpenAI |


Tips

  1. Better tests with better code: Well-documented functions with clear types produce better tests
  2. Review generated tests: AI-generated tests are a starting point, review and adjust as needed
  3. Use --dry-run first: Preview tests before writing to files
  4. Combine with TDD: Generate initial tests, then refine as you develop

Support

If autotest-ai saved you time:

License

MIT