AI-Powered Jest Test Case Generator for TypeScript (Node.js)
npm install ts-genai-test๐ 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.
---
๐ 
---
๐ https://github.com/srinidhi-anand/testcase-gen-ai-ts
- 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.
---
- TypeScript
- Node.js
- pnpm (v10.24.0)
- Jest
- Generative AI (LLM-based test generation)
---
Using pnpm (recommended):
``bash`
pnpm install ts-genai-test
or using npm
`bash`
npm install ts-genai-test
#### Basic Example
`Typescript
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.
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:
`Typescript``
await generateTests(inputPrompt, overrideTestCases= true);
| 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
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
- โ Accepts file path, folder path, and output path
- โ Validates input paths and file existence
- โณ Planned: print number of files and functions detected
- โ Generates prompts using function name
- โ Calls configured GenAI provider
- โ Produces TypeScript-ready Jest test code
- โณ Planned: support additional testing frameworks
- โ 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
- โ Clear error messages for invalid input or AI failures
- โณ Planned: handle unsupported languages and malformed code
- โณ Planned: handle API rate limits and timeouts
| Framework | Status |
| --------- | ------------ |
| Jest | โ
Supported |
| Mocha | โณ Planned |
| Vitest | โณ Planned |
| Provider | Status |
| ---------- | ---------- |
| OpenAI GPT | โ
|
| Gemini | โ
|
| Groq | โ
|
| Others | โณ Planned |
- โณ 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
- 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
MIT ยฉ Srinidhi Anand