Skip to content

Commit

Permalink
junit-reporter: fix log file names (#3892)
Browse files Browse the repository at this point in the history
* junit-reporter: fix log file names

* junit-reporter: fix unit test
  • Loading branch information
naddison authored and christian-bromann committed Apr 29, 2019
1 parent 27725a9 commit c52193d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
17 changes: 9 additions & 8 deletions packages/wdio-junit-reporter/README.md
Expand Up @@ -32,7 +32,7 @@ are examples of XML output given different scenarios in the spec file.
```javascript
describe('a test suite', () => {
it('a test case', function () {
// do something
// do something
// assert something
});
});
Expand All @@ -57,7 +57,7 @@ becomes
describe('a test suite', () => {
describe('a nested test suite', function() {
it('a test case', function () {
// do something
// do something
// assert something
});
});
Expand Down Expand Up @@ -90,13 +90,13 @@ becomes
```javascript
describe('a test suite', () => {
it('a test case', function () {
// do something
// do something
// assert something
});
});
describe('a second test suite', () => {
it('a second test case', function () {
// do something
// do something
// assert something
});
});
Expand Down Expand Up @@ -153,8 +153,8 @@ module.exports = {
'dot',
['junit', {
outputDir: './',
outputFileFormat: function(opts) { // optional
return `results-${opts.cid}.${opts.capabilities}.xml`
outputFileFormat: function(options) { // optional
return `results-${options.cid}.${options.capabilities}.xml`
}
}]
],
Expand All @@ -174,15 +174,16 @@ Required
Define the xml files created after the test execution.

Type: `Object`<br>
Default: ``function(opts){return `WDIO.xunit.${opts.capabilities}.${opts.cid}.xml`}``
Default: ``function(opts){return `wdio-${this.cid}-${name}-reporter.log`}``

```
outputFileFormat: {
single: function (config) {
single: function (options) {
return 'mycustomfilename.xml';
}
}
```
> Note: `options.capabilities` is your capabilities object for that runner, so specifying `${options.capabilities}` in your string will return [Object object]. You must specify which properties of capabilities you want in your filename.
### suiteNameFormat

Expand Down
8 changes: 6 additions & 2 deletions packages/wdio-runner/src/reporter.js
Expand Up @@ -17,14 +17,17 @@ export default class BaseReporter {
constructor (config, cid, caps) {
this.config = config
this.cid = cid
this.reporters = config.reporters.map(::this.initReporter)
this.caps = caps

/**
* these configurations are not publicly documented as there should be no desire for it
*/
this.reporterSyncInterval = this.config.reporterSyncInterval || DEFAULT_SYNC_INTERVAL
this.reporterSyncTimeout = this.config.reporterSyncTimeout || DEFAULT_SYNC_TIMEOUT

// ensure all properties are set before initializing the reporters
this.reporters = config.reporters.map(::this.initReporter)

}

/**
Expand All @@ -39,7 +42,8 @@ export default class BaseReporter {
}

getLogFile(name) {
let options = this.config
// clone the config to avoid changing original properties
let options = Object.assign({}, this.config)
let filename = `wdio-${this.cid}-${name}-reporter.log`

const reporterOptions = this.config.reporters.find((reporter) => (
Expand Down
4 changes: 1 addition & 3 deletions packages/wdio-runner/tests/reporter.test.js
Expand Up @@ -42,15 +42,13 @@ describe('BaseReporter', () => {
const reporter = new BaseReporter({
outputDir: '/foo/bar',
reporters: [
'dot',
['dot', {
foo: 'bar',
outputDir: '/foo/bar/baz'
}]
]
}, '0-0')

expect(reporter.getLogFile('foobar')).toMatch(/(\\|\/)foo(\\|\/)bar(\\|\/)baz(\\|\/)wdio-0-0-foobar-reporter.log/)
expect(reporter.getLogFile('dot')).toMatch(/(\\|\/)foo(\\|\/)bar(\\|\/)baz(\\|\/)wdio-0-0-dot-reporter.log/)
})

it('should return custom log file name', () => {
Expand Down

0 comments on commit c52193d

Please sign in to comment.