Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

feat: Add config.teamcityReporter and prependSpecIdInSpecNameEnabled … #100

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ var formatMessage = function () {
return util.format.apply(null, args) + '\n'
}

var TeamcityReporter = function (baseReporterDecorator) {
var TeamcityReporter = function (baseReporterDecorator, teamcityReporter) {
const prependSpecIdInSpecNameEnabled = !!(teamcityReporter && teamcityReporter.prependSpecIdInSpecNameEnabled)
const useSpecFullName = !!(teamcityReporter && teamcityReporter.useSpecFullName)

baseReporterDecorator(this)
var self = this

Expand All @@ -65,6 +68,22 @@ var TeamcityReporter = function (baseReporterDecorator) {
}
}

const getFormattedSpecName = ({ id, description, fullName }) => {
let formattedSpecName = ''

if (prependSpecIdInSpecNameEnabled) {
formattedSpecName += `[${id.toLocaleUpperCase()}] `
}

if (useSpecFullName) {
formattedSpecName += fullName
} else {
formattedSpecName += description
}

return formattedSpecName
}

this.onRunStart = function (browsers) {
this.write(formatMessage(this.BLOCK_OPENED, 'JavaScript Unit Tests'))

Expand All @@ -79,15 +98,15 @@ var TeamcityReporter = function (baseReporterDecorator) {

this.specSuccess = function (browser, result) {
var log = this.getLog(browser, result)
var testName = result.description
var testName = getFormattedSpecName(result)

log.push(formatMessage(this.TEST_START, testName))
log.push(formatMessage(this.TEST_END, testName, result.time))
}

this.specFailure = function (browser, result) {
var log = this.getLog(browser, result)
var testName = result.description
var testName = getFormattedSpecName(result)

log.push(formatMessage(this.TEST_START, testName))
log.push(formatMessage(this.TEST_FAILED, testName, result.log.join('\n\n')))
Expand All @@ -96,7 +115,7 @@ var TeamcityReporter = function (baseReporterDecorator) {

this.specSkipped = function (browser, result) {
var log = this.getLog(browser, result)
var testName = result.description
var testName = getFormattedSpecName(result)

log.push(formatMessage(this.TEST_IGNORED, testName))
}
Expand Down Expand Up @@ -148,7 +167,7 @@ var TeamcityReporter = function (baseReporterDecorator) {
}
}

TeamcityReporter.$inject = ['baseReporterDecorator']
TeamcityReporter.$inject = ['baseReporterDecorator', 'config.teamcityReporter']

module.exports = {
'reporter:teamcity': ['type', TeamcityReporter]
Expand Down