Skip to content

Commit 04a4ab0

Browse files
committed
added null checks
1 parent 3a3910a commit 04a4ab0

File tree

1 file changed

+17
-13
lines changed

1 file changed

+17
-13
lines changed

src/testObservability.js

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ class TestObservability {
486486
result: 'pending',
487487
framework: 'nightwatch',
488488
integrations: {
489-
[provider]: helper.getIntegrationsObject(testMetaData.sessionCapabilities, testMetaData.sessionId, testMetaData.host, settings.desiredCapabilities['bstack:options']?.osVersion)
489+
[provider]: helper.getIntegrationsObject(testMetaData.sessionCapabilities, testMetaData.sessionId, testMetaData.host, settings?.desiredCapabilities?.['bstack:options']?.osVersion)
490490
},
491491
product_map: {
492492
accessibility: helper.isAccessibilitySession()
@@ -496,19 +496,23 @@ class TestObservability {
496496
if (eventType === 'TestRunFinished') {
497497
const eventData = test.envelope[testName].testcase;
498498
testResults = test.testResults;
499-
testData.finished_at = testResults.endTimestamp ? new Date(testResults.endTimestamp).toISOString() : new Date(testResults.startTimestamp).toISOString();
500-
testData.result = testResults.__failedCount > 0 ? 'failed' : 'passed';
501-
if (testData.result === 'failed' && testResults.__lastError) {
502-
testData.failure = [
503-
{
504-
'backtrace': [stripAnsi(testResults.__lastError.message), testResults.__lastError.stack]
499+
if (!testResults) {
500+
Logger.debug(`Test results could not be retrieved for test: ${testName}. Skipping result processing.`);
501+
} else {
502+
testData.finished_at = testResults.endTimestamp ? new Date(testResults.endTimestamp).toISOString() : new Date(testResults.startTimestamp).toISOString();
503+
testData.result = testResults.__failedCount > 0 ? 'failed' : 'passed';
504+
if (testData.result === 'failed' && testResults.__lastError) {
505+
testData.failure = [
506+
{
507+
'backtrace': [stripAnsi(testResults.__lastError.message), testResults.__lastError.stack]
508+
}
509+
];
510+
testData.failure_reason = testResults.__lastError ? stripAnsi(testResults.__lastError.message) : null;
511+
if (testResults.__lastError && testResults.__lastError.name) {
512+
testData.failure_type = testResults.__lastError.name.match(/Assert/) ? 'AssertionError' : 'UnhandledError';
505513
}
506-
];
507-
testData.failure_reason = testResults.__lastError ? stripAnsi(testResults.__lastError.message) : null;
508-
if (testResults.__lastError && testResults.__lastError.name) {
509-
testData.failure_type = testResults.__lastError.name.match(/Assert/) ? 'AssertionError' : 'UnhandledError';
510514
}
511-
}
515+
}
512516

513517
this.processTestRunData (eventData, uuid);
514518
}
@@ -846,7 +850,7 @@ class TestObservability {
846850
}
847851

848852
getTestBody(testCaseData) {
849-
return testCaseData.context.__module[testCaseData.testName] || null;
853+
return testCaseData?.context.__module[testCaseData.testName] || null;
850854
}
851855
}
852856

0 commit comments

Comments
 (0)