@@ -19,89 +19,88 @@ const shouldSkipCommand = (command) => {
1919 return command . attributes . name == 'log' || ( command . attributes . name == 'task' && ( [ 'test_observability_platform_details' , 'test_observability_step' , 'test_observability_command' , 'browserstack_log' , 'test_observability_log' ] . some ( event => command . attributes . args . includes ( event ) ) ) ) ;
2020}
2121
22- if ( parseInt ( Cypress . version . split ( '.' ) [ 0 ] , 10 ) >= 13 ) {
23- Cypress . on ( 'log:changed' , ( attrs ) => {
24- if ( ! Cypress . env ( 'BROWSERSTACK_O11Y_LOGS' ) ) return ;
25- if ( ! attrs ) return ;
26- if ( attrs . state !== 'passed' && attrs . state !== 'failed' ) return ;
22+ Cypress . on ( 'log:changed' , ( attrs ) => {
23+ if ( ! Cypress . env ( 'BROWSERSTACK_O11Y_LOGS' ) ) return ;
24+ if ( ! attrs ) return ;
25+ if ( ! attrs . createdAtTimestamp || ! attrs . updatedAtTimestamp ) return ;
26+ if ( attrs . state !== 'passed' && attrs . state !== 'failed' ) return ;
2727
28- if ( attrs . name === 'assert' ) {
29- const assertMessage = ( attrs . message || '' )
28+ if ( attrs . name === 'assert' ) {
29+ const assertMessage = ( attrs . message || '' )
3030
31- eventsQueue . push ( {
32- task : 'test_observability_command' ,
33- data : {
34- type : 'COMMAND_START' ,
35- command : {
36- attributes : {
37- id : attrs . id ,
38- name : 'assert' ,
39- args : [ assertMessage ]
40- } ,
41- state : 'pending' ,
42- started_at : new Date ( attrs . createdAtTimestamp ) . toISOString ( ) ,
43- location : testRunStarted ? 'test' : 'hook'
44- }
45- } ,
46- options : { log : false }
47- } ) ;
31+ eventsQueue . push ( {
32+ task : 'test_observability_command' ,
33+ data : {
34+ type : 'COMMAND_START' ,
35+ command : {
36+ attributes : {
37+ id : attrs . id ,
38+ name : 'assert' ,
39+ args : [ assertMessage ]
40+ } ,
41+ state : 'pending' ,
42+ started_at : new Date ( attrs . createdAtTimestamp ) . toISOString ( ) ,
43+ location : testRunStarted ? 'test' : 'hook'
44+ }
45+ } ,
46+ options : { log : false }
47+ } ) ;
4848
49- eventsQueue . push ( {
50- task : 'test_observability_command' ,
51- data : {
52- type : 'COMMAND_END' ,
53- command : {
54- attributes : {
55- id : attrs . id ,
56- name : 'assert' ,
57- args : [ assertMessage ]
58- } ,
59- state : attrs . state ,
60- finished_at : new Date ( attrs . updatedAtTimestamp ) . toISOString ( ) ,
61- location : testRunStarted ? 'test' : 'hook'
62- }
63- } ,
64- options : { log : false }
65- } ) ;
66- }
49+ eventsQueue . push ( {
50+ task : 'test_observability_command' ,
51+ data : {
52+ type : 'COMMAND_END' ,
53+ command : {
54+ attributes : {
55+ id : attrs . id ,
56+ name : 'assert' ,
57+ args : [ assertMessage ]
58+ } ,
59+ state : attrs . state ,
60+ finished_at : new Date ( attrs . updatedAtTimestamp ) . toISOString ( ) ,
61+ location : testRunStarted ? 'test' : 'hook'
62+ }
63+ } ,
64+ options : { log : false }
65+ } ) ;
66+ }
67+
68+ const keyword = ( attrs . name || '' ) . trim ( ) ;
69+ if ( STEP_KEYWORDS . includes ( keyword . toLowerCase ( ) ) ) {
70+ const text = ( attrs . message || '' )
6771
68- const keyword = ( attrs . name || '' ) . trim ( ) ;
69- if ( STEP_KEYWORDS . includes ( keyword . toLowerCase ( ) ) ) {
70- const text = ( attrs . message || '' )
72+ eventsQueue . push ( {
73+ task : 'test_observability_step' ,
74+ data : {
75+ log : {
76+ name : 'step' ,
77+ chainerId : attrs . chainerId ,
78+ consoleProps : { step : { keyword, text } }
79+ } ,
80+ started_at : new Date ( attrs . createdAtTimestamp ) . toISOString ( ) ,
81+ finished_at : new Date ( attrs . updatedAtTimestamp ) . toISOString ( )
82+ } ,
83+ options : { log : false }
84+ } ) ;
7185
86+ if ( attrs . state === 'failed' ) {
7287 eventsQueue . push ( {
7388 task : 'test_observability_step' ,
7489 data : {
7590 log : {
76- name : 'step' ,
91+ name : 'then' ,
92+ type : 'child' ,
7793 chainerId : attrs . chainerId ,
78- consoleProps : { step : { keyword, text } }
94+ state : attrs . state ,
95+ err : attrs . err
7996 } ,
80- started_at : new Date ( attrs . createdAtTimestamp ) . toISOString ( ) ,
8197 finished_at : new Date ( attrs . updatedAtTimestamp ) . toISOString ( )
8298 } ,
8399 options : { log : false }
84100 } ) ;
85-
86- if ( attrs . state === 'failed' ) {
87- eventsQueue . push ( {
88- task : 'test_observability_step' ,
89- data : {
90- log : {
91- name : 'then' ,
92- type : 'child' ,
93- chainerId : attrs . chainerId ,
94- state : attrs . state ,
95- err : attrs . err
96- } ,
97- finished_at : new Date ( attrs . updatedAtTimestamp ) . toISOString ( )
98- } ,
99- options : { log : false }
100- } ) ;
101- }
102101 }
103- } ) ;
104- }
102+ }
103+ } ) ;
105104
106105Cypress . on ( 'command:start' , ( command ) => {
107106
0 commit comments