Skip to content

Commit b077373

Browse files
committed
feat: Add additional tests
1 parent c288ad4 commit b077373

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

packages/apm/test/hub.test.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { BrowserClient } from '@sentry/browser';
22
import { Hub, Scope } from '@sentry/hub';
3+
import { Span, Transaction } from '@sentry/types';
34

45
import { addExtensionMethods } from '../src/hubextensions';
56

@@ -36,14 +37,22 @@ describe('Hub', () => {
3637
});
3738
});
3839

39-
describe('start', () => {
40-
test('simple', () => {
40+
describe('startSpan', () => {
41+
test('simple standalone Span', () => {
4142
const hub = new Hub(new BrowserClient());
4243
const span = hub.startSpan({}) as any;
4344
expect(span.spanId).toBeTruthy();
4445
});
4546

46-
test('transaction inherits trace_id from span on scope', () => {
47+
test('simple standalone Transaction', () => {
48+
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }));
49+
const transaction = hub.startSpan({ name: 'transaction' }) as Transaction;
50+
expect(transaction.spanId).toBeTruthy();
51+
// tslint:disable-next-line: no-unbound-method
52+
expect(transaction.setName).toBeTruthy();
53+
});
54+
55+
test('Transaction inherits trace_id from span on scope', () => {
4756
const myScope = new Scope();
4857
const hub = new Hub(new BrowserClient(), myScope);
4958
const parentSpan = hub.startSpan({}) as any;
@@ -53,6 +62,24 @@ describe('Hub', () => {
5362
const span = hub.startSpan({ name: 'test' }) as any;
5463
expect(span.trace_id).toEqual(parentSpan.trace_id);
5564
});
65+
66+
test('create a child if there is a Span already on the scope', () => {
67+
const myScope = new Scope();
68+
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1 }), myScope);
69+
const transaction = hub.startSpan({ name: 'transaction' }) as Transaction;
70+
hub.configureScope(scope => {
71+
scope.setSpan(transaction);
72+
});
73+
const span = hub.startSpan({}) as Span;
74+
expect(span.traceId).toEqual(transaction.traceId);
75+
expect(span.parentSpanId).toEqual(transaction.spanId);
76+
hub.configureScope(scope => {
77+
scope.setSpan(span);
78+
});
79+
const span2 = hub.startSpan({}) as Span;
80+
expect(span2.traceId).toEqual(span.traceId);
81+
expect(span2.parentSpanId).toEqual(span.spanId);
82+
});
5683
});
5784
});
5885
});

0 commit comments

Comments
 (0)