Skip to content

Commit ed57f48

Browse files
committed
add integration tests
1 parent 76e1cff commit ed57f48

File tree

15 files changed

+192
-0
lines changed

15 files changed

+192
-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+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [new Integrations.BrowserTracing({ tracePropagationTargets: ['http://example.com'] })],
9+
tracesSampleRate: 1,
10+
});
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, Request } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../../utils/fixtures';
4+
5+
sentryTest(
6+
'should attach `sentry-trace` and `baggage` header to request matching tracePropagationTargets',
7+
async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const requests = (
11+
await Promise.all([
12+
page.goto(url),
13+
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))),
14+
])
15+
)[1];
16+
17+
expect(requests).toHaveLength(3);
18+
19+
requests?.forEach(async (request: Request) => {
20+
const requestHeaders = await request.allHeaders();
21+
expect(requestHeaders).toMatchObject({
22+
'sentry-trace': expect.any(String),
23+
baggage: expect.any(String),
24+
});
25+
});
26+
},
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [
9+
new Integrations.BrowserTracing({ tracePropagationTargets: [], tracingOrigins: ['http://example.com'] }),
10+
],
11+
tracesSampleRate: 1,
12+
});
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')));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, Request } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../../utils/fixtures';
4+
5+
sentryTest(
6+
'[pre-v8] should prefer custom tracePropagationTargets over tracingOrigins',
7+
async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const requests = (
11+
await Promise.all([
12+
page.goto(url),
13+
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))),
14+
])
15+
)[1];
16+
17+
expect(requests).toHaveLength(3);
18+
19+
requests?.forEach(async (request: Request) => {
20+
const requestHeaders = await request.allHeaders();
21+
expect(requestHeaders).not.toMatchObject({
22+
'sentry-trace': expect.any(String),
23+
baggage: expect.any(String),
24+
});
25+
});
26+
},
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [new Integrations.BrowserTracing({ tracingOrigins: ['http://example.com'] })],
9+
tracesSampleRate: 1,
10+
});
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')));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, Request } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../../utils/fixtures';
4+
5+
sentryTest(
6+
'[pre-v8] should attach `sentry-trace` and `baggage` header to request matching tracingOrigins',
7+
async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const requests = (
11+
await Promise.all([
12+
page.goto(url),
13+
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))),
14+
])
15+
)[1];
16+
17+
expect(requests).toHaveLength(3);
18+
19+
requests?.forEach(async (request: Request) => {
20+
const requestHeaders = await request.allHeaders();
21+
expect(requestHeaders).toMatchObject({
22+
'sentry-trace': expect.any(String),
23+
baggage: expect.any(String),
24+
});
25+
});
26+
},
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [new Integrations.BrowserTracing()],
9+
tracesSampleRate: 1,
10+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fetch('http://localhost:4200/0').then(fetch('http://localhost:4200/1').then(fetch('http://localhost:4200/2')));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, Request } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../../utils/fixtures';
4+
5+
sentryTest(
6+
'should attach `sentry-trace` and `baggage` header to request matching default tracePropagationTargets',
7+
async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const requests = (
11+
await Promise.all([
12+
page.goto(url),
13+
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://localhost:4200/${idx}`))),
14+
])
15+
)[1];
16+
17+
expect(requests).toHaveLength(3);
18+
19+
requests?.forEach(async (request: Request) => {
20+
const requestHeaders = await request.allHeaders();
21+
expect(requestHeaders).toMatchObject({
22+
'sentry-trace': expect.any(String),
23+
baggage: expect.any(String),
24+
});
25+
});
26+
},
27+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import * as Sentry from '@sentry/browser';
2+
import { Integrations } from '@sentry/tracing';
3+
4+
window.Sentry = Sentry;
5+
6+
Sentry.init({
7+
dsn: 'https://[email protected]/1337',
8+
integrations: [new Integrations.BrowserTracing()],
9+
tracesSampleRate: 1,
10+
});
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')));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { expect, Request } from '@playwright/test';
2+
3+
import { sentryTest } from '../../../../../utils/fixtures';
4+
5+
sentryTest(
6+
'should not attach `sentry-trace` and `baggage` header to request not matching default tracePropagationTargets',
7+
async ({ getLocalTestPath, page }) => {
8+
const url = await getLocalTestPath({ testDir: __dirname });
9+
10+
const requests = (
11+
await Promise.all([
12+
page.goto(url),
13+
Promise.all([0, 1, 2].map(idx => page.waitForRequest(`http://example.com/${idx}`))),
14+
])
15+
)[1];
16+
17+
expect(requests).toHaveLength(3);
18+
19+
requests?.forEach(async (request: Request) => {
20+
const requestHeaders = await request.allHeaders();
21+
expect(requestHeaders).not.toMatchObject({
22+
'sentry-trace': expect.any(String),
23+
baggage: expect.any(String),
24+
});
25+
});
26+
},
27+
);

0 commit comments

Comments
 (0)