Trying out qunit teamcity
by ozzymcduff
HTML
<script src="//code.jquery.com/qunit/qunit-1.18.0.js"></script>
<link rel="stylesheet" href="//code.jquery.com/qunit/qunit-1.18.0.css">
<div id="qunit"></div>
JavaScript
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined' ? args[number] : '{' + number + '}';
});
};
Object.prototype.teamCityEscape = function () {
var val = this.toString();
return val.replace(/['\n\r\|\[\]]/g, function (match) {
switch (match) {
case "'":
return "|'";
case "\n":
return "|n";
case "\r":
return "|r";
case "|":
return "||";
case "[":
return "|[";
case "]":
return "|]";
default:
return match;
}
});
};
/* TODO (dw): Have this passed through as a param to PhantonJS.exe? */
var currentTestName = "";
/* QUnit.testStart({ name }) */
QUnit.testStart(function (args) {
currentTestName = args.name;
});
QUnit.moduleStart(function (args) {
console.log("##teamcity[testSuiteStarted name='{0}']".format(args.name.teamCityEscape()));
});
QUnit.moduleDone(function (args) {
console.log("##teamcity[testSuiteFinished name='{0}']".format(args.name.teamCityEscape()));
});
/* QUnit.log({ result, actual, expected, message }) */
QUnit.log = function (args) {
var currentAssertion = "{0} > {1}".format(currentTestName, args.message).teamCityEscape();
console.log("##teamcity[testStarted name='{0}']".format(currentAssertion));
if (!args.result) {
console.log("##teamcity[testFailed type='comparisonFailure' name='{0}' details='expected={1}, actual={2}' expected='{1}' actual='{2}']".format(currentAssertion, args.expected.teamCityEscape(), args.actual.teamCityEscape()));
}
console.log("##teamcity[testFinished name='{0}']".format(currentAssertion));
};
/* QUnit.done({ failed, passed, total,...