Skip to content
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

fix: watermarks are not handled correctly #145

Merged
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ var CoverageReporter = function(rootConfig, helper, logger) {
var sourceCache = globalSourceCache.getByBasePath(basePath);
var includeAllSources = config.includeAllSources === true;

if (config.watermarks) {
config.watermarks = helper.merge({}, istanbul.config.defaultConfig().reporting.watermarks, config.watermarks);
}

if (!helper.isDefined(reporters)) {
reporters = [config];
}
Expand Down Expand Up @@ -134,7 +138,7 @@ var CoverageReporter = function(rootConfig, helper, logger) {
reporterConfig.dir || config.dir,
reporterConfig.subdir || config.subdir)));
var _ = helper._;
var options = helper.merge({}, reporterConfig, {
var options = helper.merge({}, config, reporterConfig, {
dir : outputDir,
sourceStore : _.isEmpty(sourceCache) ? null : new SourceCacheStore({
sourceCache: sourceCache
Expand Down
61 changes: 61 additions & 0 deletions test/reporter.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,19 @@ describe 'reporter', ->
mockCoverageMap =
add: sinon.spy()
get: sinon.spy()
mockDefaultWatermarks =
statements: [50, 80]
branches: [50, 80]
functions: [50, 80]
lines: [50, 80]

mocks =
fs: mockFs
istanbul:
Store: mockStore
Collector: mockCollector
Report: create: mockReportCreate
config: defaultConfig: sinon.stub().returns(reporting: watermarks: mockDefaultWatermarks)
dateformat: require 'dateformat'
'./coverageMap': mockCoverageMap

Expand Down Expand Up @@ -294,3 +300,58 @@ describe 'reporter', ->
browsers.forEach (b) -> reporter.onBrowserStart b

expect(mockCoverageMap.get).not.to.have.been.called

it 'should pass watermarks to istanbul', ->
watermarks =
statements: [10, 20]
branches: [30, 40]
functions: [50, 60]
lines: [70, 80]

customConfig = _.merge {}, rootConfig,
coverageReporter:
reporters: [
{
dir: 'reporter1'
}
]
watermarks: watermarks

mockReportCreate.reset()

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

expect(mockReportCreate).to.have.been.called
options = mockReportCreate.getCall(0)
expect(options.args[1].watermarks).to.deep.equal(watermarks)

it 'should merge with istanbul default watermarks', ->
watermarks =
statements: [10, 20]
lines: [70, 80]

customConfig = _.merge {}, rootConfig,
coverageReporter:
reporters: [
{
dir: 'reporter1'
}
]
watermarks: watermarks

mockReportCreate.reset()

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

expect(mockReportCreate).to.have.been.called
options = mockReportCreate.getCall(0)
expect(options.args[1].watermarks.statements).to.deep.equal(watermarks.statements)
expect(options.args[1].watermarks.branches).to.deep.equal(mockDefaultWatermarks.branches)
expect(options.args[1].watermarks.functions).to.deep.equal(mockDefaultWatermarks.functions)
expect(options.args[1].watermarks.lines).to.deep.equal(watermarks.lines)