Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add retries property in reports #206

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
fix: append failure nodes only in final fail case
  • Loading branch information
bweber-ftapi committed May 16, 2024
commit a048b1176cc542a4e887e1642b9f9c7c95452758
54 changes: 26 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,31 +194,29 @@ function getJenkinsClassname (test, options) {
return titles.join(options.suiteTitleSeparatedBy);
}

function appendFormattedErrorMessageToTestcase(testcase, err, self) {
var message;
if (err.message && typeof err.message.toString === 'function') {
message = err.message + '';
} else if (typeof err.inspect === 'function') {
message = err.inspect() + '';
} else {
message = '';
}
var failureMessage = err.stack || message;
if (!Base.hideDiff && err.expected !== undefined) {
var oldUseColors = Base.useColors;
Base.useColors = false;
failureMessage += "\n" + Base.generateDiff(err.actual, err.expected);
Base.useColors = oldUseColors;
}
var failureElement = {
_attr: {
message: self.removeInvalidCharacters(message) || '',
type: err.name || ''
},
_cdata: self.removeInvalidCharacters(failureMessage)
};

testcase.testcase.push({failure: failureElement});
function formatErrorMessage(err, removeInvalidCharacters) {
var message;
if (err.message && typeof err.message.toString === 'function') {
message = err.message + '';
} else if (typeof err.inspect === 'function') {
message = err.inspect() + '';
} else {
message = '';
}
var failureMessage = err.stack || message;
if (!Base.hideDiff && err.expected !== undefined) {
var oldUseColors = Base.useColors;
Base.useColors = false;
failureMessage += "\n" + Base.generateDiff(err.actual, err.expected);
Base.useColors = oldUseColors;
}
return {
_attr: {
message: removeInvalidCharacters(message) || '',
type: err.name || ''
},
_cdata: removeInvalidCharacters(failureMessage)
};
}

/**
Expand Down Expand Up @@ -388,11 +386,11 @@ MochaJUnitReporter.prototype.getTestcaseData = function(test, err) {
if (test.prevAttempts) {
const self = this;
test.prevAttempts.forEach(function (attempt) {
appendFormattedErrorMessageToTestcase(testcase, attempt.err, self);
testcase.testcase.push({flakyFailure: formatErrorMessage(attempt.err, self.removeInvalidCharacters)});
})
}
}
if (err) {
appendFormattedErrorMessageToTestcase(testcase, err, this);
testcase.testcase.push({failure: formatErrorMessage(err, this.removeInvalidCharacters)});
}
return testcase;
};
Expand Down