@@ -2,11 +2,15 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
22import { getCurrentScope } from '../../../src/currentScopes' ;
33import { debug } from '../../../src/utils/debug-logger' ;
44import {
5+ _INTERNAL_copyFlagsFromScopeToEvent ,
56 _INTERNAL_insertFlagToScope ,
67 _INTERNAL_insertToFlagBuffer ,
78 type FeatureFlag ,
89} from '../../../src/utils/featureFlags' ;
910
11+ import * as currentScopeModule from '../../../src/currentScopes' ;
12+ import type { Event } from '../../../src/types-hoist/event' ;
13+
1014describe ( 'flags' , ( ) => {
1115 describe ( 'insertFlagToScope()' , ( ) => {
1216 it ( 'adds flags to the current scope context' , ( ) => {
@@ -109,4 +113,59 @@ describe('flags', () => {
109113 ] ) ;
110114 } ) ;
111115 } ) ;
116+
117+ describe ( 'copyFlagsFromScopeToEvent()' , ( ) => {
118+ it . each ( [ 'transaction' , 'replay_event' , 'feedback' , 'profile' ] ) ( 'does not add flags context to %s events' , type => {
119+ vi . spyOn ( currentScopeModule , 'getCurrentScope' ) . mockReturnValue ( {
120+ // @ts -expect-error - only returning partial scope data
121+ getScopeData : ( ) => ( {
122+ contexts : {
123+ flags : { values : [ { flag : 'feat1' , result : true } ] } ,
124+ } ,
125+ } ) ,
126+ } ) ;
127+
128+ const event = {
129+ type : type ,
130+ spans : [ ] ,
131+ } as Event ;
132+
133+ const result = _INTERNAL_copyFlagsFromScopeToEvent ( event ) ;
134+
135+ expect ( result ) . toEqual ( event ) ;
136+ expect ( getCurrentScope ) . not . toHaveBeenCalled ( ) ;
137+ } ) ;
138+
139+ it ( 'adds add flags context to error events' , ( ) => {
140+ vi . spyOn ( currentScopeModule , 'getCurrentScope' ) . mockReturnValue ( {
141+ // @ts -expect-error - only returning partial scope data
142+ getScopeData : ( ) => ( {
143+ contexts : {
144+ flags : {
145+ values : [
146+ { flag : 'feat1' , result : true } ,
147+ { flag : 'feat2' , result : false } ,
148+ ] ,
149+ } ,
150+ } ,
151+ } ) ,
152+ } ) ;
153+
154+ const event : Event = {
155+ exception : {
156+ values : [
157+ {
158+ type : 'Error' ,
159+ value : 'error message' ,
160+ } ,
161+ ] ,
162+ } ,
163+ } ;
164+
165+ const result = _INTERNAL_copyFlagsFromScopeToEvent ( event ) ;
166+
167+ expect ( result ) . toEqual ( event ) ;
168+ expect ( getCurrentScope ) . toHaveBeenCalled ( ) ;
169+ } ) ;
170+ } ) ;
112171} ) ;
0 commit comments