Skip to content

Commit 166a8b0

Browse files
committed
fix test
1 parent a3c2d7e commit 166a8b0

File tree

2 files changed

+43
-43
lines changed

2 files changed

+43
-43
lines changed

packages/sveltekit/test/server/handle.test.ts

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, addTracingExtensions, spanToJSON } from '@sentry/core';
1+
import { SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, addTracingExtensions, spanIsSampled, spanToJSON } from '@sentry/core';
2+
import type { Transaction as TransactionClass } from '@sentry/core';
23
import { NodeClient, setCurrentClient } from '@sentry/node-experimental';
34
import * as SentryNode from '@sentry/node-experimental';
4-
import type { Transaction } from '@sentry/types';
5+
import type { Span, Transaction } from '@sentry/types';
56
import type { Handle } from '@sveltejs/kit';
67
import { redirect } from '@sveltejs/kit';
78
import { vi } from 'vitest';
@@ -117,9 +118,9 @@ describe('handleSentry', () => {
117118
});
118119

119120
it("creates a transaction if there's no active span", async () => {
120-
let ref: any = undefined;
121+
let _span: Span | undefined = undefined;
121122
client.on('finishTransaction', (transaction: Transaction) => {
122-
ref = transaction;
123+
_span = transaction;
123124
});
124125

125126
try {
@@ -128,22 +129,25 @@ describe('handleSentry', () => {
128129
//
129130
}
130131

131-
expect(ref).toBeDefined();
132+
expect(_span!).toBeDefined();
132133

133-
expect(spanToJSON(ref).description).toEqual('GET /users/[id]');
134-
expect(spanToJSON(ref).op).toEqual('http.server');
135-
expect(ref.status).toEqual(isError ? 'internal_error' : 'ok');
136-
expect(ref.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route');
134+
expect(spanToJSON(_span!).description).toEqual('GET /users/[id]');
135+
expect(spanToJSON(_span!).op).toEqual('http.server');
136+
expect(spanToJSON(_span!).status).toEqual(isError ? 'internal_error' : 'ok');
137+
expect(spanToJSON(_span!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route');
137138

138-
expect(ref.endTimestamp).toBeDefined();
139-
expect(ref.spanRecorder.spans).toHaveLength(1);
139+
expect(spanToJSON(_span!).timestamp).toBeDefined();
140+
141+
// eslint-disable-next-line deprecation/deprecation
142+
const spans = (_span! as TransactionClass).spanRecorder?.spans;
143+
expect(spans).toHaveLength(1);
140144
});
141145

142146
it('creates a child span for nested server calls (i.e. if there is an active span)', async () => {
143-
let ref: any = undefined;
147+
let _span: Span | undefined = undefined;
144148
let txnCount = 0;
145149
client.on('finishTransaction', (transaction: Transaction) => {
146-
ref = transaction;
150+
_span = transaction;
147151
++txnCount;
148152
});
149153

@@ -164,17 +168,19 @@ describe('handleSentry', () => {
164168
}
165169

166170
expect(txnCount).toEqual(1);
167-
expect(ref).toBeDefined();
171+
expect(_span!).toBeDefined();
172+
173+
expect(spanToJSON(_span!).description).toEqual('GET /users/[id]');
174+
expect(spanToJSON(_span!).op).toEqual('http.server');
175+
expect(spanToJSON(_span!).status).toEqual(isError ? 'internal_error' : 'ok');
176+
expect(spanToJSON(_span!).data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route');
168177

169-
expect(spanToJSON(ref).description).toEqual('GET /users/[id]');
170-
expect(spanToJSON(ref).op).toEqual('http.server');
171-
expect(ref.status).toEqual(isError ? 'internal_error' : 'ok');
172-
expect(ref.attributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]).toEqual('route');
178+
expect(spanToJSON(_span!).timestamp).toBeDefined();
173179

174-
expect(ref.endTimestamp).toBeDefined();
180+
// eslint-disable-next-line deprecation/deprecation
181+
const spans = (_span! as TransactionClass).spanRecorder?.spans?.map(spanToJSON);
175182

176-
expect(ref.spanRecorder.spans).toHaveLength(2);
177-
const spans = ref.spanRecorder.spans.map(spanToJSON);
183+
expect(spans).toHaveLength(2);
178184
expect(spans).toEqual(
179185
expect.arrayContaining([
180186
expect.objectContaining({ op: 'http.server', description: 'GET /users/[id]' }),
@@ -198,9 +204,9 @@ describe('handleSentry', () => {
198204
},
199205
});
200206

201-
let ref: any = undefined;
207+
let _span: Span | undefined = undefined;
202208
client.on('finishTransaction', (transaction: Transaction) => {
203-
ref = transaction;
209+
_span = transaction;
204210
});
205211

206212
try {
@@ -209,10 +215,10 @@ describe('handleSentry', () => {
209215
//
210216
}
211217

212-
expect(ref).toBeDefined();
213-
expect(ref.traceId).toEqual('1234567890abcdef1234567890abcdef');
214-
expect(ref.parentSpanId).toEqual('1234567890abcdef');
215-
expect(ref.sampled).toEqual(true);
218+
expect(_span!).toBeDefined();
219+
expect(_span!.spanContext().traceId).toEqual('1234567890abcdef1234567890abcdef');
220+
expect(spanToJSON(_span!).parent_span_id).toEqual('1234567890abcdef');
221+
expect(spanIsSampled(_span!)).toEqual(true);
216222
});
217223

218224
it('creates a transaction with dynamic sampling context from baggage header', async () => {
@@ -238,9 +244,9 @@ describe('handleSentry', () => {
238244
},
239245
});
240246

241-
let ref: any = undefined;
247+
let _span: Span | undefined = undefined;
242248
client.on('finishTransaction', (transaction: Transaction) => {
243-
ref = transaction;
249+
_span = transaction;
244250
});
245251

246252
try {
@@ -249,8 +255,8 @@ describe('handleSentry', () => {
249255
//
250256
}
251257

252-
expect(ref).toBeDefined();
253-
expect(ref.metadata.dynamicSamplingContext).toEqual({
258+
expect(_span!).toBeDefined();
259+
expect(_span.metadata.dynamicSamplingContext).toEqual({
254260
environment: 'production',
255261
release: '1.0.0',
256262
public_key: 'dogsarebadatkeepingsecrets',
@@ -302,9 +308,9 @@ describe('handleSentry', () => {
302308
});
303309

304310
it("doesn't create a transaction if there's no route", async () => {
305-
let ref: any = undefined;
311+
let _span: Span | undefined = undefined;
306312
client.on('finishTransaction', (transaction: Transaction) => {
307-
ref = transaction;
313+
_span = transaction;
308314
});
309315

310316
try {
@@ -313,13 +319,13 @@ describe('handleSentry', () => {
313319
//
314320
}
315321

316-
expect(ref).toBeUndefined();
322+
expect(_span!).toBeUndefined();
317323
});
318324

319325
it("Creates a transaction if there's no route but `handleUnknownRequests` is true", async () => {
320-
let ref: any = undefined;
326+
let _span: Span | undefined = undefined;
321327
client.on('finishTransaction', (transaction: Transaction) => {
322-
ref = transaction;
328+
_span = transaction;
323329
});
324330

325331
try {
@@ -331,7 +337,7 @@ describe('handleSentry', () => {
331337
//
332338
}
333339

334-
expect(ref).toBeDefined();
340+
expect(_span!).toBeDefined();
335341
});
336342
});
337343
});

packages/sveltekit/test/server/load.test.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ describe('wrapLoadWithSentry calls trace', () => {
203203
},
204204
op: 'function.sveltekit.load',
205205
name: '/users/[id]',
206-
status: 'ok',
207206
},
208207
expect.any(Function),
209208
);
@@ -222,7 +221,6 @@ describe('wrapLoadWithSentry calls trace', () => {
222221
},
223222
op: 'function.sveltekit.load',
224223
name: '/users/123',
225-
status: 'ok',
226224
},
227225
expect.any(Function),
228226
);
@@ -258,7 +256,6 @@ describe('wrapServerLoadWithSentry calls trace', () => {
258256
name: '/users/[id]',
259257
parentSampled: true,
260258
parentSpanId: '1234567890abcdef',
261-
status: 'ok',
262259
traceId: '1234567890abcdef1234567890abcdef',
263260
data: {
264261
'http.method': 'GET',
@@ -291,7 +288,6 @@ describe('wrapServerLoadWithSentry calls trace', () => {
291288
},
292289
op: 'function.sveltekit.server.load',
293290
name: '/users/[id]',
294-
status: 'ok',
295291
metadata: {},
296292
data: {
297293
'http.method': 'GET',
@@ -316,7 +312,6 @@ describe('wrapServerLoadWithSentry calls trace', () => {
316312
name: '/users/[id]',
317313
parentSampled: true,
318314
parentSpanId: '1234567890abcdef',
319-
status: 'ok',
320315
traceId: '1234567890abcdef1234567890abcdef',
321316
data: {
322317
'http.method': 'GET',
@@ -347,7 +342,6 @@ describe('wrapServerLoadWithSentry calls trace', () => {
347342
name: '/users/123',
348343
parentSampled: true,
349344
parentSpanId: '1234567890abcdef',
350-
status: 'ok',
351345
traceId: '1234567890abcdef1234567890abcdef',
352346
data: {
353347
'http.method': 'GET',

0 commit comments

Comments
 (0)