UNPKG

siesta-lite

Version:

Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers

164 lines (106 loc) 5.11 kB
/* Siesta 5.6.1 Copyright(c) 2009-2022 Bryntum AB https://bryntum.com/contact https://bryntum.com/products/siesta/license */ Role('Siesta.Launcher.Dispatcher.Reporter.TeamCity', { has : { tcSuiteName : null, tcEncodeRegExp : /(['\[\]|])/g, testSuiteStartPrinted : false, testSuiteFinishPrinted : false, teamCityPrintState : Joose.I.Object }, override : { initialize : function () { var me = this this.launcher.on('destroy', function () { if (me.testSuiteStartPrinted && !me.testSuiteFinishPrinted) me.tcPrintTestSuiteFinish() }) this.SUPER() }, warn : function (text) { this.tcPrint('message', { text : text, status : 'WARNING' }) this.SUPERARG(arguments) }, onTestSuiteStart : function (userAgent, platform) { var browserInfo = this.parseBrowser(userAgent) this.tcSuiteName = this.options[ 'tc-suite' ] || ( (this.testSuiteName ? this.testSuiteName + ': ' : '') + browserInfo.name + ' ' + browserInfo.version ) this.tcPrint('testSuiteStarted', { name : this.tcSuiteName }) this.SUPERARG(arguments) this.testSuiteStartPrinted = true }, onTestSuiteEnd : function () { this.SUPER() this.tcPrintTestSuiteFinish() }, printTestBody : function (testResult) { if (testResult.ERROR) this.tcPrint('testFailed', { name : this.getTcTestName(testResult), details : testResult.ERROR }) this.SUPERARG(arguments) }, printTestHeader : function (testResult) { this.tcPrint('testStarted', { name : this.getTcTestName(testResult) }) this.SUPERARG(arguments) }, printTestFooter : function (testResult) { this.SUPERARG(arguments) var duration = testResult.endDate - testResult.startDate this.tcPrint('testFinished', { name : this.getTcTestName(testResult), duration : duration }) }, printAssertionInfo : function (assertion, parentTests, printState) { this.SUPERARG(arguments) switch (assertion.type) { case 'Siesta.Result.Assertion' : if (!assertion.isTodo && (assertion.isException || !assertion.passed)) { var text = this.getAssertionText(assertion) text = this.getFormattedAssertionText(text, assertion, parentTests, this.teamCityPrintState, true) if (parentTests[ 0 ]) { this.tcPrint('testFailed', { name : this.getTcTestName(parentTests[ 0 ]), details : text }) } // TODO: no parentTests case happens (if preloads are missing) ..still show the assertion w/ some made up test identifier else { this.tcPrint('testFailed', { name : '.fail.' + assertion.index + '.' + Date.now(), details : text }) } } break; case 'Siesta.Result.Diagnostic' : if (assertion.isWarning) { var text = this.getAssertionText(assertion) text = this.getFormattedAssertionText(text, assertion, parentTests, {}, true) this.tcPrint('message', { text : text, status : 'WARNING' }) } break; } } }, methods : { tcPrintTestSuiteFinish : function () { var duration = this.endDate - this.startDate this.tcPrint('testSuiteFinished', { name : this.tcSuiteName, duration : duration }) this.testSuiteFinishPrinted = true }, tcPrint : function(messageName, attributes) { attributes = attributes || {} var text = '##teamcity[' + messageName for (var name in attributes) { text += ' ' + name + "='" + this.tcEncode(attributes[name]) + "'" } text += ']' this.print(text) }, getTcTestName : function (testResult, encode) { // the leading dot here is needed to fix a bug in TeamCity, where if a build has a single failed test // that has dots in the name, the name of that test will be partly included in the test suite name: // http://teamcity.bryntum.com/viewLog.html?buildId=81389&tab=buildResultsDiv&buildTypeId=Siesta_SiestaFirefoxTests var testName = '.' + (testResult.name || testResult.url) return encode ? this.tcEncode(testName) : testName }, tcEncode : function (text) { return String(text).replace(this.tcEncodeRegExp, '|$1').replace(/\r/g, '|r').replace(/\n/g, '|n') } } })