Skip to content

Commit c7f0b42

Browse files
committed
move tracesSampleRate vs tracesSampler tests
1 parent a575c83 commit c7f0b42

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

packages/tracing/test/hub.test.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,6 @@ describe('Hub', () => {
4141
});
4242

4343
describe('transaction sampling', () => {
44-
describe('tracesSampleRate and tracesSampler options', () => {
45-
it("should call tracesSampler if it's defined", () => {
46-
const tracesSampler = jest.fn();
47-
const hub = new Hub(new BrowserClient({ tracesSampler }));
48-
hub.startTransaction({ name: 'dogpark' });
49-
50-
expect(tracesSampler).toHaveBeenCalled();
51-
});
52-
53-
it('should prefer tracesSampler to tracesSampleRate', () => {
54-
const tracesSampler = jest.fn();
55-
const hub = new Hub(new BrowserClient({ tracesSampleRate: 1, tracesSampler }));
56-
hub.startTransaction({ name: 'dogpark' });
57-
58-
expect(tracesSampler).toHaveBeenCalled();
59-
});
60-
61-
it('tolerates tracesSampler returning a boolean', () => {
62-
const tracesSampler = jest.fn().mockReturnValue(true);
63-
const hub = new Hub(new BrowserClient({ tracesSampler }));
64-
const transaction = hub.startTransaction({ name: 'dogpark' });
65-
66-
expect(tracesSampler).toHaveBeenCalled();
67-
expect(transaction.sampled).toBe(true);
68-
});
69-
});
70-
7144
describe('default sample context', () => {
7245
it('should extract request data for default sampling context when in node', () => {
7346
// make sure we look like we're in node
@@ -196,6 +169,33 @@ describe('Hub', () => {
196169

197170
expect(transaction.sampled).toBe(true);
198171
});
172+
173+
it("should call tracesSampler if it's defined", () => {
174+
const tracesSampler = jest.fn();
175+
const hub = new Hub(new BrowserClient({ tracesSampler }));
176+
hub.startTransaction({ name: 'dogpark' });
177+
178+
expect(tracesSampler).toHaveBeenCalled();
179+
});
180+
181+
it('should prefer tracesSampler to tracesSampleRate', () => {
182+
// make the two options do opposite things to prove precedence
183+
const tracesSampler = jest.fn().mockReturnValue(true);
184+
const hub = new Hub(new BrowserClient({ tracesSampleRate: 0, tracesSampler }));
185+
const transaction = hub.startTransaction({ name: 'dogpark' });
186+
187+
expect(tracesSampler).toHaveBeenCalled();
188+
expect(transaction.sampled).toBe(true);
189+
});
190+
191+
it('should tolerate tracesSampler returning a boolean', () => {
192+
const tracesSampler = jest.fn().mockReturnValue(true);
193+
const hub = new Hub(new BrowserClient({ tracesSampler }));
194+
const transaction = hub.startTransaction({ name: 'dogpark' });
195+
196+
expect(tracesSampler).toHaveBeenCalled();
197+
expect(transaction.sampled).toBe(true);
198+
});
199199
});
200200

201201
describe('isValidSampleRate()', () => {

0 commit comments

Comments
 (0)