Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
QUnit integration with TeamCity (via service messages)Supports stacktraces, comparison failure diffs for large texts.
(function(QUnit) {
var tcEscape = function(str) {
str = str ? str.toString() : "";
str = str.replace(/\n/g, "|n");
str = str.replace(/\r/g, "|r");
str = str.replace(/(['\[\]])/g, "|$1");
return str;
};
//QUnit.moduleStart({ name })
QUnit.moduleStart(function(settings){
console.log("##teamcity[testSuiteStarted name='" + settings.name + "']");
});
//QUnit.moduleDone({ name, failed, passed, total })
QUnit.moduleDone(function(settings){
console.log("##teamcity[testSuiteFinished name='" + settings.name + "']");
});
//QUnit.testStart({ name })
QUnit.testStart(function (settings){
console.log("##teamcity[testStarted name='" + settings.name + "' captureStandardOutput='true']");
});
//QUnit.testDone({ name, failed, passed, total })
QUnit.testDone(function(settings){
if (settings.name) {
console.log("##teamcity[testFinished name='" + settings.name + "']");
}
});
QUnit.log(function( details ) {
if (!details.result) {
var isComparison = details.expected || details.actual;
if ( (isComparison && ("" + details.actual + details.expected).length > 10) ) {
console.log("##teamcity[testFailed type='comparisonFailure' name='" + details.name
+"' message='" + tcEscape(details.message)
+ "' details='" + tcEscape(details.source) +
"' expected='" + tcEscape(details.expected) +
"' actual='" + tcEscape(details.actual)+ "']");
}
var message = "";
if (isComparison) {
message = "Expected: " + details.expected + ", Actual: " + details.actual;
}
if (details.message) {
message = details.message + ": " + message;
}
console.log("Message: " + message);
console.log("##teamcity[testFailed name='" + details.name
+"' message='" + tcEscape(message) + "' details='" + tcEscape(details.source) + "']");
}
});
})(QUnit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.