|
7 | 7 | withIsolationScope,
|
8 | 8 | withScope,
|
9 | 9 | } from '@sentry/core';
|
| 10 | +import { describe, beforeEach, afterEach, afterAll, test, expect, it } from 'vitest'; |
10 | 11 |
|
11 | 12 | import type { Scope } from '@sentry/core';
|
12 | 13 | import { setOpenTelemetryContextAsyncContextStrategy } from '../src/asyncContextStrategy';
|
@@ -301,130 +302,142 @@ describe('asyncContextStrategy', () => {
|
301 | 302 | });
|
302 | 303 |
|
303 | 304 | describe('withScope()', () => {
|
304 |
| - it('will make the passed scope the active scope within the callback', done => { |
305 |
| - withScope(scope => { |
306 |
| - expect(getCurrentScope()).toBe(scope); |
307 |
| - done(); |
308 |
| - }); |
309 |
| - }); |
310 |
| - |
311 |
| - it('will pass a scope that is different from the current active isolation scope', done => { |
312 |
| - withScope(scope => { |
313 |
| - expect(getIsolationScope()).not.toBe(scope); |
314 |
| - done(); |
315 |
| - }); |
316 |
| - }); |
317 |
| - |
318 |
| - it('will always make the inner most passed scope the current scope when nesting calls', done => { |
319 |
| - withIsolationScope(_scope1 => { |
320 |
| - withIsolationScope(scope2 => { |
321 |
| - expect(getIsolationScope()).toBe(scope2); |
| 305 | + it('will make the passed scope the active scope within the callback', () => |
| 306 | + new Promise<void>(done => { |
| 307 | + withScope(scope => { |
| 308 | + expect(getCurrentScope()).toBe(scope); |
322 | 309 | done();
|
323 | 310 | });
|
324 |
| - }); |
325 |
| - }); |
326 |
| - |
327 |
| - it('forks the scope when not passing any scope', done => { |
328 |
| - const initialScope = getCurrentScope(); |
329 |
| - initialScope.setTag('aa', 'aa'); |
330 |
| - |
331 |
| - withScope(scope => { |
332 |
| - expect(getCurrentScope()).toBe(scope); |
333 |
| - scope.setTag('bb', 'bb'); |
334 |
| - expect(scope).not.toBe(initialScope); |
335 |
| - expect(scope.getScopeData().tags).toEqual({ aa: 'aa', bb: 'bb' }); |
336 |
| - done(); |
337 |
| - }); |
338 |
| - }); |
339 |
| - |
340 |
| - it('forks the scope when passing undefined', done => { |
341 |
| - const initialScope = getCurrentScope(); |
342 |
| - initialScope.setTag('aa', 'aa'); |
| 311 | + })); |
343 | 312 |
|
344 |
| - withScope(undefined, scope => { |
345 |
| - expect(getCurrentScope()).toBe(scope); |
346 |
| - scope.setTag('bb', 'bb'); |
347 |
| - expect(scope).not.toBe(initialScope); |
348 |
| - expect(scope.getScopeData().tags).toEqual({ aa: 'aa', bb: 'bb' }); |
349 |
| - done(); |
350 |
| - }); |
351 |
| - }); |
| 313 | + it('will pass a scope that is different from the current active isolation scope', () => |
| 314 | + new Promise<void>(done => { |
| 315 | + withScope(scope => { |
| 316 | + expect(getIsolationScope()).not.toBe(scope); |
| 317 | + done(); |
| 318 | + }); |
| 319 | + })); |
| 320 | + |
| 321 | + it('will always make the inner most passed scope the current scope when nesting calls', () => |
| 322 | + new Promise<void>(done => { |
| 323 | + withIsolationScope(_scope1 => { |
| 324 | + withIsolationScope(scope2 => { |
| 325 | + expect(getIsolationScope()).toBe(scope2); |
| 326 | + done(); |
| 327 | + }); |
| 328 | + }); |
| 329 | + })); |
| 330 | + |
| 331 | + it('forks the scope when not passing any scope', () => |
| 332 | + new Promise<void>(done => { |
| 333 | + const initialScope = getCurrentScope(); |
| 334 | + initialScope.setTag('aa', 'aa'); |
| 335 | + |
| 336 | + withScope(scope => { |
| 337 | + expect(getCurrentScope()).toBe(scope); |
| 338 | + scope.setTag('bb', 'bb'); |
| 339 | + expect(scope).not.toBe(initialScope); |
| 340 | + expect(scope.getScopeData().tags).toEqual({ aa: 'aa', bb: 'bb' }); |
| 341 | + done(); |
| 342 | + }); |
| 343 | + })); |
| 344 | + |
| 345 | + it('forks the scope when passing undefined', () => |
| 346 | + new Promise<void>(done => { |
| 347 | + const initialScope = getCurrentScope(); |
| 348 | + initialScope.setTag('aa', 'aa'); |
| 349 | + |
| 350 | + withScope(undefined, scope => { |
| 351 | + expect(getCurrentScope()).toBe(scope); |
| 352 | + scope.setTag('bb', 'bb'); |
| 353 | + expect(scope).not.toBe(initialScope); |
| 354 | + expect(scope.getScopeData().tags).toEqual({ aa: 'aa', bb: 'bb' }); |
| 355 | + done(); |
| 356 | + }); |
| 357 | + })); |
352 | 358 |
|
353 |
| - it('sets the passed in scope as active scope', done => { |
354 |
| - const initialScope = getCurrentScope(); |
355 |
| - initialScope.setTag('aa', 'aa'); |
| 359 | + it('sets the passed in scope as active scope', () => |
| 360 | + new Promise<void>(done => { |
| 361 | + const initialScope = getCurrentScope(); |
| 362 | + initialScope.setTag('aa', 'aa'); |
356 | 363 |
|
357 |
| - const customScope = new ScopeClass(); |
| 364 | + const customScope = new ScopeClass(); |
358 | 365 |
|
359 |
| - withScope(customScope, scope => { |
360 |
| - expect(getCurrentScope()).toBe(customScope); |
361 |
| - expect(scope).toBe(customScope); |
362 |
| - done(); |
363 |
| - }); |
364 |
| - }); |
| 366 | + withScope(customScope, scope => { |
| 367 | + expect(getCurrentScope()).toBe(customScope); |
| 368 | + expect(scope).toBe(customScope); |
| 369 | + done(); |
| 370 | + }); |
| 371 | + })); |
365 | 372 | });
|
366 | 373 |
|
367 | 374 | describe('withIsolationScope()', () => {
|
368 |
| - it('will make the passed isolation scope the active isolation scope within the callback', done => { |
369 |
| - withIsolationScope(scope => { |
370 |
| - expect(getIsolationScope()).toBe(scope); |
371 |
| - done(); |
372 |
| - }); |
373 |
| - }); |
374 |
| - |
375 |
| - it('will pass an isolation scope that is different from the current active scope', done => { |
376 |
| - withIsolationScope(scope => { |
377 |
| - expect(getCurrentScope()).not.toBe(scope); |
378 |
| - done(); |
379 |
| - }); |
380 |
| - }); |
381 |
| - |
382 |
| - it('will always make the inner most passed scope the current scope when nesting calls', done => { |
383 |
| - withIsolationScope(_scope1 => { |
384 |
| - withIsolationScope(scope2 => { |
385 |
| - expect(getIsolationScope()).toBe(scope2); |
| 375 | + it('will make the passed isolation scope the active isolation scope within the callback', () => |
| 376 | + new Promise<void>(done => { |
| 377 | + withIsolationScope(scope => { |
| 378 | + expect(getIsolationScope()).toBe(scope); |
386 | 379 | done();
|
387 | 380 | });
|
388 |
| - }); |
389 |
| - }); |
390 |
| - |
391 |
| - it('forks the isolation scope when not passing any isolation scope', done => { |
392 |
| - const initialScope = getIsolationScope(); |
393 |
| - initialScope.setTag('aa', 'aa'); |
394 |
| - |
395 |
| - withIsolationScope(scope => { |
396 |
| - expect(getIsolationScope()).toBe(scope); |
397 |
| - scope.setTag('bb', 'bb'); |
398 |
| - expect(scope).not.toBe(initialScope); |
399 |
| - expect(scope.getScopeData().tags).toEqual({ aa: 'aa', bb: 'bb' }); |
400 |
| - done(); |
401 |
| - }); |
402 |
| - }); |
403 |
| - |
404 |
| - it('forks the isolation scope when passing undefined', done => { |
405 |
| - const initialScope = getIsolationScope(); |
406 |
| - initialScope.setTag('aa', 'aa'); |
| 381 | + })); |
407 | 382 |
|
408 |
| - withIsolationScope(undefined, scope => { |
409 |
| - expect(getIsolationScope()).toBe(scope); |
410 |
| - scope.setTag('bb', 'bb'); |
411 |
| - expect(scope).not.toBe(initialScope); |
412 |
| - expect(scope.getScopeData().tags).toEqual({ aa: 'aa', bb: 'bb' }); |
413 |
| - done(); |
414 |
| - }); |
415 |
| - }); |
| 383 | + it('will pass an isolation scope that is different from the current active scope', () => |
| 384 | + new Promise<void>(done => { |
| 385 | + withIsolationScope(scope => { |
| 386 | + expect(getCurrentScope()).not.toBe(scope); |
| 387 | + done(); |
| 388 | + }); |
| 389 | + })); |
| 390 | + |
| 391 | + it('will always make the inner most passed scope the current scope when nesting calls', () => |
| 392 | + new Promise<void>(done => { |
| 393 | + withIsolationScope(_scope1 => { |
| 394 | + withIsolationScope(scope2 => { |
| 395 | + expect(getIsolationScope()).toBe(scope2); |
| 396 | + done(); |
| 397 | + }); |
| 398 | + }); |
| 399 | + })); |
| 400 | + |
| 401 | + it('forks the isolation scope when not passing any isolation scope', () => |
| 402 | + new Promise<void>(done => { |
| 403 | + const initialScope = getIsolationScope(); |
| 404 | + initialScope.setTag('aa', 'aa'); |
| 405 | + |
| 406 | + withIsolationScope(scope => { |
| 407 | + expect(getIsolationScope()).toBe(scope); |
| 408 | + scope.setTag('bb', 'bb'); |
| 409 | + expect(scope).not.toBe(initialScope); |
| 410 | + expect(scope.getScopeData().tags).toEqual({ aa: 'aa', bb: 'bb' }); |
| 411 | + done(); |
| 412 | + }); |
| 413 | + })); |
| 414 | + |
| 415 | + it('forks the isolation scope when passing undefined', () => |
| 416 | + new Promise<void>(done => { |
| 417 | + const initialScope = getIsolationScope(); |
| 418 | + initialScope.setTag('aa', 'aa'); |
| 419 | + |
| 420 | + withIsolationScope(undefined, scope => { |
| 421 | + expect(getIsolationScope()).toBe(scope); |
| 422 | + scope.setTag('bb', 'bb'); |
| 423 | + expect(scope).not.toBe(initialScope); |
| 424 | + expect(scope.getScopeData().tags).toEqual({ aa: 'aa', bb: 'bb' }); |
| 425 | + done(); |
| 426 | + }); |
| 427 | + })); |
416 | 428 |
|
417 |
| - it('sets the passed in isolation scope as active isolation scope', done => { |
418 |
| - const initialScope = getIsolationScope(); |
419 |
| - initialScope.setTag('aa', 'aa'); |
| 429 | + it('sets the passed in isolation scope as active isolation scope', () => |
| 430 | + new Promise<void>(done => { |
| 431 | + const initialScope = getIsolationScope(); |
| 432 | + initialScope.setTag('aa', 'aa'); |
420 | 433 |
|
421 |
| - const customScope = new ScopeClass(); |
| 434 | + const customScope = new ScopeClass(); |
422 | 435 |
|
423 |
| - withIsolationScope(customScope, scope => { |
424 |
| - expect(getIsolationScope()).toBe(customScope); |
425 |
| - expect(scope).toBe(customScope); |
426 |
| - done(); |
427 |
| - }); |
428 |
| - }); |
| 436 | + withIsolationScope(customScope, scope => { |
| 437 | + expect(getIsolationScope()).toBe(customScope); |
| 438 | + expect(scope).toBe(customScope); |
| 439 | + done(); |
| 440 | + }); |
| 441 | + })); |
429 | 442 | });
|
430 | 443 | });
|
0 commit comments