@@ -9,11 +9,11 @@ describe('Profiler', () => {
99 beforeEach ( ( ) => {
1010 performance . clearMarks ( ) ;
1111 performance . clearMeasures ( ) ;
12+ delete process . env . CP_PROFILING ;
1213
1314 profiler = new Profiler ( {
1415 prefix : 'cp' ,
1516 track : 'test-track' ,
16- color : 'primary' ,
1717 tracks : { } ,
1818 } ) ;
1919 } ) ;
@@ -183,11 +183,78 @@ describe('Profiler', () => {
183183 expect ( marks ) . toHaveLength ( 0 ) ;
184184 } ) ;
185185
186+ it ( 'marker should execute without error when enabled with default color' , ( ) => {
187+ performance . clearMarks ( ) ;
188+
189+ const profilerWithColor = new Profiler ( {
190+ prefix : 'cp' ,
191+ track : 'test-track' ,
192+ color : 'primary' ,
193+ tracks : { } ,
194+ } ) ;
195+ profilerWithColor . setEnabled ( true ) ;
196+
197+ expect ( ( ) => {
198+ profilerWithColor . marker ( 'test-marker-default-color' , {
199+ tooltipText : 'Test marker with default color' ,
200+ } ) ;
201+ } ) . not . toThrow ( ) ;
202+
203+ const marks = performance . getEntriesByType ( 'mark' ) ;
204+ expect ( marks ) . toStrictEqual ( [
205+ expect . objectContaining ( {
206+ name : 'test-marker-default-color' ,
207+ detail : {
208+ devtools : expect . objectContaining ( {
209+ dataType : 'marker' ,
210+ color : 'primary' , // Should use default color
211+ tooltipText : 'Test marker with default color' ,
212+ } ) ,
213+ } ,
214+ } ) ,
215+ ] ) ;
216+ } ) ;
217+
218+ it ( 'marker should execute without error when enabled with no default color' , ( ) => {
219+ const profilerNoColor = new Profiler ( {
220+ prefix : 'cp' ,
221+ track : 'test-track' ,
222+ tracks : { } ,
223+ } ) ;
224+ profilerNoColor . setEnabled ( true ) ;
225+
226+ expect ( ( ) => {
227+ profilerNoColor . marker ( 'test-marker-no-color' , {
228+ color : 'secondary' ,
229+ tooltipText : 'Test marker without default color' ,
230+ properties : [ [ 'key' , 'value' ] ] ,
231+ } ) ;
232+ } ) . not . toThrow ( ) ;
233+
234+ const marks = performance . getEntriesByType ( 'mark' ) ;
235+ expect ( marks ) . toStrictEqual ( [
236+ expect . objectContaining ( {
237+ name : 'test-marker-no-color' ,
238+ detail : {
239+ devtools : expect . objectContaining ( {
240+ dataType : 'marker' ,
241+ color : 'secondary' ,
242+ tooltipText : 'Test marker without default color' ,
243+ properties : [ [ 'key' , 'value' ] ] ,
244+ } ) ,
245+ } ,
246+ } ) ,
247+ ] ) ;
248+ } ) ;
249+
186250 it ( 'measure should execute work and return result when enabled' , ( ) => {
251+ performance . clearMarks ( ) ;
252+ performance . clearMeasures ( ) ;
253+
187254 profiler . setEnabled ( true ) ;
188255
189256 const workFn = vi . fn ( ( ) => 'result' ) ;
190- const result = profiler . measure ( 'test-event' , workFn ) ;
257+ const result = profiler . measure ( 'test-event' , workFn , { color : 'primary' } ) ;
191258
192259 expect ( result ) . toBe ( 'result' ) ;
193260 expect ( workFn ) . toHaveBeenCalled ( ) ;
@@ -203,7 +270,6 @@ describe('Profiler', () => {
203270 devtools : expect . objectContaining ( {
204271 dataType : 'track-entry' ,
205272 track : 'test-track' ,
206- color : 'primary' ,
207273 } ) ,
208274 } ,
209275 } ) ,
@@ -213,7 +279,6 @@ describe('Profiler', () => {
213279 devtools : expect . objectContaining ( {
214280 dataType : 'track-entry' ,
215281 track : 'test-track' ,
216- color : 'primary' ,
217282 } ) ,
218283 } ,
219284 } ) ,
@@ -226,7 +291,6 @@ describe('Profiler', () => {
226291 devtools : expect . objectContaining ( {
227292 dataType : 'track-entry' ,
228293 track : 'test-track' ,
229- color : 'primary' ,
230294 } ) ,
231295 } ,
232296 } ) ,
@@ -280,7 +344,9 @@ describe('Profiler', () => {
280344 return 'async-result' ;
281345 } ) ;
282346
283- const result = await profiler . measureAsync ( 'test-async-event' , workFn ) ;
347+ const result = await profiler . measureAsync ( 'test-async-event' , workFn , {
348+ color : 'primary' ,
349+ } ) ;
284350
285351 expect ( result ) . toBe ( 'async-result' ) ;
286352 expect ( workFn ) . toHaveBeenCalled ( ) ;
0 commit comments