Skip to content

Commit

Permalink
feat: add Teamcity reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
edjafarov authored and vojtajina committed Feb 21, 2013
1 parent 5b4d5d8 commit 03e700a
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ exports.DotsColor = require('./reporters/DotsColor');
exports.ProgressColor = require('./reporters/ProgressColor');
exports.JUnit = require('./reporters/JUnit');
exports.Coverage = require('./reporters/Coverage');
exports.Teamcity = exports.TeamcityColor = require('./reporters/Teamcity');
exports.Growl = require('./reporters/Growl');

exports.createReporters = createReporters;
125 changes: 125 additions & 0 deletions lib/reporters/Teamcity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
var BaseReporter = require('./Base');
var util = require('util');

var escTCString = function (message) {
if(!message) {
return '';
}

return message.
replace(/\|/g, '||').
replace(/\'/g, '|\'').
replace(/\n/g, '|n').
replace(/\r/g, '|r').
replace(/\u0085/g, '|x').
replace(/\u2028/g, '|l').
replace(/\u2029/g, '|p').
replace(/\[/g, '|[').
replace(/\]/g, '|]');
};

var getTestName = function (result) {
return result.slice(1).join(' ');
}

var TeamcityReporter = function(formatError, reportSlow) {
BaseReporter.call(this, formatError, reportSlow);

this.onRunStart = function(browsers) {
this._browsers = browsers;
this.browserResults = {};
};

this.writeCommonMsg = function(msg) {
this.write('\n' + msg);
this._dotsCount = 0;
};

this.specSuccess = function(browser, result) {
var browseResult = this.checkNewSuit(browser, result);
var testName = getTestName(result.suite);

browseResult.log.push(util.format(this.TEST_START, escTCString(testName)));
browseResult.log.push(util.format(this.TEST_END,
escTCString(testName), result.time));
};

this.specFailure = function(browser, result) {
var browseResult = this.checkNewSuit(browser, result);
var testName = getTestName(result.suite);

browseResult.log.push(util.format(this.TEST_START, escTCString(testName)));
browseResult.log.push(util.format(this.TEST_FAILED, escTCString(testName),
escTCString(JSON.stringify(result.log))));
browseResult.log.push(util.format(this.TEST_END,
escTCString(testName), result.time));
};

this.specSkipped = function(browser, result) {
var browseResult = this.checkNewSuit(browser, result);
var testName = getTestName(result.suite);

browseResult.log.push(util.format(this.TEST_IGNORED, escTCString(testName)));
};

this.checkNewSuit = function(browser, result) {
var browserResult = this.checkNewBrowser(browser);
var suiteExists = browserResult.suits.indexOf(result.suite[0]) !== -1;

if(!suiteExists) {
if(browserResult.suits.length > 0) {
browserResult.log.push(util.format(this.SUITE_END,
escTCString(browserResult.suits[browserResult.suits.length - 1])));
}
browserResult.suits.push(result.suite[0]);
browserResult.log.push(util.format(this.SUITE_START, escTCString(result.suite[0])));
}
return browserResult;
};

this.checkNewBrowser = function(browser) {
if(!this.browserResults[browser.id]) {
this.browserResults[browser.id] = {
log : [],
suits : []
};
}
return this.browserResults[browser.id];
};

this.onRunComplete = function(browsers, results) {
var self = this;

Object.keys(this.browserResults).forEach(function(key) {
var browserResult = self.browserResults[key];
if(browserResult.suits.length > 0) {
browserResult.log.push(util.format(self.SUITE_END,
escTCString(browserResult.suits[browserResult.suits.length - 1])));
}
self.write(self.BROWSER_START, key);
self.write(browserResult.log.join('\n'));
self.write(self.BROWSER_END, key);
});

this.writeCommonMsg(browsers.map(this.renderBrowser).join('\n') + '\n');

if (browsers.length > 1 && !results.disconnected && !results.error) {
if (!results.failed) {
this.write(this.TOTAL_SUCCESS, results.success);
} else {
this.write(this.TOTAL_FAILED, results.failed, results.success);
}
}
};

this.TEST_IGNORED = '##teamcity[testIgnored name=\'%s\']';
this.SUITE_START = '##teamcity[testSuiteStarted name=\'%s\']';
this.SUITE_END = '##teamcity[testSuiteFinished name=\'%s\']';
this.TEST_START = '##teamcity[testStarted name=\'%s\']';
this.TEST_FAILED = '##teamcity[testFailed name=\'%s\' message=\'FAILED\' details=\'%s\']';
this.TEST_END = '##teamcity[testFinished name=\'%s\' duration=\'%s\']';
this.BROWSER_START = '##teamcity[browserStart name=\'%s\']\n';
this.BROWSER_END = '\n##teamcity[browserEnd name=\'%s\']';
};

module.exports = TeamcityReporter;
2 changes: 1 addition & 1 deletion test/client/testacular.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exclude = [
];

// use dots reporter, as travis terminal does not support escaping sequences
// possible values: 'dots', 'progress', 'junit'
// possible values: 'dots', 'progress', 'junit', 'teamcity'
// CLI --reporters progress
reporters = ['progress', 'junit'];

Expand Down

0 comments on commit 03e700a

Please sign in to comment.