Skip to content

Commit 1cd1a52

Browse files
committed
fix tests
1 parent f880d78 commit 1cd1a52

File tree

2 files changed

+52
-39
lines changed

2 files changed

+52
-39
lines changed

dev-packages/e2e-tests/test-applications/angular-17/tests/performance.test.ts

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { expect, test } from '@playwright/test';
2-
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/browser';
3-
import { SEMANTIC_ATTRIBUTE_SENTRY_OP } from '@sentry/core/src';
2+
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/core';
43
import { waitForTransaction } from '../event-proxy-server';
54

65
test('sends a pageload transaction with a parameterized URL', async ({ page }) => {
@@ -169,14 +168,16 @@ test.describe('finish routing span', () => {
169168
// immediately navigate to a different route
170169
const [_, navigationTxn] = await Promise.all([page.locator('#nonExistentLink').click(), navigationTxnPromise]);
171170

171+
const nonExistentRoute = '/non-existent';
172+
172173
expect(navigationTxn).toMatchObject({
173174
contexts: {
174175
trace: {
175176
op: 'navigation',
176177
origin: 'auto.navigation.angular',
177178
},
178179
},
179-
transaction: '/non-existent',
180+
transaction: nonExistentRoute,
180181
transaction_info: {
181182
source: 'url',
182183
},
@@ -185,7 +186,7 @@ test.describe('finish routing span', () => {
185186
const routingSpan = navigationTxn.spans?.find(span => span.op === 'ui.angular.routing');
186187

187188
expect(routingSpan).toBeDefined();
188-
expect(routingSpan?.description).toBe('/nonExistentLink');
189+
expect(routingSpan?.description).toBe(nonExistentRoute);
189190
});
190191
});
191192

@@ -200,25 +201,25 @@ test.describe('TraceDirective', () => {
200201
// immediately navigate to a different route
201202
const [_, navigationTxn] = await Promise.all([page.locator('#componentTracking').click(), navigationTxnPromise]);
202203

203-
const traceDirectiveSpan = navigationTxn.spans?.find(span => span.op === 'ui.angular.init');
204+
const traceDirectiveSpan = navigationTxn.spans?.find(
205+
span => span?.data && span?.data[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] === 'auto.ui.angular.trace_directive',
206+
);
204207

205208
expect(traceDirectiveSpan).toBeDefined();
206209
expect(traceDirectiveSpan).toEqual(
207210
expect.objectContaining({
208-
description: '<sample-component>',
209-
attributes: {
211+
data: {
210212
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.angular.init',
211213
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_directive',
212214
},
215+
description: '<sample-component>',
213216
op: 'ui.angular.init',
214217
origin: 'auto.ui.angular.trace_directive',
218+
start_timestamp: expect.any(Number),
219+
timestamp: expect.any(Number),
215220
}),
216221
);
217222
});
218-
219-
test('finishes tracingSpan after ngAfterViewInit', () => {
220-
// todo
221-
});
222223
});
223224

224225
test.describe('TraceClassDecorator', () => {
@@ -232,9 +233,25 @@ test.describe('TraceClassDecorator', () => {
232233
// immediately navigate to a different route
233234
const [_, navigationTxn] = await Promise.all([page.locator('#componentTracking').click(), navigationTxnPromise]);
234235

235-
const initSpan = navigationTxn.spans?.find(span => span.op === 'ui.angular.init');
236+
const classDecoratorSpan = navigationTxn.spans?.find(
237+
span => span?.data && span?.data[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN] === 'auto.ui.angular.trace_class_decorator',
238+
);
236239

237-
expect(initSpan).toBeDefined();
240+
expect(classDecoratorSpan).toBeDefined();
241+
expect(classDecoratorSpan).toEqual(
242+
expect.objectContaining({
243+
data: {
244+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.angular.init',
245+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_class_decorator',
246+
},
247+
// todo: right now, it shows the minified version of the component name - we will add a name input to the Decorator
248+
description: expect.any(String),
249+
op: 'ui.angular.init',
250+
origin: 'auto.ui.angular.trace_class_decorator',
251+
start_timestamp: expect.any(Number),
252+
timestamp: expect.any(Number),
253+
}),
254+
);
238255
});
239256
});
240257

@@ -255,26 +272,32 @@ test.describe('TraceMethodDecorator', () => {
255272
expect(ngInitSpan).toBeDefined();
256273
expect(ngInitSpan).toEqual(
257274
expect.objectContaining({
258-
description: '<ComponentTrackingComponent>',
259-
op: 'ui.angular.ngOnInit',
260-
attributes: {
275+
data: {
261276
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.angular.ngOnInit',
262-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_class_decorator',
277+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_method_decorator',
263278
},
279+
// todo: right now, it shows the minified version of the component name - we will add a name input to the Decorator
280+
description: expect.any(String),
281+
op: 'ui.angular.ngOnInit',
282+
origin: 'auto.ui.angular.trace_method_decorator',
283+
start_timestamp: expect.any(Number),
284+
timestamp: expect.any(Number),
264285
}),
265286
);
266287

267288
expect(ngAfterViewInitSpan).toBeDefined();
268289
expect(ngAfterViewInitSpan).toEqual(
269290
expect.objectContaining({
270-
description: '<ComponentTrackingComponent>',
271-
op: 'ui.angular.ngAfterViewInit',
272-
attributes: {
273-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.angular.ngOnInit',
291+
data: {
292+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'ui.angular.ngAfterViewInit',
274293
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.angular.trace_method_decorator',
275294
},
276-
startTimestamp: expect.any(Number),
277-
endTimestamp: expect.any(Number),
295+
// todo: right now, it shows the minified version of the component name - we will add a name input to the Decorator
296+
description: expect.any(String),
297+
op: 'ui.angular.ngAfterViewInit',
298+
origin: 'auto.ui.angular.trace_method_decorator',
299+
start_timestamp: expect.any(Number),
300+
timestamp: expect.any(Number),
278301
}),
279302
);
280303
});

packages/angular/test/tracing.test.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { ActivatedRouteSnapshot } from '@angular/router';
2-
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, SentrySpan, spanToJSON } from '@sentry/core';
3-
4-
import { SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '@sentry/browser';
2+
import {
3+
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
4+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
5+
SentrySpan,
6+
spanToJSON,
7+
} from '@sentry/core';
58
import { TraceDirective, browserTracingIntegration, init } from '../src/index';
69
import { _updateSpanAttributesForParametrizedUrl, getParameterizedRouteFromSnapshot } from '../src/tracing';
710

@@ -25,8 +28,6 @@ describe('browserTracingIntegration', () => {
2528
it('implements required hooks', () => {
2629
const integration = browserTracingIntegration();
2730
expect(integration.name).toEqual('BrowserTracing');
28-
expect(integration.setupOnce).toBeDefined();
29-
expect(integration.afterAllSetup).toBeDefined();
3031
});
3132
});
3233

@@ -127,17 +128,6 @@ describe('Angular Tracing', () => {
127128
}),
128129
);
129130
});
130-
131-
it('should contain the keys "test1" and "test2"', () => {
132-
const obj = { test1: 'value1', test2: 'value2', otherKey: 'otherValue', ll: { sdf: 'sdfsd' } };
133-
134-
expect(obj).toEqual(
135-
expect.objectContaining({
136-
test1: 'value1',
137-
ll: { sdf: 'sdfsd' },
138-
}),
139-
);
140-
});
141131
});
142132

143133
describe('TraceDirective', () => {

0 commit comments

Comments
 (0)