From 89c98177bc966ddadefa7c199f0e6c8f65622b73 Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Sun, 25 Aug 2013 16:47:16 -0700 Subject: [PATCH] fix: update to work with Karma 0.11 Since Karma executes immediately, we don't have all the browsers in advance, the reporter has to listen on browser_start instead. This re-introduces b744d6f2d01eb37b7160f5e82885e597132a167a but in a back-compatible way. --- lib/reporter.js | 16 ++++++++++++---- test/reporter.spec.coffee | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/reporter.js b/lib/reporter.js index 7e4385f..b1520de 100644 --- a/lib/reporter.js +++ b/lib/reporter.js @@ -64,10 +64,18 @@ var CoverageReporter = function(rootConfig, helper, logger) { } this.onRunStart = function(browsers) { - collectors = {}; - browsers.forEach(function(browser) { - collectors[browser.id] = new istanbul.Collector(); - }); + collectors = Object.create(null); + + // TODO(vojta): remove once we don't care about Karma 0.10 + if (browsers) { + browsers.forEach(function(browser) { + collectors[browser.id] = new istanbul.Collector(); + }); + } + }; + + this.onBrowserStart = function(browser) { + collectors[browser.id] = new istanbul.Collector(); }; this.onBrowserComplete = function(browser, result) { diff --git a/test/reporter.spec.coffee b/test/reporter.spec.coffee index 5f6623e..335a240 100644 --- a/test/reporter.spec.coffee +++ b/test/reporter.spec.coffee @@ -120,7 +120,8 @@ describe 'reporter', -> fakeOpera = makeBrowser 'bbb', 'Opera/9.80 Mac OS X Version/12.00', browsers, emitter browsers.add fakeChrome browsers.add fakeOpera - reporter.onRunStart browsers + reporter.onRunStart() + browsers.forEach (b) -> reporter.onBrowserStart b mockFs.writeFile.reset() mockMkdir.reset()