diff --git a/lib/in-memory-report.js b/lib/in-memory-report.js index dd50409..f938c6a 100644 --- a/lib/in-memory-report.js +++ b/lib/in-memory-report.js @@ -1,11 +1,18 @@ +var Report = require('istanbul').Report +var util = require('util') function InMemoryReport (opt) { - this.browser = opt.browser - this.emitter = opt.emitter + this.opt = opt } +util.inherits(InMemoryReport, Report) + InMemoryReport.prototype.writeReport = function (collector, sync) { - this.emitter.emit('coverage_complete', this.browser, collector.getFinalCoverage()) + if (!this.opt.emitter || !this.opt.emitter.emit) { + console.error('Could not raise "coverage_complete" event, missing emitter because it was not supplied during initialization of the reporter') + } else { + this.opt.emitter.emit('coverage_complete', this.opt.browser, collector.getFinalCoverage()) + } } InMemoryReport.TYPE = 'in-memory' diff --git a/test/in-memory-report.spec.coffee b/test/in-memory-report.spec.coffee index 90213bc..01e4a7d 100644 --- a/test/in-memory-report.spec.coffee +++ b/test/in-memory-report.spec.coffee @@ -1,4 +1,5 @@ InMemoryReport = require '../lib/in-memory-report' +istanbul = require 'istanbul'; describe 'InMemoryReport', -> @@ -17,3 +18,9 @@ describe 'InMemoryReport', -> it 'should be of type "in-memory"', -> expect(InMemoryReport.TYPE).to.be.equal('in-memory') + + it 'should not fail when created without arguments', -> + expect(new InMemoryReport()).to.be.ok + + it 'should inherit from Report', -> + expect(new InMemoryReport()).to.be.an.instanceof(istanbul.Report) \ No newline at end of file