Skip to main content
The Sentry JavaScript SDK has comprehensive test coverage including unit tests, integration tests, and E2E tests. This guide explains how to run them all.
You must run yarn build before yarn test will work, as tests depend on built type definitions.

Unit Tests

Run All Unit Tests

From the repository root:
This runs unit tests for all packages except integration and E2E test packages:

Run Tests for a Single Package

Navigate to the package directory and run tests:
Or run tests with coverage:

Run Tests for Changed Packages

To run tests only for packages affected by your changes:

Test Configuration

Tests are run with Vitest. Each package has a test script in its package.json:

Integration Tests

Integration tests verify SDK behavior in real runtime environments.

Browser Integration Tests

Test browser-specific functionality using Playwright:

Node.js Integration Tests

Test Node.js-specific functionality:

Cloudflare Integration Tests

Test Cloudflare Workers functionality:

E2E Tests

E2E tests verify SDK behavior in real-world framework scenarios using a local npm registry (Verdaccio).

Prerequisites

  1. Docker - Required to run the Verdaccio registry container
  2. Volta with pnpm support - Enable with VOLTA_FEATURE_PNPM=1

Setup

  1. Build packages and create tarballs:
You must re-run yarn build:tarball after any changes to packages for the changes to take effect in E2E tests.
  1. Configure environment (optional):

Run E2E Tests

Run all E2E tests:
Run a specific test application:
Run with a specific variant:

How E2E Tests Work

  1. A fake npm registry (Verdaccio) is launched in Docker
  2. SDK packages are built, packed, and published to Verdaccio
  3. Test applications install packages from Verdaccio
  4. Tests run against the test applications
This ensures tests use your local changes, not published versions from npm.

E2E Test Structure

Test applications live in dev-packages/e2e-tests/test-applications/:

Important: The .npmrc File

Every E2E test application must have an .npmrc file:
Without this file, pnpm will install packages from the public npm registry instead of your local Verdaccio instance, causing tests to use published versions instead of your local changes.
To verify packages are from Verdaccio, check:

Testing Locally

To test local SDK versions in external test projects, you have several options: Symlink your local package:

Option 2: yalc

Use yalc to install packages as if they were published:
See docs/using-yalc.md for details.

Option 3: Tarballs

Install from a tarball:

CI Testing

Browser Tests

Node Tests

Bun Tests

Adding Tests

Any non-trivial fixes/features should include tests. You’ll find a test/ folder in each package.

Unit Tests

Add tests in the package’s test/ directory:

Integration Tests

  • Browser changes: Add tests in dev-packages/browser-integration-tests
  • Node changes: Add tests in dev-packages/node-integration-tests
  • E2E tests: Add test apps in dev-packages/e2e-tests/test-applications

Common Issues

Tests fail after SDK changes

Rebuild packages:

E2E tests use wrong package versions

  1. Check for .npmrc file in test application
  2. Rebuild tarballs: yarn build && yarn build:tarball
  3. Delete node_modules in test app and re-run

Docker/Verdaccio issues

  • Ensure Docker daemon is running
  • Check port 4873 is not in use: lsof -i :4873
  • Stop existing containers: docker ps && docker stop <container-id>

Type errors in tests

Ensure types are built:

Debugging Tests

  1. Enable debug mode: Add debug: true to Sentry config
  2. Check browser console: Look for SDK initialization errors
  3. Inspect network requests: Verify events are sent correctly
  4. Check installed versions: Verify package versions in node_modules

Next Steps