-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update reporter to be compatible with wdio v5 #14
Changes from 10 commits
f7a4a31
2298e16
5030557
ded854a
cd4d97f
858fc60
b285f96
1e541b6
4928dc8
3cd81af
aaa5bab
4acffa6
aae35f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
{ | ||
"presets": [ | ||
"es2015" | ||
[ | ||
"env", | ||
{ | ||
"targets": { | ||
"node": "8" | ||
} | ||
} | ||
] | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,4 @@ notifications: | |
|
||
language: node_js | ||
node_js: | ||
- "6" | ||
- "4" | ||
- "0.12" | ||
- "8" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
'use strict'; | ||
|
||
const { EventEmitter } = require('events'); | ||
const WdioReporter = require('@wdio/reporter').default; | ||
const { buildFormatter, events } = require('./lib/message'); | ||
const { flow } = require('lodash'); | ||
const { inherits } = require('util'); | ||
|
||
module.exports = WdioTeamcityReporter; | ||
module.exports.reporterName = 'teamcity'; | ||
|
||
/** | ||
* @param {object} baseReporter | ||
|
@@ -17,36 +13,35 @@ module.exports.reporterName = 'teamcity'; | |
* @param {string} reporterOptions.message | ||
* @return {wdioTeamcityReporter} | ||
*/ | ||
function WdioTeamcityReporter(baseReporter, wdioConf, reporterOptions = {}) { | ||
this.baseReporter = baseReporter; | ||
|
||
const opts = { | ||
captureStandardOutput: typeof reporterOptions.captureStandardOutput === 'boolean' | ||
? reporterOptions.captureStandardOutput | ||
: false, | ||
flowId: typeof reporterOptions.flowId === 'boolean' | ||
? reporterOptions.flowId | ||
: true, | ||
name: typeof reporterOptions.message === 'string' | ||
? reporterOptions.message | ||
: '[title]', | ||
}; | ||
|
||
this.enableRealTimeOutput(opts); | ||
} | ||
|
||
inherits(WdioTeamcityReporter, EventEmitter); | ||
|
||
WdioTeamcityReporter.prototype.enableRealTimeOutput = function (opts) { | ||
events.forEach(event => this.on(event, flow(buildFormatter(event, opts), output))); | ||
}; | ||
class WdioTeamcityReporter extends WdioReporter { | ||
constructor(reporterOptions) { | ||
Object.assign(reporterOptions, { | ||
captureStandardOutput: typeof reporterOptions.captureStandardOutput === 'boolean' | ||
? reporterOptions.captureStandardOutput | ||
: false, | ||
flowId: typeof reporterOptions.flowId === 'boolean' | ||
? reporterOptions.flowId | ||
: true, | ||
name: typeof reporterOptions.message === 'string' | ||
? reporterOptions.message | ||
: '[title]', | ||
stdout: true, | ||
}); | ||
super(reporterOptions); | ||
this.enableRealTimeOutput(reporterOptions); | ||
} | ||
|
||
/** | ||
* @param {string} msg | ||
* @return {string} | ||
*/ | ||
function output(msg) { | ||
if (msg) { | ||
console.log(msg); | ||
enableRealTimeOutput(opts) { | ||
events.forEach(event => { | ||
this[event] = (...args) => | ||
flow(buildFormatter(event, opts), msg => { | ||
if (msg) { | ||
this.write(msg); | ||
} | ||
})(...args); | ||
}); | ||
} | ||
} | ||
|
||
module.exports.default = WdioTeamcityReporter; | ||
module.exports.reporterName = 'teamcity'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like wdio tries to use this as a ES6 module. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added that. It should be working now. I was using importing the reporter instead of specifying the name so I didn't catch that. Thanks! |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,20 +20,20 @@ const { camelCase, get, invoke } = require('lodash'); | |
|
||
const paths = { | ||
browser: ({ suite }) => ['suite', 'runner', suite.cid, 'browserName'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this might need an update as well. I did a console.log(ctx) to see what object properties are available - you can see the result here Based on that, this works (at least for chrome): |
||
details: () => 'suite.err.stack', | ||
details: () => 'suite.error.stack', | ||
flowId: ({ suite }) => ['reporter', 'baseReporter', 'stats', 'runners', suite.cid, 'sessionID'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this needs to be updated. I fixed using:
This may also work, based on the console.log output of the ctx object, but I haven't tested
|
||
hash: () => 'suite.specHash', | ||
message: () => 'suite.err.message', | ||
message: () => 'suite.error.message', | ||
title: () => 'suite.title', | ||
}; | ||
|
||
const events = { | ||
'suite:start': '##teamcity[testSuiteStarted flowId=\'[flowId]\' name=\'[name]\']', | ||
'test:start': '##teamcity[testStarted flowId=\'[flowId]\' name=\'[name]\' captureStandardOutput=\'[captureStandardOutput]\']', | ||
'test:end': '##teamcity[testFinished flowId=\'[flowId]\' name=\'[name]\']', | ||
'test:fail': '##teamcity[testFailed flowId=\'[flowId]\' name=\'[name]\' message=\'[message]\' details=\'[details]\']', | ||
'test:pending': '##teamcity[testIgnored flowId=\'[flowId]\' name=\'[name]\' message=\'pending\']', | ||
'suite:end': '##teamcity[testSuiteFinished flowId=\'[flowId]\' name=\'[name]\']', | ||
var events = { | ||
'onSuiteStart': '##teamcity[testSuiteStarted flowId=\'[flowId]\' name=\'[name]\']', | ||
'onTestStart': '##teamcity[testStarted flowId=\'[flowId]\' name=\'[name]\' captureStandardOutput=\'[captureStandardOutput]\']', | ||
'onTestEnd': '##teamcity[testFinished flowId=\'[flowId]\' name=\'[name]\']', | ||
'onTestFail': '##teamcity[testFailed flowId=\'[flowId]\' name=\'[name]\' message=\'[message]\' details=\'[details]\']', | ||
'onTestSkip': '##teamcity[testIgnored flowId=\'[flowId]\' name=\'[name]\' message=\'pending\']', | ||
'onSuiteEnd': '##teamcity[testSuiteFinished flowId=\'[flowId]\' name=\'[name]\']' | ||
}; | ||
|
||
exports.buildFormatter = buildFormatter; | ||
|
@@ -52,7 +52,7 @@ function buildFormatter(eventName, opts) { | |
return formatter; | ||
|
||
function formatter(suite) { | ||
if (suite.pending && eventName !== 'test:pending') { | ||
if (suite.pending && eventName !== 'onTestSkip') { | ||
return ''; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no new line appended to
this.write
, so everyone gets dumped as a giant blob with no new lines.Can you add one via:
this.write(`${msg}\n`)
See example of usage.