# E2E Tests > **Warning** > > These test applications are **not intended to be used as example apps or templates**. They may contain: > > - Outdated or deprecated dependency versions used for backwards compatibility testing > - Known security vulnerabilities in dependencies that we intentionally test against > - Non-production-ready configurations and code patterns > > For official examples and best practices, please refer to our [official documentation](https://docs.sentry.io/). E2E tests enable us to verify the behavior of the packages in this repository as if they were to be published in their current state. ## How to run - Copy `.env.example` to `.env` - OPTIONAL: Fill in auth information in `.env` for an example Sentry project - you only need this to run E2E tests that send data to Sentry. - OPTIONAL: Fill in the Cloudflare credentials in `.env` - you only need this to run E2E tests that deploy a real Cloudflare Worker (e.g. `cloudflare-workers-send-to-sentry`). A local run deploys a throwaway worker and deletes it again afterwards; set `E2E_KEEP_WORKER=1` to keep it for debugging. CI keeps one worker per branch or PR instead, and PR workers are deleted by the `cleanup-e2e-workers` workflow when the PR closes. - Run `pnpm run build:tarball` in the root of the repository (needs to be rerun after every update in /packages for the changes to have effect on the tests). To finally run all of the tests: ```bash pnpm run test:e2e ``` Or run only a single E2E test app: ```bash pnpm run test:run ``` Or you can run a single E2E test app with a specific variant: ```bash pnpm run test:run --variant ``` Pass the variant's full label from the test app's `package.json`, for example `--variant "nextjs-16 (webpack, production)"`. ### Using the Makefile Alternatively, you can use the provided Makefile for an interactive test selection experience: **Prerequisites**: Install `fzf` with Homebrew: ```bash brew install fzf ``` **Run tests interactively**: ```bash make run ``` This will display a fuzzy-finder menu of all available test applications. Select one to run it automatically. **List all test applications**: ```bash make list ``` For example, `nextjs-16` has these variants in its `package.json` (shortened): ```json "sentryTest": { "variants": [ { "build-command": "pnpm test:build-webpack", "label": "nextjs-16 (webpack, production)", "assert-command": "pnpm test:prod" }, { "build-command": "pnpm install", "label": "nextjs-16 (webpack, development)", "assert-command": "pnpm test:dev-webpack" } ] } ``` To run one of them, pass its full label: `pnpm run test:run nextjs-16 --variant "nextjs-16 (webpack, production)"`. A variant runs its `build-command` and `assert-command`. Without them, it runs the app's `test:build` and `test:assert` scripts, like the app's default job. ## How they work We build our packages, pack them into tarballs (`pnpm run build:tarball`), and create symlinks in the `packed/` directory that point to the versioned tarballs. When a test application is run, pnpm overrides are injected into its `pnpm-workspace.yaml` to pin all `@sentry/*` and `@sentry-internal/*` packages to those local tarballs. This means test apps install the packages as if they were published, but from the local build output instead of a registry. `@sentry-internal/test-utils` is packed as well. Test apps depend on its tarball directly (`"@sentry-internal/test-utils": "file:../../packed/sentry-internal-test-utils-packed.tgz"`), so after changing test-utils, run `pnpm run build:tarball` again. The E2E test script looks for test applications in the `test-applications` folder. These are standalone apps that use our SDKs and can be used to verify their behavior. ## How to set up a new test Test applications are completely standalone applications that can be used to verify our SDKs. To set one up: ```sh cd dev-packages/e2e-tests mkdir test-applications/my-new-test-application ``` Make sure to add a `test:build` and `test:assert` command to the new app's `package.json` file. Sentry packages are automatically resolved to the local build via pnpm overrides injected at test time, so no manual registry configuration is needed. Each app has a `pnpm-workspace.yaml` for its pnpm settings, because pnpm ignores the `pnpm` and `resolutions` fields in `package.json`. Copy it from a similar app. It needs `minimumReleaseAge: 0` and an `allowBuilds` entry for each dependency with a build script: `true` if the app needs the script, `false` if the script only prints a message. pnpm fails the install (`ERR_PNPM_IGNORED_BUILDS`) for a build script that `allowBuilds` does not list. Apps use the pnpm version of `packageManager` in the root `package.json`. To use another version, set `packageManager` in the app's `package.json` (for example `"packageManager": "pnpm@10.34.6"`), and use the settings of that version in its `pnpm-workspace.yaml`. pnpm then switches to that version, locally and in CI. The lowest supported version is pnpm 10. Apps use the Node.js version of `devEngines.runtime` in the root `package.json`. To use another version, set `devEngines.runtime` in the app's `package.json` (for example `{ "name": "node", "version": "24.15.0", "onFail": "warn" }`). Because the apps run in a temporary directory without the repo's `package.json` files above it, the copy step writes the app's Node.js and pnpm versions into the copied `package.json`. pnpm's `node` and `actions/setup-node` in CI read them from there. ### Test apps that deploy a real Cloudflare Worker Apps like `cloudflare-workers-send-to-sentry` deploy the built app as a real Worker and check what arrives in Sentry: - Use `createWorkerGlobalSetup` and `workerGlobalTeardown` from `@sentry-internal/test-utils/cloudflare` as the Playwright global setup and teardown. Tests read the Worker URL from `E2E_TEST_WORKER_URL`, send requests with `fetchFromWorker`, and poll Sentry with the helpers from `@sentry-internal/test-utils/cli` (the app needs `sentry` as a dev dependency). - The Worker gets `E2E_TEST_DSN`, `E2E_TEST_WORKER_TOKEN` and the values of the `secrets` option as secrets. - CI keeps the Worker after the run, and anyone can reach its `workers.dev` URL. If the Worker can spend money (for example, it holds an LLM API key), it must reject requests without `Authorization: Bearer `. The token is new for every deploy, and `fetchFromWorker` sends it. See `cloudflare-flue-send-to-sentry/src/auth.ts`. - Add the `workerPrefix` to `.github/workflows/cleanup-e2e-workers.yml`, which deletes the Worker of a PR when the PR closes. - To check what Cloudflare stored for a request (for example its Cloudflare trace id), read Workers Logs with `fetchWorkersLogsEvents`. `CLOUDFLARE_API_TOKEN` then also needs "Workers Observability: Edit". See `cloudflare-workers-without-tracing-send-to-sentry`. - Set `"sentryTest": { "optional": true }` in `package.json`, because only the optional CI job has the Cloudflare secrets. ## Runtime variants (Bun, Deno, Cloudflare) To test a framework on a runtime other than Node.js, add an `optionalVariants` entry to the existing test app instead of creating a new app. When the variant is green, move it to `variants`, so that it is required. `react-router-8-framework` is the reference setup. - **`runtime`**: set `"runtime": "bun"`, `"deno"` or `"cloudflare"` on the variant. For such a variant, CI installs Bun or Deno, and the runner and CI set the `RUNTIME` env var for the build and the assert command. Without `runtime`, `RUNTIME` is empty or not set, which means `node`. So a runtime variant can use the default `test:build` and `test:assert` scripts, with no `test:assert:` script, and a new variant needs no change to `.github/workflows/build.yml`. - **`RUNTIME` env var**: read it with `getRuntime()` from `@sentry-internal/test-utils`, which throws on any value other than `node`, `bun`, `deno` or `cloudflare`. Tests branch on it where the runtimes are expected to differ (for example `platform` or `sdk.name`). - **SDK per runtime**: each runtime inits its own SDK, the way a user of that runtime would: Node the framework SDK (`instrument.mjs`), Bun `@sentry/bun` (`instrument.bun.mjs`), Deno `@sentry/deno` (`instrument.deno.mjs`) and Cloudflare `@sentry/cloudflare`. The framework SDK only provides the framework wrappers on the other runtimes, so values that come from its `init()` (`sdk.name`, default integrations) are Node-only. Next.js is different: it loads `instrumentation.ts` on every runtime, so `nextjs-16` calls `init()` of `@sentry/nextjs` on Bun and Deno too. Its Bun and Deno variants build the app on that runtime, so `@sentry/nextjs` loads its `bun` or `deno` entry, which adds the integrations of `@sentry/bun` or `@sentry/deno`. Nuxt is similar: `@sentry/nuxt` bundles `sentry.server.config.ts` into the Nitro output, so `nuxt-4` calls `init()` of `@sentry/nuxt` on Bun and Deno too. `sentry.server.config.bun.ts` and `sentry.server.config.deno.ts` add the integrations of `@sentry/bun` or `@sentry/deno`. On Cloudflare, `nuxt-4` builds with the `cloudflare_durable` preset, and `@sentry/nuxt` wraps the Worker with `withSentry` and the options of the root `sentry.cloudflare.config.ts`. Like the documented Cloudflare setup, that build has no `sentry.server.config.ts`: a runtime-specific file can replace a file but not remove it, so the build command deletes it. Nitro turns every file under `server/api` into a route, so `nuxt.config.ts` lists the runtime-specific files there (such as `db-mongoose.cloudflare.ts`) in Nitro's `ignore`. `nuxt-5` (Nitro 3) has the same setup, with the `cloudflare_module` preset on Cloudflare. - **Start commands**: `playwright.config.mjs` selects the start command with `getRuntime()`. Bun and Deno use the same build as Node and only change the start command, for example `bun --bun --preload ./instrument.bun.mjs ./node_modules/@react-router/serve/bin.cjs ./build/server/index.js` and `deno run -A --preload=@sentry/deno/import --preload=./instrument.deno.mjs ./node_modules/@react-router/serve/bin.cjs ./build/server/index.js`. The app's `deno.json` maps `@sentry/deno/import` to `node_modules`, because the e2e dependencies are `file:` tarballs that `npm:@sentry/deno/import` does not resolve. `nuxt-4` starts the Nitro output with no preload: `bun .output/server/index.mjs` and `deno run -A .output/server/index.mjs`. `express-5` builds CommonJS for Node, so Deno runs its TypeScript sources (`src/main.ts`), and `deno.json` turns on `sloppy-imports` for the relative imports without a file extension. - **Cloudflare**: the app has the Cloudflare dependencies installed all the time. The Cloudflare build has its own `vite.cloudflare.config.ts` with `@cloudflare/vite-plugin` and `sentryCloudflareVitePlugin` from `@sentry/cloudflare/vite`, which the runner uses in place of `vite.config.ts` (see runtime-specific files). List the Sentry plugins after all other plugins: they set no `enforce`, so their position decides when their hooks run, and a sourcemap upload has to see the final output. Node, Bun and Deno share `vite.config.ts`. The Worker entry lives in a separate file (for example `workers/app.ts`) and exports a plain handler: the Sentry plugin wraps it with `withSentry` and reads the init options from `instrument.server.ts` next to the entry. The start command runs `wrangler dev` on the build output. Code at module scope must not do I/O (for example open a database connection), because workerd does not allow it. A socket also works only in the request that opened it, so `express-5` opens its MySQL connection in the request. In an app without `"type": "module"`, name the config `vite.config.mts`. `nextjs-16` has no Vite build: its Cloudflare variant builds with `opennextjs-cloudflare build --config wrangler.opennext.jsonc` and wraps the generated Worker in `worker.ts` with `withSentry` from `@sentry/nextjs/cloudflare`. - **Cloudflare in `vite dev`**: to run the Worker in `vite dev` (for example the dev tests of the `hono-4` Cloudflare variant), start it with `CLOUDFLARE_INCLUDE_PROCESS_ENV=true vite dev`. The runner gives `E2E_TEST_DSN` to the app only as a process env var. `wrangler dev` adds it to the Worker `env` with `--var "E2E_TEST_DSN:$E2E_TEST_DSN"`, but `@cloudflare/vite-plugin` has no such option. It fills the Worker `env` from the `vars` of the wrangler config and from `.dev.vars` or `.env`, and adds process env vars only when `CLOUDFLARE_INCLUDE_PROCESS_ENV` is `true`. Without it, `env.E2E_TEST_DSN` is `undefined`, the SDK sends no events, and the tests fail. - **Build flavors**: a variant can also build the same app with another tool, for example `nextjs-16 (vinext)` builds `nextjs-16` with vinext. A build flavor is not a runtime: its assert script sets its own env var (`VINEXT=1`, read by `tests/isVinext.ts`). It sets `runtime` only to run on another runtime, for example `nextjs-16 (vinext, bun)`. - **Runtime-specific files**: a file that has the runtime as a part of its name replaces the existing file without that part, for example `app/entry.server.cloudflare.tsx` replaces `app/entry.server.tsx` and `vite.cloudflare.config.ts` replaces `vite.config.ts`. For a variant with `runtime`, the runner copies these files over the others in the temporary copy of the app, before the build. This needs no framework or bundler config. A build in the app folder itself does not get these files, so run a variant with `pnpm run test:run --variant `. - **Bun and Deno versions**: a variant can pin the Bun or Deno version, for example `"bun-version": "1.4.4"` or `"deno-version": "v2.9.0"`. - **Bun**: under `bun run` before Bun 1.4.6 the SDK cannot inject diagnostics channels into packages that stay outside the build (for example Express behind `react-router-serve`), so those produce no spans on Bun. Where a test depends on them, branch on `RUNTIME` and say why in a comment. An app that starts its own server can instead bundle it with `@sentry/bun/plugin`, as `nestjs-12/bun-build.mjs` and `express-5/bun-build.mjs` do. Bun 1.3 renames classes in bundles (`class Foo2`), which changes span names taken from class names, so `nestjs-12` pins Bun 1.4 (see #26289). `nuxt-4` and `nuxt-5` build with `bun --bun nuxt build` on Bun, because the Nitro prerenderer loads its `bun-sqlite` connector in the build process. On Bun, Nitro 3 selects its `bun` preset, which serves with `Bun.serve`, so the Bun config of `nuxt-5` adds `bunServerIntegration` and not `bunHttpServerIntegration`. ```json "sentryTest": { "optionalVariants": [ { "runtime": "bun", "label": "my-app (bun)" }, { "runtime": "deno", "label": "my-app (deno)" }, { "runtime": "cloudflare", "label": "my-app (cloudflare)" } ] } ``` ## Troubleshooting ### Common Issues #### Tests fail with "Cannot find module '@sentry/...'" or use wrong package version 1. Rebuild tarballs: `pnpm run build && pnpm run build:tarball` 2. Re-run `pnpm run test:prepare` to refresh symlinks 3. Delete `node_modules` in the test application and re-run the test #### Tests pass locally but fail in CI (or vice versa) - Verify all `@sentry/*` dependencies use `latest || *` version specifier - Check if the test relies on environment-specific behavior ### Debugging Tips 1. **Enable Sentry debug mode**: Add `debug: true` to the Sentry init config to see detailed SDK logs 2. **Check browser console**: Look for SDK initialization errors or warnings 3. **Inspect network requests**: Verify events are being sent to the expected endpoint 4. **Check installed versions**: `cat node_modules/@sentry/browser/package.json | grep version` ## Bundler-Specific Behavior Different bundlers handle environment variables and code replacement differently. This is important when writing tests or SDK code that relies on build-time constants. ### Webpack - `DefinePlugin` replaces variables in your application code - **Does NOT replace values inside `node_modules`** - Environment variables must be explicitly defined ### Vite - `define` option replaces variables in your application code - **Does NOT replace values inside `node_modules`** - `import.meta.env.VITE_*` variables are replaced at build time - For replacing values in dependencies, use `@rollup/plugin-replace` ### Next.js - Automatically injects `process.env` via webpack/turbopack - Handles environment variables more seamlessly than raw webpack/Vite - Server and client bundles may have different environment variable access ### `import.meta.env` Considerations - Only available in Vite and ES modules - Webpack and Turbopack do not have `import.meta.env` - SDK code accessing `import.meta.env` must use try-catch to handle environments where it doesn't exist ```typescript // Safe pattern for SDK code let envValue: string | undefined; try { envValue = import.meta.env.VITE_SOME_VAR; } catch { // import.meta.env not available in this bundler } ``` Test apps in the folder `test-applications` will be automatically picked up by CI in the job `job_e2e_tests` (in `.github/workflows/build.yml`). The test matrix for CI is generated in `dev-packages/e2e-tests/lib/getTestMatrix.mjs`. For each test app, CI checks its dependencies (and devDependencies) to see if any of them have changed in the current PR (based on nx affected projects). For example, if something is changed in the browser package, only E2E test apps that depend on browser will run, while others will be skipped. You can add additional information about the test (e.g. canary versions, optional in CI) by adding `sentryTest` in the `package.json` of a test application. `sentryTest.baseVariant` overrides the default matrix entry using the same fields as an entry in `variants`. For example, set its `assert-command` to run production tests and add a development variant to run both environments in parallel. The local `test:assert` script can still run both; select the base variant locally with `--variant