Generate Javascript Test Cases
JavaScript-based test case configuration example for promptfoo, demonstrating how to define and run prompt evaluation tests programmatically using code instead
Why it matters
Automate the creation and validation of Javascript test cases for your codebase. This asset helps ensure code quality and reliability by generating comprehensive tests.
Outcomes
What it gets done
Generate unit tests for Javascript functions.
Validate generated test cases for correctness.
Integrate test generation into CI/CD pipelines.
Debug and refine test generation logic.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/pfoo-config-javascript-test-cases | bash Capabilities
What this chain does
Creates unit, integration, or end-to-end test cases.
Traces errors to their root cause and suggests fixes.
Analyzes code for bugs, style issues, and improvements.
Writes source code or scripts from a description.
Overview
Config Javascript Test Cases
What it does
This is a working example from the promptfoo repository that demonstrates JavaScript-based test case configuration. It shows how to define prompt evaluation tests programmatically using code, providing an alternative to YAML configuration files for scenarios requiring dynamic logic or computed values.
How it connects
Use this example when your prompt testing needs exceed what static YAML can express-such as generating test cases in loops, applying conditional logic, computing assertions dynamically, or integrating test data from external sources. It's ideal for teams who need programmatic control over their LLM evaluation workflows.
Source README
config-javascript-test-cases (JavaScript/TypeScript Test Cases Example)
You can run this example with:
npx promptfoo@latest init --example config-javascript-test-cases
cd config-javascript-test-cases
This example demonstrates different ways to generate test cases using JavaScript/TypeScript functions. It shows both static and dynamic test case generation with optional type checking.
Files
promptfooconfig.yaml- Configuration file specifying prompts and providersstaticTests.ts- Static test cases with type checking examplesdynamicTests.ts- Dynamic test case generation from a simulated database
Usage
Install dependencies:
npm install promptfooSet up your API key:
export OPENAI_API_KEY=your_api_key_hereRun the evaluation:
npx promptfoo eval
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.