Skip to content

Commit 07ad5a1

Browse files
committed
test: test isolation scope
1 parent 98f9b79 commit 07ad5a1

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

dev-packages/e2e-tests/test-applications/nitro-3/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "module",
66
"scripts": {
77
"build": "nitro build",
8-
"start": "PORT=3030 NODE_OPTIONS='--import ./instrument.mjs' npx srvx --prod .output/",
8+
"start": "PORT=3030 NODE_OPTIONS='--import ./instrument.mjs' srvx --prod .output/",
99
"clean": "npx rimraf node_modules pnpm-lock.yaml .output",
1010
"test": "playwright test",
1111
"test:build": "pnpm install && pnpm build",
@@ -17,8 +17,10 @@
1717
"devDependencies": {
1818
"@playwright/test": "~1.56.0",
1919
"@sentry-internal/test-utils": "link:../../../test-utils",
20+
"@sentry/core": "latest || *",
2021
"nitro": "https://pkg.pr.new/nitrojs/nitro@4001",
21-
"rolldown": "latest"
22+
"rolldown": "latest",
23+
"srvx": "^0.11.2"
2224
},
2325
"volta": {
2426
"extends": "../../package.json"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { getDefaultIsolationScope, setTag } from '@sentry/core';
2+
import { defineHandler } from 'nitro/h3';
3+
4+
export default defineHandler(() => {
5+
setTag('my-isolated-tag', true);
6+
// Check if the tag leaked into the default (global) isolation scope
7+
setTag('my-global-scope-isolated-tag', getDefaultIsolationScope().getScopeData().tags['my-isolated-tag']);
8+
9+
throw new Error('Isolation test error');
10+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
3+
4+
test('Isolation scope prevents tag leaking between requests', async ({ request }) => {
5+
const transactionEventPromise = waitForTransaction('nitro-3', event => {
6+
return event?.transaction === 'GET /test-isolation/1';
7+
});
8+
9+
const errorPromise = waitForError('nitro-3', event => {
10+
return !event.type && event.exception?.values?.some(v => v.value === 'Isolation test error');
11+
});
12+
13+
await request.get('/test-isolation/1').catch(() => {
14+
// noop - route throws
15+
});
16+
17+
const transactionEvent = await transactionEventPromise;
18+
const error = await errorPromise;
19+
20+
// Assert that isolation scope works properly
21+
expect(error.tags?.['my-isolated-tag']).toBe(true);
22+
expect(error.tags?.['my-global-scope-isolated-tag']).not.toBeDefined();
23+
expect(transactionEvent.tags?.['my-isolated-tag']).toBe(true);
24+
expect(transactionEvent.tags?.['my-global-scope-isolated-tag']).not.toBeDefined();
25+
});

0 commit comments

Comments
 (0)