-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters