Skip to content
Browse files

Replaced the Team City output file with a forked Gist (https://gist.g…

  • Loading branch information...
1 parent c969c65 commit 0329ff2b2c267126e51abe2efbcedfcbe84f984e Ben Hanna committed Nov 10, 2013
Showing with 55 additions and 56 deletions.
  1. +55 −56 QUnitTeamCityDriver/QUnitTeamCityDriver.js
View
111 QUnitTeamCityDriver/QUnitTeamCityDriver.js
@@ -1,69 +1,68 @@
-if (navigator.userAgent.indexOf("PhantomJS") !== -1) {
- String.prototype.format = function () {
- var args = arguments;
- return this.replace(/{(\d+)}/g, function (match, number) {
- return typeof args[number] != 'undefined'
- ? args[number]
- : '{' + number + '}';
- });
- };
+(function (QUnit) {
- String.prototype.teamCityEscape = function () {
- return this.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;
- }
- });
+ if (!window.console) {
+ window.console = {
+ log: function () { }
+ };
+ }
+
+ 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;
};
-
- /* TODO (dw): Have this passed through as a param to PhantonJS.exe? */
- var suiteName = "QUnit Tests";
- var currentTestName = "";
- var hasBegun = false;
- qunitBegin = function () {
- // TODO (dw): Should be able to use QUnit.begin() - but that doesn't seem to fire.
- console.log("##teamcity[testSuiteStarted name='{0}']".format(suiteName.teamCityEscape()));
+ var suiteRunning = false;
+
+//QUnit.moduleStart({ name })
+ QUnit.moduleStart = function (settings) {
+ console.log("##teamcity[testSuiteStarted name='" + settings.name + "']");
+ suiteRunning = true;
};
- /* QUnit.testStart({ name }) */
- QUnit.testStart = function (args) {
- if (!hasBegun) {
- qunitBegin();
- hasBegun = true;
+//QUnit.moduleDone({ name, failed, passed, total })
+ QUnit.moduleDone = function (settings) {
+ if (suiteRunning) {
+ suiteRunning = false;
+ console.log("##teamcity[testSuiteFinished name='" + settings.name + "']");
}
+ };
- currentTestName = args.name;
+//QUnit.testStart({ name })
+ QUnit.testStart = function (settings) {
+ console.log("##teamcity[testStarted name='" + tcEscape(settings.name) + "' captureStandardOutput='true']");
};
- /* QUnit.log({ result, actual, expected, message }) */
- QUnit.log = function (args) {
- var currentAssertion = "{0} > {1}".format(currentTestName, args.message).teamCityEscape();
+//QUnit.testDone({ name, failed, passed, total })
+ QUnit.testDone = function (settings) {
+ console.log("##teamcity[testFinished name='" + tcEscape(settings.name) + "']");
+ };
- console.log("##teamcity[testStarted name='{0}']".format(currentAssertion));
+ QUnit.log(function (details) {
+ if (!details.result) {
+ var isComparison = details.expected || details.actual;
- 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()));
- }
+ if ((isComparison && ("" + details.actual + details.expected).length > 10)) {
+ console.log("##teamcity[testFailed type='comparisonFailure' name='" + tcEscape(details.name)
+ + "' message='" + tcEscape(details.message)
+ + "' details='" + tcEscape(details.source) +
+ "' expected='" + tcEscape(details.expected) +
+ "' actual='" + tcEscape(details.actual) + "']");
+ }
- console.log("##teamcity[testFinished name='{0}']".format(currentAssertion));
- };
+ var message = "";
+ if (isComparison) {
+ message = "Expected: " + details.expected + ", Actual: " + details.actual;
+ }
+ if (details.message) {
+ message = details.message + ": " + message;
+ }
- /* QUnit.done({ failed, passed, total, runtime }) */
- QUnit.done = function (args) {
- console.log("##teamcity[testSuiteFinished name='{0}']".format(suiteName.teamCityEscape()));
- };
-}
+ console.log("##teamcity[testFailed name='" + tcEscape(details.name)
+ + "' message='" + tcEscape(message) + "' details='" + tcEscape(details.source) + "']");
+ }
+ });
+
+})(QUnit);

0 comments on commit 0329ff2

Please sign in to comment.
Something went wrong with that request. Please try again.