louayhouimli /
testgenie-ai
AI-powered CLI test generator that creates comprehensive test suites for your JavaScript/TypeScript projects in seconds.
Loading repository data…
srinidhi-anand / repository
AI-Powered Jest Test Case Generator for TypeScript (Node.js)
🚀 The Intelligent, Complexity-Aware Jest Test Generator for TypeScript
ts-genai-test is a high-performance developer tool that uses AST-based code analysis to automatically generate optimized Jest unit tests. It doesn't just call an AI; it calculates code complexity to route your requests to the most efficient LLM provider (Gemini, OpenAI, or Groq), saving you costs while maximizing test accuracy.
🔗 View the Technical Walkthrough (Architecture, CLI Demo & Deep Dive)
Built with pnpm and optimized for TypeScript-first projects.
🔗 https://github.com/srinidhi-anand/testcase-gen-ai-ts
openai, gemini, groq).generate) or manual path targeting (run).auto, suggest, or never for AI model swaps..test.ts files with hardened safety against infinite-nesting hallucinations.Using pnpm (recommended):
pnpm install ts-genai-test
or using npm
npm install ts-genai-test
The tool utilizes environment variables to drive its intelligence engine. Create a .env file in your project root:
# --- Core Credentials ---
AI_API_KEY=your_api_key_here
# --- Provider & Model (Optional - overridden by Intelligence by default) ---
LLM=openai # openai | gemini | groq
MODEL=gpt-4o-mini # specific model name
# --- Intelligence Preferences ---
AI_PREFERENCE=balanced # high-accuracy | low-cost | balanced
AI_MODE=auto # auto | manual (manual locks strictly to your MODEL)
AI_OVERRIDE_POLICY=auto # auto | suggest | never
[!NOTE] Backward Compatibility: Legacy variables (
AI_MODEL,AI_MODEL_NAME) are still supported in this version but will trigger a deprecation warning in the console. I explicitly recommend migrating to the new standard above.
[!CAUTION] Programmatic usage (Basic Example) is now deprecated. To improve your workflow efficiency, I strongly recommend using the CLI interface instead of manually framing
inputPromptarrays and callinggenerateTestsprograms. Support for this manual execution pattern may be removed in future major versions.
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.
The system calculates a Complexity Score based on Lines of Code (LOC), Branching (if/switch/ternary), and Async/Await usage.
gemini-1.5-flash (Low-cost).gpt-4o-mini (Balanced).gpt-4o (High-accuracy).| Command | Behavior |
|---|---|
generate | (Default) Only processes files currently staged in your Git index. |
run | Manually processes files/folders based on the --path flag (ignores Git). |
Available CLI Flags:
--path <string>: Required for run. Can be used as a filter for generate.--function <string>: Isolates generation strictly to one specific function name.--override: Forces regeneration of existing test files (defaults false).--root <path>: Manually set the project root for complex monorepo structures.--staged: Explicitly trigger staged detection (active by default for generate).1. Generate tests for Git staged files (Automated):
npx ts-genai-test generate
2. Manually generate tests for a specific folder:
npx ts-genai-test run --path src/services/userAuth
3. Target only one specific function in a file:
npx ts-genai-test run --path src/utils/helper.ts --function computeComplexity
4. Force regeneration of existing tests:
npx ts-genai-test run --path src/components --override
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, { override: true });
[!IMPORTANT] API Migration Notice: The second argument of
generateTestshas been upgraded from a simplebooleanto anExecutionContextobject to support advanced metadata. While I currently maintain backward compatibility for boolean inputs, this will be removed in future major versions. I highly recommend migrating your scripts to use the object syntax or switching to the new CLI commands.
| 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:
The tool tracks execution data to help you audit cost and reliability. This log is stored entirely locally.
.ts-genai-test/test-summary.jsonTo improve reliability, the system automatically retries twice (3 total attempts) if a GenAI request fails due to:
If the retry sequence fails, a clear error message is securely thrown avoiding half-baked test case rendering.
✔️ Prevents duplicate test creation ✔️ Improves success rate ✔️ Keeps execution deterministic
.ts files within a target path automatically.--function flag..test.ts files using modern Jest matchers.default and named exports using an AST-ready framing engine.import Default, { Named } from '...' syntax for grouped batches.| Framework | Status |
|---|---|
| Jest | ✅ Supported |
| Mocha | ⏳ Planned |
| Vitest | ⏳ Planned |
| Provider | Status |
|---|---|
| OpenAI GPT | ✅ |
| Gemini | ✅ |
| Groq | ✅ |
| Others | ⏳ Planned |
.ts files. JavaScript (.js) and other languages are on the roadmap.I'm actively seeking collaboration with Academic Researchers, PhD Scholars, and Software Engineering Labs (IISc, IITs, CMU, etc.) to push the boundaries of AI-driven software verification. Our architecture is designed as a platform for research in:
📄 View the Research Collaboration Proposal
If you are a professor or researcher interested in using ts-genai-test as a base for your studies, please reach out via GitHub Issues or LinkedIn.
This project was developed with a high-velocity, co-engineering ap
Selected from shared topics, language and repository description—not editorial ratings.
louayhouimli /
AI-powered CLI test generator that creates comprehensive test suites for your JavaScript/TypeScript projects in seconds.
artshllk /
AI-powered test quality analyzer for TypeScript - evaluates assertions, flags weak matchers, scores test files, and generates interactive HTML reports.
seyseyseyz /
AI-powered test generator for JavaScript/TypeScript projects
piguelmon /
Pedro Arantes Tests — AI-powered test generator for TypeScript Generate, fix, and manage Jest unit tests automatically using **Azure OpenAI** or **Ollama** (local).
yadavxprakhar /
AI-powered test generator for 12+ languages. Auto-creates comprehensive tests with 80%+ coverage for pytest, Jest, JUnit & more. Reduce testing time by 70-90%.
devness-com /
AI-powered test quality platform — scan, cover, run, and track your codebase quality score