Prompt Chain

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

Works with github

75
Spark score
out of 100
Updated 3 months ago
Version 1.0.0

Add to Favorites

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

01

Generate unit tests for Javascript functions.

02

Validate generated test cases for correctness.

03

Integrate test generation into CI/CD pipelines.

04

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

Write tests

Creates unit, integration, or end-to-end test cases.

Debug

Traces errors to their root cause and suggests fixes.

Review code

Analyzes code for bugs, style issues, and improvements.

Generate code

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 providers
  • staticTests.ts - Static test cases with type checking examples
  • dynamicTests.ts - Dynamic test case generation from a simulated database

Usage

  1. Install dependencies:

    npm install promptfoo
    
  2. Set up your API key:

    export OPENAI_API_KEY=your_api_key_here
    
  3. Run the evaluation:

    npx promptfoo eval
    

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.