Prompt Chain

Generate Javascript Test Cases

A promptfoo example generating test cases from JavaScript/TypeScript functions, both statically and dynamically.

Works with github

79
Spark score
out of 100
Updated 27 days ago
Version 0.121.18
Models
gpt 4o

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

Steps

Steps in the chain

01
Install dependencies
02
Set up your API key
03
Run the evaluation

Overview

Config Javascript Test Cases

This promptfoo example generates test cases from TypeScript functions, demonstrating both statically type-checked test cases and dynamic test case generation from a simulated database. Use it as a template when promptfoo test cases need to be generated from code or a dynamic data source rather than written as static YAML.

What it does

This promptfoo example demonstrates different ways to generate test cases using JavaScript/TypeScript functions. It shows both static test case generation (with type-checking examples) and dynamic test case generation, simulated from a database.

npx promptfoo@latest init --example config-javascript-test-cases
cd config-javascript-test-cases

When to use - and when NOT to

Use this as a starting template when your promptfoo test cases need to be generated programmatically in TypeScript rather than written out as static YAML - for example pulling test inputs from a data source, or wanting compile-time type checking on your test case shape. It is not itself a specific eval subject; it's a pattern for test-case generation.

Inputs and outputs

The example ships three files: promptfooconfig.yaml (the configuration specifying prompts and providers), staticTests.ts (static test cases with type-checking examples), and dynamicTests.ts (dynamic test case generation from a simulated database). To run it: install dependencies with npm install promptfoo, set your API key via export OPENAI_API_KEY=your_api_key_here, and run the evaluation with npx promptfoo eval.

Who it's for

Developers who want their promptfoo test cases generated from code rather than hand-written YAML, particularly when test data comes from a database or other dynamic source, or when TypeScript's type checking should validate the test case shape before an eval runs.

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
    

FAQ

Common questions

Discussion

Questions & comments ยท 0

Sign In Sign in to leave a comment.