Running promptfoo checks in Jest and Vitest without a second test runner
A team with an existing JavaScript test suite in Jest or Vitest now needs to check what its LLM features return. promptfoo can be installed as a dev dependency with npm install --save-dev promptfoo and exposed as custom matchers, such as toMatchSemanticSimilarity and LLM-graded assertions, that run inside the test files the team already has. promptfoo documents this method on its Jest and Vitest integration page, so the team does not need to adopt a separate runner to start.
The practical benefit is that LLM checks run in the same command, the same CI job and the same reporting as the rest of the suite. A failing semantic check fails the build in the same way a failing unit test does. Engineers writing these tests should confirm three things before rollout: which Node.js version the installed promptfoo release requires (the 0.124.1 npm release requires Node.js 22.22.0 or newer, so check the version pinned in your lockfile), which model provider the matchers call and where its API key is stored, and whether the grading model is configured the same way in local runs and CI.
Keep these tests separate from a full promptfoo config when the checks are assertions about code behavior, such as a function that formats a prompt or parses a model response, and the team wants them to gate merges alongside other unit tests. Use a full promptfoo configuration, with its own YAML file, when the work is comparing prompts or models across a dataset, running red team scans, or producing shared reports for reviewers. Matchers are a poor fit for large datasets because each assertion sits inside a test case and the results are harder to compare across runs. The split also controls cost: LLM-graded matchers make paid model calls on every run, so decide which tests run on each pull request and which run on a schedule. Ask the team that owns the suite to define that boundary in writing before the first LLM assertion is merged.
What a Jest or Vitest team needs before adding promptfoo matchers
Adding promptfoo matchers to an existing suite is mostly a question of environment, not code. The cards below cover the runtime, the install, the credentials, the network path from CI and who pays for the model calls each run makes.
Node.js runtime version
The current promptfoo release on npm, 0.124.1, requires Node.js 22.22.0 or newer. Check the Node version on every developer machine and every CI image that runs the suite, not only the one the team uses day to day. A suite that passed on an older runtime can fail at install time after the dependency is added. Pin the runtime in your build configuration so the requirement is visible in review.
promptfoo on npmDev dependency installation
Add promptfoo as a development dependency with npm install --save-dev promptfoo, so it stays out of production bundles. Confirm that your lockfile is committed and that the install step in CI uses the lockfile rather than resolving versions fresh. Decide who approves dependency upgrades, because the matchers depend on the promptfoo version your suite was tested with.
Grader model credentials
LLM-graded and semantic similarity checks call a model, so the test process needs credentials for that provider. Decide which provider and model acts as the grader and store its API key in your CI secret store, not in test files. Use a key scoped to the test project and confirm the provider's rate limits can handle the number of assertions your suite makes in parallel.
Network egress from CI runners
promptfoo runs on your machine or runner and calls the model provider directly, so the runner needs outbound HTTPS to that provider. If your runners sit behind a proxy, a private network or an egress allowlist, add the provider endpoints before the first run. Failures here often look like flaky tests, so confirm connectivity with a single assertion before the full suite is enabled.
Local execution and data flow
promptfoo's documentation states that evals run completely locally and talk directly to the LLM. That means test inputs and model outputs go from your runner to the provider you configured, with no promptfoo-hosted relay in between. Record which prompts and test data leave your environment, and confirm the provider's data handling terms cover them before any sensitive content is used in a test.
promptfoo introductionOwner of the test budget
Every grader call is billed by the model provider, and the cost recurs each time the suite runs on a pull request or nightly job. Name one owner for the provider account and its spending limits, and agree who approves increases when the suite grows. Ask the provider for usage caps or alerts, and keep the number of LLM-graded assertions small enough that the budget is predictable.
How to wire promptfoo matchers into an existing suite
This sequence adds promptfoo-backed semantic similarity and LLM-graded checks to a Jest or Vitest suite you already run, so prompt quality is tested alongside the rest of your code and in CI.
Install promptfoo as a dev dependency
A developer with access to the existing JavaScript project runs
npm install --save-dev promptfoofrom the project root, then confirms the package appears indevDependenciesinpackage.json. Check that Node.js meets the version the npm package requires (the current release, 0.124.1, requires Node.js 22.22.0 or newer), because an older runtime fails before any test runs. Confirm the install by runningnpx promptfoo --versionand seeing a version number printed.Register the custom matchers in the setup file
Add the promptfoo matchers to the setup file your runner already loads, such as a
setupFilesentry for Jest or asetupFilesentry in the Vitest configuration, following the promptfoo Jest and Vitest documentation for the exact import and matcher registration. Keep this change in the shared setup file, not in individual test files, so every test in the suite gets the same matchers. The step is done when an existing test still passes and a deliberately emptyexpect(...).toMatchSemanticSimilaritycall runs without a "matcher not found" error.Set the grader provider and its key
Choose the model that will grade outputs and make its credentials available through environment variables, not through test files or committed config. The developer or platform engineer who owns the CI secret store should confirm which key the chosen provider expects, since the promptfoo documentation lists the variable names per provider. Confirm with your security team where the key is stored and who can read it in CI. The step is done when a local shell with the variable exported can reach the grader, and the same variable is absent from any file that enters version control.
Write a semantic similarity test
Add one test that calls your prompt or application function, takes its output, and checks it against a reference answer with
toMatchSemanticSimilarity. The reference should be a sentence that states the required meaning, not an exact string, so harmless rewording still passes. Keep the test small and deterministic in its inputs. The check that closes this step is a passing run locally, followed by a deliberate edit to the reference meaning that causes the test to fail, which proves the matcher is actually comparing content.Write an LLM-graded test
Add a second test for a property that similarity scoring handles poorly, such as whether a response refuses a prohibited request, stays in a required format, or avoids a stated claim. Express the rule as a grading criterion that a model can apply to the output, and use the LLM-graded matcher the promptfoo documentation describes for Jest or Vitest. Record why the grader is needed for this case in a comment, since future maintainers will otherwise question the extra cost. The step closes when the test passes on a compliant output and fails on a non-compliant output you supply on purpose.
Run the suite locally
The developer runs the existing test command, such as
npm testornpx vitest run, with the grader key exported in the shell. Review the output for the two new tests, confirm they make grader calls (for example, through the provider's usage view), and note any intermittent results across a few runs, since graded outputs can vary. Record the expected pass or fail behavior for each test in the team's notes. The step is done when the whole suite passes with the new tests included and the failure check from the previous steps has been repeated.Run the suite in CI with secrets injected
Add the grader key to your CI system's secret store, expose it only to the job that runs these tests, and run the same test command in the pipeline. Confirm that pull requests from forks cannot read the secret, and decide whether these tests run on every commit or on a schedule, since each graded assertion makes a paid model call. The step is done when a pull request with an intentional meaning change turns the pipeline red, and a normal pull request turns it green without printing the key in logs.
How the matchers call the grader and what a failure means
The semantic similarity matcher and the LLM-graded check do different jobs, and a failure from each means something different. The similarity matcher converts the model output and the expected text into embeddings, which are numeric representations of meaning, then compares how close they are. It does not ask a model to reason about correctness, so a fluent answer that says the wrong thing can still score well if it uses similar words. The LLM-graded check sends the output and your rubric to a model acting as a judge and reads back a verdict. Here the grader's own behavior matters: it is a second model call, so its answers can shift with the grader model, its version, its settings and the wording of your rubric. Confirm which provider and grader model your Jest or Vitest setup uses before you compare results across machines or over time.
Both paths are non-deterministic in practice. The application under test can return different text on each run, and the grader can judge borderline outputs differently from one call to the next. A single red test is therefore a signal to investigate, not proof of a regression. Re-run the failing case a few times, read the actual output and the grader's stated reasoning if your setup records it, and check whether the threshold or rubric is the thing that moved. Treat a rewritten rubric or a changed threshold as a change to the test itself, and record it the same way you would record a change to the prompt.
When an assertion fails, review it before you change the prompt. Ask whether the output was actually wrong, whether the expected text or rubric was too narrow, whether the grader misread the instruction, and whether a recent upgrade of promptfoo or the grader model changed the result. Only after that review should the prompt change, and then the whole suite should be re-run, since a prompt edit that fixes one case can break others. Keep a short note of each failure and its cause. Over several weeks, those notes show whether your tests are catching real quality problems or mostly reflecting grader noise, and that answer decides how far you can rely on these checks as a merge gate.
Which settings map to which test concepts
This table maps each concept in a Jest or Vitest suite with promptfoo matchers to the file or setting where it is configured. Read it when you add the first matcher, so you know which file to edit and which values to confirm against the documentation for your installed version.
| Concept | Where it lives | What to confirm |
|---|---|---|
| Test assertion | The Jest or Vitest test file, where the matcher is called on the model output | The matcher name and its argument order for your promptfoo version |
| Matcher registration | The setup file listed in your test runner configuration, which registers promptfoo matchers before tests run | The setup file path and import form shown in the promptfoo Jest and Vitest documentation |
| Grader provider | The grader setting passed to the matcher or the configuration it reads, naming the model that judges the output | Which grader option is supported, and whether it can be set per test or only globally |
| Expected value | The reference text or expected answer passed as the matcher argument in the test file | Whether the matcher expects a string, an object or a list of expected values |
| Threshold | The minimum score passed to a similarity or grading matcher, set alongside the expected value | The default threshold and the score range the installed version returns |
| API keys | Environment variables read at run time, such as the key for the grader or model provider | The variable names the chosen provider expects, and that they stay out of committed test files |
| Test runner options | The Jest or Vitest configuration file and the npm script that runs the suite | Whether promptfoo requires a specific timeout or sequential run setting for LLM calls |
How a test run flows from Jest or Vitest to the model provider
The run starts in the test runner, where a test calls a promptfoo matcher such as toMatchSemanticSimilarity or an LLM-graded check. The matcher makes a grader provider call over the network to the model provider, and the response comes back to the assertion as a pass or fail. Provider keys are injected at the CI runner, which is the trust boundary to check: keys should be scoped to the job and never written into test files or logs.
Test runner, promptfoo matcher and the model provider, with the CI boundary marked.
Keeping provider keys and test data safe in CI
Jest and Vitest tests that call a model or a grader run in CI with credentials and data that need the same care as production. The cards below cover where keys live, who can read them, what test data leaves your network, which promptfoo version runs, and what ends up in logs.
Store provider keys in the CI secret store
Keep the API key for each model provider and grader in your CI system's secret store, never in the repository, a .env file committed by accident, or a test fixture. Expose it to the test job as an environment variable at run time. Check the repository history and any shared test helpers for keys that were pasted in during earlier debugging, and rotate any key that was ever committed.
Limit which pipelines read secrets
Scope the key to the jobs that need it. Pull requests from forks, and branches that are not protected, should not receive the model key, because any code in the pull request can print environment variables during a test run. Run the LLM tests on protected branches or after review, and confirm how your CI system handles secrets for forked pull requests.
Use synthetic data in fixtures
Fixtures sent to a model or to an LLM grader leave your environment and reach a third-party service. Use invented customers, accounts and documents that match the shape of your real data. Before a test sends anything, confirm with your privacy and legal teams which providers are approved to receive that category of data, and what each provider's data retention terms say.
Pin the promptfoo version
Install promptfoo as a dev dependency and commit the lockfile, so CI runs the same release on every build. Upgrade on purpose, read the release notes, and rerun the suite after each change. The current npm release is 0.124.1, which requires Node.js 22.22.0 or newer, so pin the Node.js version in CI too.
promptfoo on npmReview logs for prompts and outputs
Test output, failure messages and CI artifacts often include the full prompt, the model response and the grader's reasoning. Those can contain test data, and in some cases fragments of a provider's response that you would not want stored. Set the log level for CI runs, decide which artifacts are kept and for how long, restrict who can download them, and search a sample of recent logs for keys and sensitive values before you widen access.
Common failures when promptfoo runs inside Jest or Vitest
This table lists the failures teams most often hit when promptfoo matchers run inside an existing Jest or Vitest suite, with the likely cause and fix for each. Read it before the first CI run, and use the cause column to narrow down a failure that only appears on a runner. The main takeaway is that most failures come from setup, credentials and network reach rather than from the prompts under test.
| Failure | Likely cause | Fix |
|---|---|---|
| Install or run error on Node.js | The local or CI Node.js version is older than the release requires. The current npm release requires Node.js 22.22.0 or newer. | Pin the runtime to Node.js 22.22.0 or newer in local tooling and in the CI image, then reinstall dependencies. |
| Matchers not found or not registered | The setup file that registers promptfoo's custom matchers is not listed in the test runner configuration, so the matcher names are undefined at test time. | Add the promptfoo setup file to the runner's setup hook in the Jest or Vitest config and confirm it loads before the first test. |
| Matcher works locally but fails with a missing key | The grader provider needs an API key, and the key lives in a local shell profile or .env file that the CI job never receives. | Store the grader key as a masked CI secret, expose it only to the job that runs these tests, and fail fast with a clear message when it is absent. |
| Flaky pass or fail on the same input | LLM-graded checks and some similarity checks vary between calls, so a borderline output can pass on one run and fail on the next. | Set explicit thresholds, use a deterministic grader model setting where supported, keep prompts for graded tests fixed, and rerun or quarantine tests that sit near the threshold. |
| Timeouts on provider calls | Default test timeouts in Jest or Vitest are shorter than the latency of a model call plus grading, especially on large prompts or busy providers. | Raise the timeout for these test files only, not the whole suite, and keep the number of graded assertions per test small. |
| Passes on a laptop, fails on the runner | The CI runner has different egress rules, so it cannot reach the model endpoint, the grader endpoint or a proxy the developer machine uses. | Confirm with the network team which provider hostnames the runner may reach, allow them explicitly, and check proxy variables in the job environment. |
| Results differ between Jest and Vitest | The two runners handle setup files, globals and async assertion errors differently, so a matcher setup copied from one may behave differently in the other. | Keep one setup file per runner, test each runner in CI, and confirm the failure message appears in the runner's output before trusting a pass. |
Questions teams ask before adding promptfoo to Jest or Vitest
What does adding promptfoo checks to Jest or Vitest cost in engineering effort?
The one-time cost is mostly engineering time: installing the package, wiring the matchers into the test setup, writing the first set of checks and agreeing what a passing result means. The recurring cost is smaller but continuous: maintaining expected outputs as prompts change, reviewing failures, and paying for the model calls the graders make on every run. Model usage is billed by your provider, so ask any partner to show which calls run in CI, how often, and which model acts as grader. A quote should separate the setup work, the recurring test maintenance and the handover.
How long does a first Jest or Vitest integration take?
Duration depends on three drivers: how many prompt-driven functions the suite covers, how many of them need semantic or LLM-graded checks rather than exact matches, and how the grader is set up. A suite with a handful of functions and a grader model already approved by your security team is far quicker to wire up than one that needs new provider accounts, a review of grader prompts and agreement on pass thresholds. No duration is given here. Ask for a timeline tied to a written scope that lists the test files, the matchers and the CI jobs in use.
What must our team provide before an integration starts?
Plan to provide five things:
- Read and write access to the repository that holds the test suite
- CI access to add a job that runs the checks and stores their output
- Provider accounts and API keys for the model under test and for the grader, with spend limits you control
- A named owner for expected outputs who can decide whether a changed answer is a regression or an improvement
- A decision on where secrets live, such as your CI secret store
The expected-output owner is the item teams most often skip, and the checks are weak without one.
Can an in-house engineering team add promptfoo to Jest or Vitest alone?
Yes, if the team already maintains a JavaScript test suite and has someone comfortable with npm and CI configuration. The package is installed with npm install --save-dev promptfoo, and the work is mostly ordinary test writing. Where an in-house team usually needs help is in grader design: choosing what counts as a semantic match, writing reliable rubrics for LLM grading and setting thresholds that do not flap between runs. A partner can review those choices, or the team can run a short pilot first and decide afterward.
Does the free promptfoo Community edition cover these matchers?
The promptfoo Community edition is free and includes all LLM evaluation features, all model providers and integrations, and red teaming with 10k probes per month, with community support. The Jest and Vitest matchers are part of the LLM evaluation feature set, so the Community edition covers them under the MIT license. Enterprise features such as team sharing, SSO and continuous monitoring are separate and are not needed for Jest or Vitest checks to run. Confirm the current edition terms on the promptfoo pricing page before you commit.
Should LLM checks run inside Jest or Vitest, or in a full promptfoo config?
Use Jest or Vitest matchers for checks that belong to application code, such as a function that must return a summary close in meaning to a reference, and that should fail the same build as unit tests. Use a full promptfoo config for suites that compare several prompts or models, run red team scans, or need a shared report for reviewers. The two can coexist: the test runner gates each commit, and the config produces broader evidence on a schedule. Keeping them separate avoids forcing large comparison runs into a unit test job.
What breaks most often after the checks go live?
The most common problems are flaky thresholds, grader drift and unexpected cost. A semantic similarity threshold set too tight fails on harmless rewording, while one set too loose lets regressions pass. LLM-graded checks can change verdict when the grader model is updated, so pin model versions where your provider allows it. Also watch CI run time and provider spend, since every grader call costs money. Ask your team or a partner to review failing checks weekly during the first month.
Where the official Jest and Vitest guidance sits
The authoritative reference for matcher names, setup steps and configuration is the promptfoo documentation page titled Testing prompts with Jest and Vitest. Treat that page as the source of truth when this guide and the library disagree, and check it again before you upgrade promptfoo, because matcher names and options are the details most likely to change between releases. The page covers the install step, which uses npm install --save-dev promptfoo, and the custom matchers such as toMatchSemanticSimilarity and the LLM-graded checks that your tests will call. Read it once end to end before writing your first assertion, so that the matcher you choose matches the grading approach your team has agreed to use.
Before you copy any example into your suite, confirm three things against that page and your own environment: the promptfoo version pinned in your lockfile, the Node.js version your CI runners provide, and which model provider the graded matchers will call. The supplied facts state that the current npm release requires Node.js 22.22.0 or newer, so a runner image older than that will fail before any test runs. Graded matchers also send prompts to a model, so the provider and its credentials need to be available in the environment where Jest or Vitest runs, not only on a developer laptop. Write these checks into your own runbook so the next engineer does not have to rediscover them.
How DeployOpen scopes and delivers promptfoo test integrations
DeployOpen plans, builds, documents and supports promptfoo checks inside your existing JavaScript test suite, in infrastructure you control. We start from the tests your team already runs under Jest or Vitest, agree what the LLM checks should cover, and deliver the work under a written, fixed scope.
How we scope
- Inventory the existing Jest or Vitest suites, CI jobs and the LLM calls they would exercise before any code changes.
- Agree which outputs need semantic similarity checks and which need LLM-graded checks, and which model provides the grading.
- Record in writing which tests stay in Jest or Vitest and which belong in a separate promptfoo config, with reasons.
How we build
- Install promptfoo as a development dependency and add the custom matchers to the test setup your team already uses.
- Write the LLM checks as ordinary test cases, with fixtures, thresholds and provider settings kept in version-controlled files.
- Keep API keys out of test code and wire them through your existing secret store or CI variables, tested in a non-production environment first.
How we hand over
- Deliver the test code, configuration, a short runbook and notes on how to add new prompt checks without changing the framework.
- Walk your engineers through a run locally and in the pipeline, and document the expected cost and rate-limit behavior of grading calls.
- Confirm with your team which promptfoo version is pinned and the Node.js version required by that release before handover.
How we support
- Ongoing support, upgrades of promptfoo and continuous testing are available as retainers after handover.
- Upgrades are planned against the promptfoo release notes, with the matcher behavior and test results re-verified after each change.
- Ask your DeployOpen contact to confirm response expectations and what a retainer includes before signing a scope.

