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

ts-genai-test

v1.1.0

Published

AI-Powered Jest Test Case Generator for TypeScript (Node.js)

Readme

testcase-gen-ai-ts

📘 AI-powered Jest test case generator for TypeScript (Node.js)

testcase-gen-ai-ts is a developer tool that automatically generates Jest unit test cases for TypeScript (Node.js) backend functions using Generative AI.

It is designed to integrate smoothly into modern backend workflows and supports multiple LLM providers (Gemini, OpenAI, Groq, etc.) with a reliable retry mechanism to handle transient AI failures.

Built with pnpm and optimized for TypeScript-first projects.


📦 npm Package

🔗 npm version


🧩 GitHub Repository

🔗 https://github.com/srinidhi-anand/testcase-gen-ai-ts

🚀 Features

  • Generate Jest unit tests automatically from a typescript function
  • Works with server-side Node.js + TypeScript projects
  • Configurable AI model support (Gemini, Groq, OpenAI GPT, etc.)
  • Strict output format (valid .test.ts test files)
  • Easy to integrate into existing development workflows
  • Creates test folders automatically if missing
  • Built with pnpm (v10.24.0)
  • Built-in one-time retry mechanism for GenAI calls if the initial request fails.

🧰 Tech Stack

  • TypeScript
  • Node.js
  • pnpm (v10.24.0)
  • Jest
  • Generative AI (LLM-based test generation)

📦 Installation

Using pnpm (recommended):

pnpm install ts-genai-test

or using npm

npm install ts-genai-test

🚀 Usage

Basic Example

import path from "path";
import { generateTests, functionalTypes } from "ts-genai-test";
const inputPrompt: functionalTypes.PromptInput[] = [
  {
    outputTestDir: path.resolve(__dirname, "../__tests__"), // optional test suite directory, defaults to 'tests' folder
    folderPath: path.resolve(__dirname, "../src"),  // source folder
    filePath: path.resolve(__dirname, "../src/index"), // source file
    functionName: "add", // function to generate tests for
    testFileName: "" // optional custom test file name
    rootPath: "" // optional if outputTestDir is provided else its mandatory to form tests folder path
  }
];

await generateTests(inputPrompt);

The generated Jest test file will be created automatically inside the specified test directory.

♻️ Override Test Case Option

By default, the tool does NOT overwrite existing test files to prevent accidental data loss. You can explicitly allow regeneration of test cases using the override option:

await generateTests(inputPrompt, overrideTestCases= true);

Behavior Summary

| Scenario | Result | | ----------------------------------- | ----------------------- | | Test file exists & override = false | ❌ Skips generation | | Test file exists & override = true | ✅ Overwrites test file | | Test file does not exist | ✅ Creates test file |

This makes the tool safe for:

  • CI pipelines
  • Iterative development
  • Controlled regeneration of tests

🔁 GenAI Retry Strategy

To improve reliability, the system automatically retries once if a GenAI request fails due to:

  • network issues
  • API rate limits
  • transient LLM errors

If the retry fails, a clear error message is returned

✔️ Prevents duplicate test creation ✔️ Improves success rate ✔️ Keeps execution deterministic

🧠 Core Functionality

1. Input Handling

  • ✔ Accepts file path, folder path, and output path
  • ✔ Validates input paths and file existence
  • ⏳ Planned: print number of files and functions detected

2. AI Test Case Generation

  • ✔ Generates prompts using function name
  • ✔ Calls configured GenAI provider
  • ✔ Produces TypeScript-ready Jest test code
  • ⏳ Planned: support additional testing frameworks

3. Formatting & Storage

  • ✔ Parses AI response into clean TypeScript code
  • ✔ Automatically creates test directories if missing
  • ✔ Writes generated test cases to the output path
  • ✔ Displays generation status
  • ⏳ Planned: return structured results for API usage

4. Error Handling

  • ✔ Clear error messages for invalid input or AI failures
  • ⏳ Planned: handle unsupported languages and malformed code
  • ⏳ Planned: handle API rate limits and timeouts

🧪 Supported Test Frameworks

| Framework | Status | | --------- | ------------ | | Jest | ✅ Supported | | Mocha | ⏳ Planned | | Vitest | ⏳ Planned |

🧠 Supported AI Providers

| Provider | Status | | ---------- | ---------- | | OpenAI GPT | ✅ | | Gemini | ✅ | | Groq | ✅ | | Others | ⏳ Planned |

🛣️ Feature Roadmap

  • ⏳ Read and process all files in src folder
  • ⏳ Generate test cases for every function in a file
  • ✅ AI-based Jest test generation
  • ✅ Automatic test folder creation
  • ✅ Predictable test file naming
  • ⏳ Support for additional test frameworks
  • ⏳ Support for non-TypeScript files
  • ⏳ API and functional test generation
  • ✅ Configurable AI model selection (Groq, OpenAI, Gemini, etc.)
  • ✅ Configurable output paths and test file names

⚠️ Limitations

  • Generated test cases should be reviewed before production use
  • Complex business logic may require manual adjustments
  • This tool assists developers; it does not replace human-written tests

📄 License

MIT © Srinidhi Anand