11import { describe , expect , it } from '@effect/vitest' ;
2- import { getClient , getCurrentScope , getIsolationScope , SDK_VERSION } from '@sentry/core' ;
2+ import * as sentryCore from '@sentry/core' ;
3+ import { getClient , getCurrentScope , getIsolationScope , SDK_VERSION , SentrySpan } from '@sentry/core' ;
34import { Effect , Layer , Logger , LogLevel } from 'effect' ;
45import { afterEach , beforeEach , vi } from 'vitest' ;
56import * as sentryClient from '../src/index.client' ;
@@ -41,6 +42,7 @@ describe.each([
4142
4243 afterEach ( ( ) => {
4344 getCurrentScope ( ) . setClient ( undefined ) ;
45+ vi . restoreAllMocks ( ) ;
4446 } ) ;
4547
4648 it ( 'creates a valid Effect layer' , ( ) => {
@@ -91,8 +93,11 @@ describe.each([
9193
9294 it . effect ( 'layer enables tracing when tracer is set' , ( ) =>
9395 Effect . gen ( function * ( ) {
96+ const startInactiveSpanMock = vi . spyOn ( sentryCore , 'startInactiveSpan' ) ;
97+
9498 const result = yield * Effect . withSpan ( 'test-span' ) ( Effect . succeed ( 'traced' ) ) ;
9599 expect ( result ) . toBe ( 'traced' ) ;
100+ expect ( startInactiveSpanMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { name : 'test-span' } ) ) ;
96101 } ) . pipe (
97102 Effect . withTracer ( SentryEffectTracer ) ,
98103 Effect . provide (
@@ -106,11 +111,14 @@ describe.each([
106111
107112 it . effect ( 'layer can be composed with tracer layer' , ( ) =>
108113 Effect . gen ( function * ( ) {
114+ const startInactiveSpanMock = vi . spyOn ( sentryCore , 'startInactiveSpan' ) ;
115+
109116 const result = yield * Effect . succeed ( 42 ) . pipe (
110117 Effect . map ( n => n * 2 ) ,
111118 Effect . withSpan ( 'computation' ) ,
112119 ) ;
113120 expect ( result ) . toBe ( 84 ) ;
121+ expect ( startInactiveSpanMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { name : 'computation' } ) ) ;
114122 } ) . pipe (
115123 Effect . provide (
116124 Layer . mergeAll (
@@ -145,13 +153,16 @@ describe.each([
145153
146154 it . effect ( 'layer can be composed with all Effect features' , ( ) =>
147155 Effect . gen ( function * ( ) {
156+ const startInactiveSpanMock = vi . spyOn ( sentryCore , 'startInactiveSpan' ) ;
157+
148158 yield * Effect . logInfo ( 'starting computation' ) ;
149159 const result = yield * Effect . succeed ( 42 ) . pipe (
150160 Effect . map ( n => n * 2 ) ,
151161 Effect . withSpan ( 'computation' ) ,
152162 ) ;
153163 yield * Effect . logInfo ( 'computation complete' ) ;
154164 expect ( result ) . toBe ( 84 ) ;
165+ expect ( startInactiveSpanMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { name : 'computation' } ) ) ;
155166 } ) . pipe (
156167 Effect . provide (
157168 Layer . mergeAll (
0 commit comments