Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad committed Mar 19, 2024
1 parent b870173 commit 886513a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ app.get('/test/express', (_req, res) => {
const traceId = transaction?.spanContext().traceId;
const headers = http.get('http://somewhere.not.sentry/').getHeaders();
if (traceId) {
headers['baggage'] = (headers['baggage'] as string).replace(traceId, '__SENTRY_TRACE_ID__')
headers['baggage'] = (headers['baggage'] as string).replace(traceId, '__SENTRY_TRACE_ID__');
}
// Responding with the headers outgoing request headers back to the assertions.
res.send({ test_data: headers });
Expand Down
21 changes: 12 additions & 9 deletions packages/node/test/handlers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getMainCarrier,
mergeScopeData,
setCurrentClient,
spanIsSampled,
spanToJSON,
withScope,
} from '@sentry/core';
Expand Down Expand Up @@ -322,12 +323,13 @@ describe('tracingHandler', () => {
dsc: { version: '1.0', environment: 'production' },
});

const transaction = (res as any).__sentry_transaction;
const transaction = (res as any).__sentry_transaction as Transaction;

// since we have no tracesSampler defined, the default behavior (inherit if possible) applies
expect(transaction.traceId).toEqual('12312012123120121231201212312012');
expect(transaction.parentSpanId).toEqual('1121201211212012');
expect(transaction.sampled).toEqual(true);
expect(transaction.spanContext().traceId).toEqual('12312012123120121231201212312012');
expect(spanToJSON(transaction).parent_span_id).toEqual('1121201211212012');
expect(spanIsSampled(transaction)).toEqual(true);
// eslint-disable-next-line deprecation/deprecation
expect(transaction.metadata?.dynamicSamplingContext).toStrictEqual({ version: '1.0', environment: 'production' });
});

Expand All @@ -341,7 +343,8 @@ describe('tracingHandler', () => {

expect(getPropagationContext().dsc).toEqual({ version: '1.0', environment: 'production' });

const transaction = (res as any).__sentry_transaction;
const transaction = (res as any).__sentry_transaction as Transaction;
// eslint-disable-next-line deprecation/deprecation
expect(transaction.metadata?.dynamicSamplingContext).toStrictEqual({ version: '1.0', environment: 'production' });
});

Expand All @@ -364,7 +367,7 @@ describe('tracingHandler', () => {
it('puts its transaction on the response object', () => {
sentryTracingMiddleware(req, res, next);

const transaction = (res as any).__sentry_transaction;
const transaction = (res as any).__sentry_transaction as Transaction;

expect(transaction).toBeDefined();

Expand Down Expand Up @@ -396,7 +399,7 @@ describe('tracingHandler', () => {

sentryTracingMiddleware(req, res, next);

const transaction = (res as any).__sentry_transaction;
const transaction = (res as any).__sentry_transaction as Transaction;

expect(spanToJSON(transaction).description).toBe(`${method.toUpperCase()} ${path}`);
});
Expand All @@ -406,7 +409,7 @@ describe('tracingHandler', () => {

sentryTracingMiddleware(req, res, next);

const transaction = (res as any).__sentry_transaction;
const transaction = (res as any).__sentry_transaction as Transaction;

expect(spanToJSON(transaction).description).toBe(`${method.toUpperCase()} ${path}`);
});
Expand All @@ -416,7 +419,7 @@ describe('tracingHandler', () => {

sentryTracingMiddleware(req, res, next);

const transaction = (res as any).__sentry_transaction;
const transaction = (res as any).__sentry_transaction as Transaction;

expect(spanToJSON(transaction).description).toBe(`${method.toUpperCase()} ${path}`);
});
Expand Down

0 comments on commit 886513a

Please sign in to comment.