Skip to content

Commit 72f9969

Browse files
committed
test(tracing): Add test to validate that spans only added when active span exists
1 parent 9690d7d commit 72f9969

File tree

6 files changed

+92
-0
lines changed

6 files changed

+92
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
// disable pageload transaction
8+
integrations: [Sentry.BrowserTracing({ tracingOrigins: ['http://example.com'], startTransactionOnPageLoad: false })],
9+
tracesSampleRate: 1,
10+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fetch('http://example.com/0').then(fetch('http://example.com/1').then(fetch('http://example.com/2')));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { shouldSkipTracingTest } from '../../../../utils/helpers';
5+
6+
sentryTest(
7+
'there should be no span created for fetch requests with no active span',
8+
async ({ getLocalTestPath, page }) => {
9+
if (shouldSkipTracingTest()) {
10+
sentryTest.skip();
11+
}
12+
13+
const url = await getLocalTestPath({ testDir: __dirname });
14+
15+
let requestCount = 0;
16+
page.on('request', request => {
17+
expect(request.url()).not.toContain(url);
18+
requestCount++;
19+
});
20+
21+
await page.goto(url);
22+
23+
// There are 6 requests in the page:
24+
// 1. HTML page
25+
// 2. Init JS bundle
26+
// 3. Subject JS bundle
27+
// and then 3 fetch requests
28+
expect(requestCount).toBe(6);
29+
},
30+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
3+
window.Sentry = Sentry;
4+
5+
Sentry.init({
6+
dsn: 'https://[email protected]/1337',
7+
// disable pageload transaction
8+
integrations: [Sentry.BrowserTracing({ tracingOrigins: ['http://example.com'], startTransactionOnPageLoad: false })],
9+
tracesSampleRate: 1,
10+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const xhr_1 = new XMLHttpRequest();
2+
xhr_1.open('GET', 'http://example.com/0');
3+
xhr_1.send();
4+
5+
const xhr_2 = new XMLHttpRequest();
6+
xhr_2.open('GET', 'http://example.com/1');
7+
xhr_2.send();
8+
9+
const xhr_3 = new XMLHttpRequest();
10+
xhr_3.open('GET', 'http://example.com/2');
11+
xhr_3.send();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../utils/fixtures';
4+
import { shouldSkipTracingTest } from '../../../../utils/helpers';
5+
6+
sentryTest(
7+
'there should be no span created for xhr requests with no active span',
8+
async ({ getLocalTestPath, page }) => {
9+
if (shouldSkipTracingTest()) {
10+
sentryTest.skip();
11+
}
12+
13+
const url = await getLocalTestPath({ testDir: __dirname });
14+
15+
let requestCount = 0;
16+
page.on('request', request => {
17+
expect(request.url()).not.toContain(url);
18+
requestCount++;
19+
});
20+
21+
await page.goto(url);
22+
23+
// There are 6 requests in the page:
24+
// 1. HTML page
25+
// 2. Init JS bundle
26+
// 3. Subject JS bundle
27+
// and then 3 fetch requests
28+
expect(requestCount).toBe(6);
29+
},
30+
);

0 commit comments

Comments
 (0)