Skip to content
This repository has been archived by the owner on Dec 18, 2019. It is now read-only.

use fullTitle of a suite in reporter #79

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 18 additions & 4 deletions lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,33 @@ class JunitReporter extends events.EventEmitter {
super()

this.baseReporter = baseReporter
this.suitTitles = {}
this.config = config
this.options = options
this.suiteNameRegEx = this.options.suiteNameFormat instanceof RegExp
? this.options.suiteNameFormat
: /[^a-z0-9]+/

this.on('runner:start', function (runner) {
this.suitTitles[runner.cid] = {}
})

this.on('suite:start', function (suite) {
this.suitTitles[suite.cid][suite.uid] = suite.fullTitle
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is only available in Mocha, how do we deal with this if someone uses a different framework?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I hadn't thought about it. At least 'parent' attribute is available in Jasmine and Mocha so I can join fullTitle directly in this function. Let me extend it.
Also seems that parent suite always starts before. So I can suggest by the time child suite will start I will already have a name for parent.

})

this.on('end', ::this.onEnd)
}

title (cid, uid) {
return this.suitTitles[cid][uid]
}

onEnd () {
const { epilogue } = this.baseReporter
for (let cid of Object.keys(this.baseReporter.stats.runners)) {
const capabilities = this.baseReporter.stats.runners[cid]
const xml = this.prepareXml(capabilities)
const xml = this.prepareXml(capabilities, cid)
this.write(capabilities, cid, xml)
}
epilogue.call(this.baseReporter)
Expand All @@ -40,7 +53,7 @@ class JunitReporter extends events.EventEmitter {
).join('_')
}

prepareXml (capabilities) {
prepareXml (capabilities, cid) {
const builder = junit.newBuilder()
const packageName = this.options.packageName
? `${capabilities.sanitizedCapabilities}-${this.options.packageName}`
Expand All @@ -59,13 +72,14 @@ class JunitReporter extends events.EventEmitter {
}

const suite = spec.suites[suiteKey]
const suiteName = this.prepareName(suite.title)
const title = this.title(cid, suite.uid)
const suiteName = this.prepareName(title)
const testSuite = builder.testSuite()
.name(suiteName)
.timestamp(suite.start)
.time(suite.duration / 1000)
.property('specId', specId)
.property('suiteName', suite.title)
.property('suiteName', title)
.property('capabilities', capabilities.sanitizedCapabilities)
.property('file', spec.files[0].replace(process.cwd(), '.'))

Expand Down