- Use the Braintrust
wrapVitesthelper to write Vitest tests that run as Braintrust evals. - Use the
vitest-evalsreporter to reportvitest-evalstest runs to Braintrust.
Setup
Install Braintrust alongside Vitest: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 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
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:
vitest-evals reporter and the Braintrust reporter:
vitest.evals.config.mts
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
- The test input, output, status, file path, and full test name.
- Scores from judges and assertions, including
avg_scoreandpasswhen provided byvitest-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 tonew BraintrustVitestEvalsReporter() to control where results are logged:
| Option | Description |
|---|---|
projectName | Braintrust project name. Required unless projectId is set. |
projectId | Braintrust project ID. Required unless projectName is set. |
experimentName | Experiment name. Defaults to a timestamped vitest-evals-* name. |
displaySummary | Whether to print the Braintrust experiment summary after the run. |
metadata | Experiment-level metadata. |
tags | Experiment-level tags. |
baseExperiment | Base experiment name for comparisons. |
baseExperimentId | Base experiment ID for comparisons. |
Key concepts
wrapVitest
wrapVitest wraps Vitest’s test, describe, and expect with Braintrust tracking.
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:
Logging helpers
UselogOutputs and logFeedback inside a wrapVitest test to log additional data to the current span: