Skip to content

Commit 8c39c57

Browse files
committed
add tests but they no work :(
1 parent 1cd0480 commit 8c39c57

File tree

11 files changed

+186
-0
lines changed

11 files changed

+186
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
async function run() {
2+
Sentry.startSpan({ name: 'parent_span' }, () => {
3+
Sentry.startSpan({ name: 'child_span' }, () => {
4+
// whatever a user would do here
5+
});
6+
});
7+
}
8+
9+
run();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getFirstSentryEnvelopeRequest, shouldSkipTracingTest } from '../../../../utils/helpers';
6+
7+
sentryTest('should send a transaction in an envelope', async ({ getLocalTestPath, page }) => {
8+
if (shouldSkipTracingTest()) {
9+
sentryTest.skip();
10+
}
11+
12+
const url = await getLocalTestPath({ testDir: __dirname });
13+
const transaction = await getFirstSentryEnvelopeRequest<Event>(page, url);
14+
15+
expect(transaction.transaction).toBe('parent_span');
16+
expect(transaction.spans).toBeDefined();
17+
});
18+
19+
sentryTest('should report finished spans as children of the root transaction', async ({ getLocalTestPath, page }) => {
20+
if (shouldSkipTracingTest()) {
21+
sentryTest.skip();
22+
}
23+
24+
const url = await getLocalTestPath({ testDir: __dirname });
25+
const transaction = await getFirstSentryEnvelopeRequest<Event>(page, url);
26+
27+
const rootSpanId = transaction?.contexts?.trace?.spanId;
28+
29+
expect(transaction.spans).toHaveLength(1);
30+
31+
const span_1 = transaction.spans?.[0];
32+
expect(span_1?.description).toBe('child_span');
33+
expect(span_1?.parentSpanId).toEqual(rootSpanId);
34+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
async function run() {
2+
await Sentry.startSpan({ name: 'parent_span' }, async () => {
3+
Promise.reject('Async Promise Rejection');
4+
});
5+
}
6+
7+
const button = document.getElementById('button1');
8+
button.addEventListener('click', async () => {
9+
await run();
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title></title>
6+
</head>
7+
<body>
8+
<button id="button1" type="button">Button 1</button>
9+
</body>
10+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers';
6+
7+
sentryTest(
8+
'should capture a promise rejection within an async startSpan callback',
9+
async ({ getLocalTestPath, page }) => {
10+
if (shouldSkipTracingTest()) {
11+
sentryTest.skip();
12+
}
13+
14+
const url = await getLocalTestPath({ testDir: __dirname });
15+
const envelopePromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);
16+
17+
const gotoPromise = page.goto(url);
18+
const clickPromise = page.getByText('Button 1').click();
19+
20+
const [_, events] = await Promise.all([gotoPromise, envelopePromise, clickPromise]);
21+
22+
const [txn, err] = events[0]?.type === 'transaction' ? [events[0], events[1]] : [events[1], events[0]];
23+
24+
expect(txn).toMatchObject({ transaction: 'parent_span' });
25+
26+
expect(err?.exception?.values?.[0]?.value).toBe('[object Promise]');
27+
},
28+
);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
async function run() {
2+
await Sentry.startSpan({ name: 'parent_span' }, async () => {
3+
throw new Error('Async Thrown Error');
4+
});
5+
}
6+
7+
const button = document.getElementById('button1');
8+
button.addEventListener('click', async () => {
9+
await run();
10+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8" />
5+
<title></title>
6+
</head>
7+
<body>
8+
<button id="button1" type="button">Button 1</button>
9+
</body>
10+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers';
6+
7+
sentryTest('should capture a thrown error within an async startSpan callback', async ({ getLocalTestPath, page }) => {
8+
if (shouldSkipTracingTest()) {
9+
sentryTest.skip();
10+
}
11+
12+
page.on('pageerror', err => console.log('pageerror', err));
13+
page.on('console', msg => console.log('console', msg.text()));
14+
15+
const url = await getLocalTestPath({ testDir: __dirname });
16+
const envelopePromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);
17+
18+
const gotoPromise = page.goto(url);
19+
const clickPromise = page.getByText('Button 1').click();
20+
21+
console.log('before wait');
22+
23+
const [_, events] = await Promise.all([gotoPromise, envelopePromise, clickPromise]);
24+
25+
console.log('after wait');
26+
27+
const [txn, err] = events[0]?.type === 'transaction' ? [events[0], events[1]] : [events[1], events[0]];
28+
29+
expect(txn).toMatchObject({ transaction: 'parent_span' });
30+
31+
expect(err?.exception?.values?.[0]?.value).toBe('[object Promise]');
32+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
function run() {
2+
Sentry.startSpan({ name: 'parent_span' }, () => {
3+
throw new Error('Sync Error');
4+
});
5+
}
6+
7+
// using `setTimeout` here because otherwise the thrown error will be
8+
// thrown as a generic "Script Error." instead of the actual error".
9+
setTimeout(run);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { expect } from '@playwright/test';
2+
import type { Event } from '@sentry/types';
3+
4+
import { sentryTest } from '../../../../utils/fixtures';
5+
import { getMultipleSentryEnvelopeRequests, shouldSkipTracingTest } from '../../../../utils/helpers';
6+
7+
sentryTest('should capture an error within a sync startSpan callback', async ({ getLocalTestPath, page }) => {
8+
if (shouldSkipTracingTest()) {
9+
sentryTest.skip();
10+
}
11+
12+
const url = await getLocalTestPath({ testDir: __dirname });
13+
const gotoPromise = page.goto(url);
14+
const envelopePromise = getMultipleSentryEnvelopeRequests<Event>(page, 2);
15+
16+
const [_, events] = await Promise.all([gotoPromise, envelopePromise]);
17+
18+
const [txn, err] = events[0]?.type === 'transaction' ? [events[0], events[1]] : [events[1], events[0]];
19+
20+
expect(txn).toMatchObject({ transaction: 'parent_span' });
21+
expect(err?.exception?.values?.[0]?.value).toBe('Sync Error');
22+
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as Sentry from '@sentry/browser';
2+
// eslint-disable-next-line no-unused-vars
3+
import * as _ from '@sentry/tracing';
4+
5+
window.Sentry = Sentry;
6+
7+
Sentry.init({
8+
dsn: 'https://[email protected]/1337',
9+
tracesSampleRate: 1.0,
10+
normalizeDepth: 10,
11+
debug: true,
12+
});

0 commit comments

Comments
 (0)