const incrementReporter = require('../lib/karma-plugin')['reporter:increment'][1];

describe('incrementReporter spec', () => {
  describe('export spec', () => {
    it('should export properly', () => {
      expect(incrementReporter).toBeDefined();
    });
    it('should export a function', () => {
      expect(typeof incrementReporter).toBe('function');
    });
  });

  describe('requirements spec', () => {
    describe('coverage reporter', () => {
      it('should throw error if no "coverage" reporter defined', () => {
        const config = {};
        expect(() => incrementReporter(config)).toThrow(new Error('coverage reporter should be used'));
        config.reporters = ['aaa'];
        expect(() => incrementReporter(config)).toThrow(new Error('coverage reporter should be used'));
      });
      it('should NOT throw error if "coverage" reporter defined', () => {
        const config = {reporters: ['coverage']};
        expect(() => incrementReporter(config)).not.toThrow(new Error('coverage reporter should be used'));
      });
    });
    describe('json-summary coverage-reporter', () => {
      const coverageReporter = { type: 'html' };
      const jsonSummaryReporter = { type: 'json-summary' };
      const config = {
        reporters: ['coverage'],
      };
      const errMsg = 'json-summary coverage-reporter should be used';

      it('should throw error if no "json-summary" coverage-reporter defined as main reporter', () => {
        config.coverageReporter = coverageReporter;
        expect(() => incrementReporter(config)).toThrow(new Error(errMsg));
      });
      it('should throw error if no "json-summary" coverage-reporter defined as a reporter in reporters array', () => {
        config.coverageReporter = {reporters: [coverageReporter]};
        expect(() => incrementReporter(config)).toThrow(new Error(errMsg));
      });
      it('should NOT throw error if "json-summary" coverage-reporter defined as main reporter', () => {
        config.coverageReporter = jsonSummaryReporter;
        expect(() => incrementReporter(config)).not.toThrow(new Error(errMsg));
      });
      it('should NOT throw error if "json-summary" coverage-reporter defined as a reporter in reporters array', () => {
        config.coverageReporter = {reporters: [coverageReporter, jsonSummaryReporter]};
        expect(() => incrementReporter(config)).not.toThrow(new Error(errMsg));
      });

    });
  });
});

@@ -80,51 +80,260 @@
 1%5D;%0A
-%0Adescribe('incrementReporter spec', () =%3E %7B
+const coverageUpdater = require('../lib/coverage-updater');%0A%0Adescribe('incrementReporter spec', () =%3E %7B%0A  const coverageReporter = 'coverage';%0A  const htmlCoverageReporter = %7Btype: 'html'%7D;%0A  const jsonSummaryCoverageReporter = %7Btype: 'json-summary'%7D;%0A
 %0A  d
@@ -1120,25 +1120,24 @@
 rters: %5B
-'
 coverage
 '%5D%7D;%0A   
@@ -1128,17 +1128,24 @@
 coverage
-'
+Reporter
 %5D%7D;%0A    
@@ -1325,117 +1325,8 @@
 %3E %7B%0A
-      const coverageReporter = %7B type: 'html' %7D;%0A      const jsonSummaryReporter = %7B type: 'json-summary' %7D;%0A
     
@@ -1364,25 +1364,24 @@
 rters: %5B
-'
 coverage
 '%5D,%0A    
@@ -1372,17 +1372,24 @@
 coverage
-'
+Reporter
 %5D,%0A     
@@ -1600,17 +1600,21 @@
 orter = 
-c
+htmlC
 overageR
@@ -1866,33 +1866,37 @@
  = %7Breporters: %5B
-c
+htmlC
 overageReporter%5D
@@ -2125,32 +2125,40 @@
 er = jsonSummary
+Coverage
 Reporter;%0A      
@@ -2400,33 +2400,37 @@
  = %7Breporters: %5B
-c
+htmlC
 overageReporter,
@@ -2441,16 +2441,24 @@
 nSummary
+Coverage
 Reporter
@@ -2551,16 +2551,867 @@
     %7D);%0A
+    %7D);%0A  %7D);%0A%0A  describe('use of coverageUpdater spec', () =%3E %7B%0A%0A    let config;%0A    const incrementConfigDefault = %7BisKarma: true%7D;%0A    const incrementConfig = %7Bflexibility: 0.3%7D;%0A%0A    beforeEach(() =%3E %7B%0A      spyOn(coverageUpdater, 'updateCodeCoverage');%0A      config = %7B%0A        reporters: %5BcoverageReporter%5D,%0A        coverageReporter: jsonSummaryCoverageReporter,%0A      %7D;%0A    %7D);%0A    it('should call updateCodeCoverage() with default config', () =%3E %7B%0A      incrementReporter(config);%0A      expect(coverageUpdater.updateCodeCoverage).toHaveBeenCalledWith(incrementConfigDefault);%0A    %7D);%0A    it('should call updateCodeCoverage()', () =%3E %7B%0A      config.incrementConfig = incrementConfig;%0A      incrementReporter(config);%0A      expect(coverageUpdater.updateCodeCoverage).toHaveBeenCalledWith(Object.assign(incrementConfig, incrementConfigDefault));
 %0A    %7D);

remove console