Automatically generate comprehensive, production-ready Jest test cases for your JavaScript functions using AI.
- Automated Test Generation: Analyzes JavaScript functions and creates ready-to-run Jest test suites.
- Deep Edge Case Analysis: Identifies subtle bugs, security issues, and boundary conditions.
- Flexible AI Backend: Supports OpenAI, Open Source Models (via compatible APIs), and Ollama.
- Integrated Workflow: Parses code, generates tests, writes files, and runs them in one go.
- Coverage Reports: Generated tests are configured to collect code coverage automatically.
-
Clone the repository
git clone <repository-url> cd prompt-qa-validator
-
Install dependencies
npm install
-
Configure Environment Duplicate
.env.exampleto.env:cp .env.example .env # or on Windows copy .env.example .envConfigure your LLM provider in
.env:For OpenAI or Open Source Models (Compatible API):
# For OpenAI OPENAI_API_KEY=sk-your-key OPENAI_MODEL=gpt-4 # OR for Open Source Models (LocalAI, vLLM, LM Studio) # Point to your local server's API endpoint OPENAI_BASE_URL=http://localhost:1234/v1 OPENAI_API_KEY=dummy-key OPENAI_MODEL=mistral-instruct # or your OSS model name
For Native Ollama:
# Special handling for Ollama native API (detects /api suffix) OPENAI_BASE_URL=http://localhost:11434/api OPENAI_MODEL=llama3 OPENAI_API_KEY=dummy
Generate tests for the included sample functions:
npm run example
# OR
node src/index.js examples/sample-functions.jsPass any JavaScript file path to the CLI:
node src/index.js ./path/to/your-file.jsTo run the generated tests separately:
npm test- Parse: The tool reads your
.jsfile and extracts function signatures and bodies. - Analyze: An AI agent acts as a Code Analyzer to understand the purpose and constraints of each function.
- Generate: A separate "QA Engineer" agent writes comprehensive Jest test cases, covering happy paths, error cases, and edge cases.
- Execute: The tool writes the tests to
generated-tests/and immediately attempts to run them using Jest.
prompt-qa-validator/
├── src/
│ ├── index.js # Entry point
│ └── lib/
│ ├── testGenerator.js # Main orchestration logic
│ ├── llmClient.js # Handles OpenAI/Ollama communication
│ ├── fileParser.js # Extracts functions from code
│ └── prompts.js # System and User prompts
├── examples/ # Sample code to test
├── generated-tests/ # Output directory for generated tests
└── jest.config.js # Jest configuration
MIT