JavaScript collectors
To use Buildkite Test Engine with your JavaScript (npm) projects, use the
test-collector-javascript package with a supported test framework. Buildkite Test Engine supports the following test frameworks:
The recommended way to set up a new test suite is to add the Tests Buildkite plugin to the step that runs your tests. It works with every runner that bktec supports, and the entire setup is configuration-only. You can get a test suite running through changes to pipeline.yml alone, with no modifications to your application code.
Use the language-specific test collector documented on this page when you want deeper framework integration, such as custom execution tags, span annotations, or richer per-framework data. For a runner that bktec supports, you can use bktec to run and split tests while the collector uploads the results. To prevent duplicate test executions, set BUILDKITE_TEST_ENGINE_UPLOAD_RESULTS to false. If you use the Tests Buildkite plugin, set upload-results: false.
You can also upload test results by importing JSON or JUnit XML.
Tests Buildkite plugin example for Jest
The following step uses the Tests Buildkite plugin to run a Jest suite through bktec. The plugin downloads bktec, requests an OIDC token, ensures the test suite exists, and exports the environment variables that bktec expects, so the step's command only needs to invoke bktec run:
steps:
- label: "Jest"
command: bktec run
plugins:
- tests#v1.0.0:
test-runner: jest
result-path: jest-results.json
parallelism: 4
See the Tests Buildkite plugin page for the full plugin reference, including all supported options, running tests inside Docker, and dynamic parallelism with bktec plan.
Add the test collector package
Whichever test framework you use, you first need to add and authenticate the buildkite-test-collector.
To add the test collector package:
In your CI environment, set the
BUILDKITE_ANALYTICS_TOKENenvironment variable to your Test Engine API token. To learn how to set environment variables securely in Pipelines, see Managing pipeline secrets.-
On the command line, create a new branch by running:
git checkout -b install-buildkite-test-engine -
Install
buildkite-test-collectorusing your package manager.For npm, run:
npm install --save-dev buildkite-test-collectorFor yarn, run:
yarn add --dev buildkite-test-collector
Configure the test framework
With the test collector installed, you need to configure it in the test framework.
Jest
If you're already using Jest, you can add buildkite-test-collector/jest/reporter to the list of reporters to collect test results into your Test Engine dashboard.
To configure Jest:
- Make sure Jest runs with access to CI environment variables.
-
Add
"buildkite-test-collector/jest/reporter"to Jest'sreportersconfiguration array (typically found injest.config.js,jest.config.js, orpackage.json):{ "reporters": ["default", "buildkite-test-collector/jest/reporter"], "testLocationInResults": true, }Note: The
"testLocationInResults": truesetting enables column and line capture for Test Engine.
Collecting Jest tests with OpenTelemetry
The JavaScript collector can send Jest results to Buildkite Test Engine as OpenTelemetry spans. Each test execution becomes a root span. Optional child spans show operations inside the test, such as HTTP requests and database queries.
Use Jest 29 or 30 with the default jest-circus runner. OpenTelemetry collection requires buildkite-test-collector 1.15.0 or later and is disabled by default.
Create a test suite if you do not have one. Configure OIDC authentication, or store your suite API token securely as
BUILDKITE_ANALYTICS_TOKENin the environment that runs Jest.-
Install the collector and the OpenTelemetry SDK. On Node.js 22.15 or later, use SDK 3:
npm install --save-dev buildkite-test-collector@1.16.0 \ '@opentelemetry/api@^1.10' \ '@opentelemetry/sdk-trace@^3' \ '@opentelemetry/context-async-hooks@^3' \ '@opentelemetry/exporter-trace-otlp-proto@~0.301.0'On earlier Node.js versions (18.19 or later on Node.js 18, or 20.6 or later), use SDK 2:
npm install --save-dev buildkite-test-collector@1.16.0 \ '@opentelemetry/api@~1.9.0' \ '@opentelemetry/sdk-trace@^2.9' \ '@opentelemetry/context-async-hooks@^2' \ '@opentelemetry/exporter-trace-otlp-proto@~0.223.0'If you're upgrading from
@opentelemetry/sdk-trace-base, replace it with@opentelemetry/sdk-trace. Without it, the collector uploads nothing. -
Configure both the reporter and the runtime in
jest.config.js. Replace an existing Buildkite reporter entry instead of adding a second one:module.exports = { reporters: [ 'default', ['buildkite-test-collector/jest/reporter', { otelEnabled: true }], ], testEnvironment: 'node', runtime: 'buildkite-test-collector/jest/runtime', testLocationInResults: true, };Keep your existing
testEnvironmentsetting, such asnode,jsdom, or a custom environment. If you used an earlier beta, removetestEnvironment: 'buildkite-test-collector/jest/environment'and add the runtime shown above. No environment wrapper is needed.With Jest 29 and
jsdomorhappy-dom, SDK 3 skips package instrumentation and warns. Test results, HTTP, and fetch spans still work. -
Run Jest with its token and CI environment variables available:
npx jest Open the new run in your Buildkite Test Engine suite. For upload problems, check the collector's warnings and the suite's Uploads page.
See the collector's OpenTelemetry guide for more details.
Jasmine
To configure Jasmine:
-
Follow the Jasmine docs to add the Buildkite reporter. For example:
// SpecHelper.js var BuildkiteReporter = require("buildkite-test-collector/jasmine/reporter"); var buildkiteReporter = new BuildkiteReporter(); jasmine.getEnv().addReporter(buildkiteReporter); -
(Optional) To pass in the API token using a custom environment variable, use the following report options:
// SpecHelper.js var buildkiteReporter = new BuildkiteReporter(undefined, { token: process.env.CUSTOM_ENV_VAR, });
Mocha
To configure Mocha:
-
Install the mocha-multi-reporters in your project by running:
npm install mocha-multi-reporters --save-dev -
Configure it to run your desired reporter and the Buildkite reporter:
// config.json { "reporterEnabled": "spec, buildkite-test-collector/mocha/reporter" } -
Update your test script to use the Buildkite reporter using mocha-multi-reporters:
// package.json "scripts": { "test": "mocha --reporter mocha-multi-reporters --reporter-options configFile=config.json" }, -
(Optional) To pass in the API token using a custom environment variable, use the report options. Since the reporter options are passed in as a JSON file, we recommend you put the environment variable name as a string value in the
config.json, which is retrieved using dotenv in the mocha reporter.// config.json { "reporterEnabled": "spec, buildkite-test-collector/mocha/reporter", "buildkiteTestCollectorMochaReporterReporterOptions": { "token_name": "CUSTOM_ENV_VAR_NAME" } }
Cypress
To configure Cypress:
- Make sure Cypress runs with access to CI environment variables.
-
Update your Cypress configuration.
// cypress.config.js // Send results to Test Engine reporter: "buildkite-test-collector/cypress/reporter",Note: To pass in the API token using a custom environment variable, add the
reporterOptionsoption to your Cypress configuration:// cypress.config.js // Send results to Test Engine reporterOptions: { token_name: "CUSTOM_ENV_VAR_NAME" }
Playwright
If you're already using Playwright, you can add buildkite-test-collector/playwright/reporter to the list of reporters to collect test results into your Test Engine dashboard.
To configure Playwright:
- Make sure Playwright runs with access to CI environment variables.
-
Add
"buildkite-test-collector/playwright/reporter"to Playwright'sreporterconfiguration array (typically found inplaywright.config.js):// playwright.config.js { "reporter": [ ["line"], ["buildkite-test-collector/playwright/reporter"] ] }
Collecting Playwright tests with OpenTelemetry
The JavaScript collector can send Playwright results to Buildkite Test Engine as OpenTelemetry spans. Each test attempt, including retries and skipped tests, becomes a root span. Playwright steps, hooks, fixtures, assertions, and actions become nested child spans.
OpenTelemetry collection requires buildkite-test-collector 1.15.0 or later and is disabled by default. Use Playwright 1.41.2 or later.
Create a test suite if you do not have one. Configure OIDC authentication, or store your suite API token securely as
BUILDKITE_ANALYTICS_TOKENin the environment that runs Playwright.-
Install the collector and the OpenTelemetry SDK. On Node.js 22.15 or later, use SDK 3:
npm install --save-dev buildkite-test-collector@1.16.0 \ '@opentelemetry/api@^1.10' \ '@opentelemetry/sdk-trace@^3' \ '@opentelemetry/exporter-trace-otlp-proto@~0.301.0'On earlier Node.js versions (18.19 or later on Node.js 18, or 20.6 or later), use SDK 2:
npm install --save-dev buildkite-test-collector@1.16.0 \ '@opentelemetry/api@~1.9.0' \ '@opentelemetry/sdk-trace@^2.9' \ '@opentelemetry/exporter-trace-otlp-proto@~0.223.0'If you're upgrading from
@opentelemetry/sdk-trace-base, replace it with@opentelemetry/sdk-trace. Without it, the collector uploads nothing. -
Enable OpenTelemetry on the reporter in
playwright.config.js. Replace an existing Buildkite reporter entry instead of adding a second one:module.exports = { reporter: [ ['line'], ['buildkite-test-collector/playwright/reporter', { otelEnabled: true }], ], };No fixture changes or custom runtime are needed. Collection happens in the reporter and does not capture automatic HTTP or database spans, manual spans inside workers, or browser application traces.
-
Run Playwright with its token and CI environment variables available:
npx playwright test Open the new run in your Buildkite Test Engine suite. For upload problems, check the collector's warnings and the suite's Uploads page.
Configuration or upload failures do not fall back to JSON uploads. To return to JSON reporting, disable otelEnabled.
See the collector's OpenTelemetry guide for more details.
Vitest
If you are already using Vitest, you can add buildkite-test-collector/vitest/reporter to the list of reporters to collect test results in your Test Engine dashboard.
To configure Vitest:
Update your Vitest configuration:
// vitest.config.js OR vite.config.js OR vitest.workspace.js
test: {
// Send results to Test Engine
reporters: [
'default',
'buildkite-test-collector/vitest/reporter'
],
// Enable column + line capture for Test Engine
includeTaskLocation: true,
}
If you would like to pass in the API token using a custom environment variable, you can do so using the report options.
// vitest.config.js OR vite.config.js OR vitest.workspace.js
test: {
// Send results to Test Engine
reporters: [
'default',
[
"buildkite-test-collector/vitest/reporter",
{ token: process.env.CUSTOM_ENV_VAR },
],
],
}
Collecting Vitest tests with OpenTelemetry
The JavaScript collector can send Vitest results to Buildkite Test Engine as OpenTelemetry spans. Each test becomes a root span, with hook phases, HTTP requests, package calls such as database queries, and custom instrumentation recorded as child spans.
OpenTelemetry collection requires buildkite-test-collector 1.15.0 or later and is disabled by default. Use Vitest 4.0.11 or later to collect child spans. Vitest 5 requires Node.js 22.12 or later.
Create a test suite if you do not have one. Configure OIDC authentication, or store your suite API token securely as
BUILDKITE_ANALYTICS_TOKENin the environment that runs Vitest.-
Install the collector and the OpenTelemetry SDK. On Node.js 22.15 or later, use SDK 3:
npm install --save-dev buildkite-test-collector@1.16.0 \ '@opentelemetry/api@^1.10' \ '@opentelemetry/sdk-trace@^3' \ '@opentelemetry/context-async-hooks@^3' \ '@opentelemetry/exporter-trace-otlp-proto@~0.301.0'On earlier Node.js versions (18.19 or later on Node.js 18, or 20.6 or later), use SDK 2:
npm install --save-dev buildkite-test-collector@1.16.0 \ '@opentelemetry/api@~1.9.0' \ '@opentelemetry/sdk-trace@^2.9' \ '@opentelemetry/context-async-hooks@^2' \ '@opentelemetry/exporter-trace-otlp-proto@~0.223.0'If you're upgrading from
@opentelemetry/sdk-trace-base, replace it with@opentelemetry/sdk-trace. Without it, the collector uploads nothing. -
Enable the reporter and native tracing in
vitest.config.js. Replace an existing Buildkite reporter entry instead of adding a second one:import { createRequire } from 'node:module'; import { defineConfig } from 'vitest/config'; const require = createRequire(import.meta.url); export default defineConfig({ test: { reporters: [ 'default', ['buildkite-test-collector/vitest/reporter', { otelEnabled: true }], ], includeTaskLocation: true, experimental: { openTelemetry: { enabled: true, sdkPath: require.resolve('buildkite-test-collector/vitest/otel.js'), }, }, }, });require.resolvesupplies the filesystem path Vitest needs, including with pnpm and Yarn. For a CommonJS configuration, omitcreateRequireand userequire.resolvedirectly. For multiple projects, configure tracing in the root configuration. When using Yarn without anode_modulesdirectory, declare the dependencies in the root workspace. -
To capture HTTP and fetch calls, install the instrumentation for your SDK. For SDK 3:
npm install --save-dev \ '@opentelemetry/instrumentation-http@^0.301.0' \ '@opentelemetry/instrumentation-undici@^0.35.0'For SDK 2, use these versions instead:
npm install --save-dev \ '@opentelemetry/instrumentation-http@^0.223.0' \ '@opentelemetry/instrumentation-undici@^0.33.0'With collector 1.16.0 or later, trace database and framework calls such as Express, GraphQL, PostgreSQL, and Redis. Choose packages matching your SDK.
For SDK 3, install individual packages such as
@opentelemetry/instrumentation-pg@0.78.0, or the bundle@opentelemetry/auto-instrumentations-node@0.83.1.For SDK 2, install individual packages such as
@opentelemetry/instrumentation-pg@0.69.0, or the bundle@opentelemetry/auto-instrumentations-node@~0.81.0.Declare them in your project's or parent workspace's
package.json.The bundle enables most instrumentation by default. Its child spans are billed by data ingested and require a plan that includes them.
Limit collection with
OTEL_NODE_ENABLED_INSTRUMENTATIONS(for example,http,undici,pg), or exclude instrumentation withOTEL_NODE_DISABLED_INSTRUMENTATIONS.Some packages need extra setup under Vitest, such as
expressimported from an ES module; see the guide's package instrumentation section. -
Run Vitest with its token and CI environment variables available:
npx vitest runDo not pass
--reporterflags, which override the reporters in the configuration. Watch mode is not supported. Open the new run in your Buildkite Test Engine suite. For upload problems, check the collector's warnings and the suite's Uploads page.
Retries share one execution per test, with each attempt's phases and child spans underneath. Browser mode, VM pools (vmThreads and vmForks), and Vitest 3 send test spans only. Use threads or forks to collect child spans. A custom SDK or missing native tracing configuration also limits collection to test spans. Vitest 1 and 2 do not upload results in OpenTelemetry mode. Configuration or upload failures do not fall back to JSON uploads. To return to JSON reporting, disable otelEnabled.
See the collector's OpenTelemetry guide for more details, including configuration for bktec.
Save the changes
When your collector is installed, commit and push your changes:
-
Add the changes to the staging area by running:
git add . -
Commit the changes by running:
git commit -m "Install and set up Buildkite Test Engine" -
Push the changes by running:
git push
View the results
After completing these steps, you'll see the analytics of test executions on all branches that include this code in the Test Engine dashboard.
If you don't see branch names, build numbers, or commit hashes in the Test Engine dashboard, see CI environments to learn more about exporting your environment.
Troubleshooting missing test executions and --forceExit
Using the --forceExit option when running Jest could result in missing test executions from Test Engine.
--forceExit could potentially terminate any ongoing processes that are attempting to send test executions to Buildkite.
We recommend using --detectOpenHandles to track down open handles which are preventing Jest from exiting cleanly.