Skip to content

Commit 80b4c6e

Browse files
committed
fix: failure case
1 parent a9d94c4 commit 80b4c6e

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

bin/testObservability/cypress/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const util = require('util');
66

77
let eventsQueue = [];
8+
let testRunStarted = false;
89

910
const browserStackLog = (message) => {
1011
if (!Cypress.env('BROWSERSTACK_LOGS')) return;
@@ -48,7 +49,8 @@ Cypress.on('command:start', (command) => {
4849
args: command.attributes.args
4950
},
5051
state: 'pending',
51-
started_at: new Date().toISOString()
52+
started_at: new Date().toISOString(),
53+
location: testRunStarted ? 'test' : 'hook'
5254
}
5355
},
5456
options: { log: false }
@@ -82,7 +84,8 @@ Cypress.on('command:retry', (command) => {
8284
error: {
8385
message: command && command.error ? command.error.message : null,
8486
isDefaultAssertionErr: command && command.error ? command.error.isDefaultAssertionErr : null
85-
}
87+
},
88+
location: testRunStarted ? 'test' : 'hook'
8689
}
8790
},
8891
options: { log: false }
@@ -105,7 +108,8 @@ Cypress.on('command:end', (command) => {
105108
'args': command.attributes.args
106109
},
107110
'state': command.state,
108-
finished_at: new Date().toISOString()
111+
finished_at: new Date().toISOString(),
112+
location: testRunStarted ? 'test' : 'hook'
109113
}
110114
},
111115
options: { log: false }
@@ -213,6 +217,7 @@ beforeEach(() => {
213217
});
214218
}
215219
eventsQueue = [];
220+
testRunStarted = true;
216221
});
217222

218223
afterEach(function() {
@@ -224,4 +229,5 @@ afterEach(function() {
224229
}
225230

226231
eventsQueue = [];
232+
testRunStarted = false;
227233
});

bin/testObservability/reporter/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,8 @@ class MyReporter {
629629
finished_at: null,
630630
duration: null,
631631
result: 'pending',
632-
test_run_uuid: this.current_test?.testAnalyticsId,
633-
hook_run_uuid : this.current_hook?.hookAnalyticsId
632+
test_run_uuid: command.location === 'test' ? this.current_test?.testAnalyticsId : null,
633+
hook_run_uuid : command.location === 'hook' ? this.current_hook?.hookAnalyticsId : null
634634
};
635635
if(currentStepObj.hook_run_uuid && currentStepObj.test_run_uuid) delete currentStepObj.test_run_uuid;
636636
this.currentTestSteps = [
@@ -660,8 +660,8 @@ class MyReporter {
660660
finished_at: new Date().toISOString(),
661661
duration: 0,
662662
result: command.state,
663-
test_run_uuid: this.current_test?.testAnalyticsId && !this.runStatusMarkedHash[this.current_test.testAnalyticsId] ? this.current_test.testAnalyticsId : null,
664-
hook_run_uuid : this.current_hook?.hookAnalyticsId && !this.runStatusMarkedHash[this.current_hook.hookAnalyticsId] ? this.current_hook.hookAnalyticsId : null
663+
test_run_uuid: command.location === 'test' ? this.current_test?.testAnalyticsId : null,
664+
hook_run_uuid : command.location === 'hook' ? this.current_hook?.hookAnalyticsId : null
665665
};
666666
if(currentStepObj.hook_run_uuid && currentStepObj.test_run_uuid) delete currentStepObj.test_run_uuid;
667667
this.currentTestSteps = [

0 commit comments

Comments
 (0)