Skip to content

Commit 6d2ac1a

Browse files
Merge pull request #1094 from browserstack/sdk-5709
Fix cy logs not appearing in dashboard for failing test
2 parents 2a3e52d + 56e11ea commit 6d2ac1a

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

bin/testObservability/cypress/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,24 +201,30 @@ Cypress.on('command:end', (command) => {
201201
});
202202
});
203203

204-
Cypress.Commands.overwrite('log', (originalFn, ...args) => {
204+
Cypress.on('command:enqueued', (attrs) => {
205+
if (!Cypress.env('BROWSERSTACK_O11Y_LOGS')) return;
206+
if (!attrs || attrs.name !== 'log') return;
207+
const args = attrs.args || [];
205208
if (args.includes('test_observability_log') || args.includes('test_observability_command')) return;
206209
const message = args.reduce((result, logItem) => {
207210
if (typeof logItem === 'object') {
208211
return [result, JSON.stringify(logItem)].join(' ');
209212
}
210-
211213
return [result, logItem ? logItem.toString() : ''].join(' ');
212214
}, '');
213215
eventsQueue.push({
214216
task: 'test_observability_log',
215217
data: {
216-
'level': 'info',
218+
level: 'info',
217219
message,
218220
timestamp: new Date().toISOString()
219221
},
220222
options: { log: false }
221223
});
224+
});
225+
226+
Cypress.Commands.overwrite('log', (originalFn, ...args) => {
227+
if (args.includes('test_observability_log') || args.includes('test_observability_command')) return;
222228
originalFn(...args);
223229
});
224230

bin/testObservability/reporter/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,9 @@ class MyReporter {
631631
if(this.current_hook && ( this.current_hook.hookAnalyticsId && !this.runStatusMarkedHash[this.current_hook.hookAnalyticsId] )) {
632632
log.hook_run_uuid = this.current_hook.hookAnalyticsId;
633633
}
634-
if(!log.hook_run_uuid && this.current_test && ( this.current_test.testAnalyticsId && !this.runStatusMarkedHash[this.current_test.testAnalyticsId] )) log.test_run_uuid = this.current_test.testAnalyticsId;
634+
if(!log.hook_run_uuid && this.current_test && this.current_test.testAnalyticsId) {
635+
log.test_run_uuid = this.current_test.testAnalyticsId;
636+
}
635637
if(log.hook_run_uuid || log.test_run_uuid) {
636638
await uploadEventData({
637639
event_type: 'LogCreated',

0 commit comments

Comments
 (0)