Skip to content

Commit

Permalink
Merge 578164b into 152a114
Browse files Browse the repository at this point in the history
  • Loading branch information
bjspencer committed Nov 1, 2016
2 parents 152a114 + 578164b commit 084a77c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
48 changes: 48 additions & 0 deletions bin/formatters/teamcity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* Copyright (c) 2016, Yanis Wang <yanis.wang@gmail.com>
* MIT Licensed
*/
var teamcityFormatter = function(formatter){

function tcEscape(message) {
return message
.replace("'", "|'")
.replace("\n", "|n")
.replace("\r", "|r")
.replace("|", "||")
.replace("[", "|[")
.replace("]", "|]");
}

function formatTeamCityMessage(name, properties) {
var message = "##teamcity[" + tcEscape(name);
for (var key in properties) {
message += " " + key + "='" + tcEscape(properties[key]) + "'";
}
message += "]";
return message;
}


formatter.on('end', function(event){
var arrAllMessages = event.arrAllMessages;
arrAllMessages.forEach(function(fileInfo){
var filePath = fileInfo.file;
var testSuiteName = "htmllint: " + filePath;
console.log(formatTeamCityMessage("testSuiteStarted", { name: testSuiteName }));

var arrMessages = fileInfo.messages;
arrMessages.forEach(function(message){
var testName = "(" + message.line + ", " + message.col + ") " + message.rule.description;
console.log(formatTeamCityMessage("testStarted", { name: testName }));
if(message.type === 'error' || message.type === 'warning'){
console.log(formatTeamCityMessage("testFailed", { name: testName, message: message.message }));
}
console.log(formatTeamCityMessage("testFinished", { name: testName }));
});

console.log(formatTeamCityMessage("testSuiteFinished", { name: testSuiteName }));
});
});
};
module.exports = teamcityFormatter;

0 comments on commit 084a77c

Please sign in to comment.