Skip to main content
Vitest is a test runner for JavaScript and TypeScript. Braintrust supports two Vitest workflows:
  • Use the Braintrust wrapVitest helper to write Vitest tests that run as Braintrust evals.
  • Use the vitest-evals reporter to report vitest-evals test runs to Braintrust.

Setup

Install Braintrust alongside Vitest:
Set your Braintrust API key as an environment variable:

Separate evals from unit tests

Eval files are regular Vitest files and can live anywhere in your project. Evals can run slower and log results to Braintrust, so a common convention is a .eval.ts suffix or a dedicated evals/ directory with a separate Vitest config:
vitest.eval.config.ts
Run evals separately from unit tests:

Run evals with wrapVitest

Call wrapVitest once at the top of your test file, passing in the Vitest globals. Use the returned object in place of the standard test, describe, and expect.
my-eval.eval.ts
Run it with the eval config:
After the suite finishes, Braintrust prints a summary to your terminal and creates an experiment with one traced span per test case.

Report vitest-evals runs to Braintrust

Use the Braintrust Vitest evals reporter when you already write evaluations with the vitest-evals package and want those runs logged to Braintrust. This workflow is separate from the standard Braintrust Eval() framework and from the wrapVitest helper. Install the reporter dependencies:
Configure Vitest with both the vitest-evals reporter and the Braintrust reporter:
vitest.evals.config.mts
Write eval tests with vitest-evals primitives. The Braintrust reporter reads the eval metadata produced by vitest-evals/reporter and logs each eval case as a Braintrust span.
refund.eval.ts
Run Vitest with the reporter config:
The reporter creates or reuses a Braintrust experiment for the run. Each eval test logs:
  • The test input, output, status, file path, and full test name.
  • Scores from judges and assertions, including avg_score and pass when provided by vitest-evals.
  • Harness metadata, session messages, tool calls, artifacts, usage metrics, and errors.
  • Nested model, tool, and trace spans when the harness includes normalized trace data.

Reporter options

Pass options to new BraintrustVitestEvalsReporter() to control where results are logged:

Key concepts

wrapVitest

wrapVitest wraps Vitest’s test, describe, and expect with Braintrust tracking.
Each describe creates one Braintrust experiment. Braintrust appends a timestamp to make each run unique. The project groups experiments together and defaults to the suite name if projectName is not set.

Test configuration

test accepts an optional config object between the name and the test function:

Scorers

A scorer receives { output, expected, input, metadata } and returns a name and score:
Scorers run after each test, including failed tests. Errors inside scorers are caught and logged.

Logging helpers

Use logOutputs and logFeedback inside a wrapVitest test to log additional data to the current span:

Inline data and dataset support

Define data inline:
Or load from a managed Braintrust dataset:
Both approaches expand into separate test cases and Braintrust spans automatically.

Resources