Skip to content

Commit

Permalink
fix: reporters can be configured individually
Browse files Browse the repository at this point in the history
The `subdir` option previously introduced in karma-coverage-reporter 0.2.5
brings an issue: it wasn't possible anymore to configure a specific output
directory for each reporter. This fix makes it possible again.

Fix #91
  • Loading branch information
aymericbeaumet committed Jul 31, 2014
1 parent b1e4289 commit 6db06ce
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ var CoverageReporter = function(rootConfig, helper, logger) {
if (collector) {
pendingFileWritings++;

var outputDir = helper.normalizeWinPath(path.resolve(basePath, generateOutputDir(browser.name, config.dir, config.subdir)));
var outputDir = helper.normalizeWinPath(path.resolve(basePath, generateOutputDir(browser.name,
reporterConfig.dir || config.dir,
reporterConfig.subdir || config.subdir)));

helper.mkdirIfNotExists(outputDir, function() {
log.debug('Writing coverage to %s', outputDir);
Expand Down
32 changes: 30 additions & 2 deletions test/reporter.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ describe 'reporter', ->

it 'should support a string for the subdir option', ->
customConfig = _.merge {}, rootConfig,
subdir: 'test'
coverageReporter:
subdir: 'test'

Expand All @@ -164,7 +163,6 @@ describe 'reporter', ->

it 'should support a function for the subdir option', ->
customConfig = _.merge {}, rootConfig,
subdir: 'test'
coverageReporter:
subdir: (browserName) -> browserName.toLowerCase().split(/[ /-]/)[0]

Expand All @@ -180,3 +178,33 @@ describe 'reporter', ->
mockMkdir.getCall(0).args[1]()
expect(mockReportCreate).to.have.been.called
expect(mockWriteReport).to.have.been.called

it 'should support a specific dir and subdir per reporter', ->
customConfig = _.merge {}, rootConfig,
coverageReporter:
dir: 'useless'
subdir: 'useless'
reporters: [
{
dir: 'reporter1'
subdir: (browserName) -> browserName.toLowerCase().split(/[ /-]/)[0]
}
{
dir: 'reporter2'
subdir: (browserName) -> browserName.toUpperCase().split(/[ /-]/)[0]
}
]

reporter = new m.CoverageReporter customConfig, mockHelper, mockLogger
reporter.onRunStart()
browsers.forEach (b) -> reporter.onBrowserStart b

reporter.onRunComplete browsers
expect(mockMkdir.callCount).to.equal 4
expect(mockMkdir.getCall(0).args[0]).to.deep.equal path.resolve('/base', 'reporter1', 'chrome')
expect(mockMkdir.getCall(1).args[0]).to.deep.equal path.resolve('/base', 'reporter1', 'opera')
expect(mockMkdir.getCall(2).args[0]).to.deep.equal path.resolve('/base', 'reporter2', 'CHROME')
expect(mockMkdir.getCall(3).args[0]).to.deep.equal path.resolve('/base', 'reporter2', 'OPERA')
mockMkdir.getCall(0).args[1]()
expect(mockReportCreate).to.have.been.called
expect(mockWriteReport).to.have.been.called

0 comments on commit 6db06ce

Please sign in to comment.