Skip to main content
Node.js test runner is the built-in test framework in Node.js. Braintrust integrates with node:test so you can use the integrated Node.js test runner to run evals.

Setup

Install Braintrust in your Node.js project:
Set your API key as an environment variable:

Run your first eval

Create a suite with initNodeTestSuite(), then pass suite.eval() directly to test().
translation.eval.test.ts
Run the test:
Braintrust creates an experiment for the suite, records each tracked test as a span, and prints a summary when the suite flushes.

Separate evals from unit tests

Keep eval files separate from regular unit tests with a naming convention such as *.eval.test.ts or a dedicated evals/ directory.
This keeps slower model-backed tests separate while letting untracked tests continue to use the native runner with no Braintrust involvement.

How it works

  • initNodeTestSuite() creates one Braintrust experiment for the suite.
  • suite.eval() returns a normal node:test callback, so you can mix tracked evals and regular unit tests in the same file.
  • The callback return value becomes the logged output and is passed to scorers.
  • Passing after from node:test registers an automatic flush hook at the end of the suite.
When you do not use suite.eval(), tests run normally and are not logged to Braintrust.

Add scorers

Scorers receive { output, expected, input, metadata } and return a score object.
You can also use scorers from autoevals:

Resources