src/mochawesome.js
function Mochawesome(runner, options) {
  // Set the config options
  this.config = conf(options);

  // Reporter options
  const reporterOptions = Object.assign(
    {},
    (options.reporterOptions || {}),
    {
      reportFilename: this.config.reportFilename,
      saveHtml: this.config.saveHtml,
      saveJson: this.config.saveJson
    }
  );

  // Done function will be called before mocha exits
  // This is where we will save JSON and generate the HTML report
  this.done = (failures, exit) => done(
    this.output,
    reporterOptions,
    this.config,
    failures,
    exit
  );

  // Reset total tests counter
  totalTestsRegistered.total = 0;

  // Call the Base mocha reporter
  Base.call(this, runner);

  // Show the Spec Reporter in the console
  new Spec(runner); // eslint-disable-line

  let endCalled = false;

  // Add a unique identifier to each test/hook
  runner.on('test', test => {
    test.uuid = uuid.v4();
  });
  runner.on('hook', hook => {
    hook.uuid = uuid.v4();
  });
  runner.on('pending', test => {
    test.uuid = uuid.v4();
  });

  // Process the full suite
  runner.on('end', () => {
    try {
      /* istanbul ignore else */
      if (!endCalled) {
        // end gets called more than once for some reason
        // so we ensure the suite is processed only once
        endCalled = true;

        const allSuites = mapSuites(this.runner.suite, totalTestsRegistered, this.config);

        const obj = {
          stats: this.stats,
          suites: allSuites,
          copyrightYear: new Date().getFullYear()
        };

        obj.stats.testsRegistered = totalTestsRegistered.total;

        const { passes, failures, pending, tests, testsRegistered } = obj.stats;
        const passPercentage = Math.round((passes / (testsRegistered - pending)) * 1000) / 10;
        const pendingPercentage = Math.round((pending / testsRegistered) * 1000) /10;

        obj.stats.passPercent = passPercentage;
        obj.stats.pendingPercent = pendingPercentage;
        obj.stats.other = (passes + failures + pending) - tests;
        obj.stats.hasOther = obj.stats.other > 0;
        obj.stats.skipped = testsRegistered - tests;
        obj.stats.hasSkipped = obj.stats.skipped > 0;
        obj.stats.failures -= obj.stats.other;
        obj.stats.passPercentClass = getPercentClass(passPercentage);
        obj.stats.pendingPercentClass = getPercentClass(pendingPercentage);

        // Save the final output to be used in the done function
        this.output = obj;
      }
    } catch (e) {
      // required because thrown errors are not handled directly in the
      // event emitter pattern and mocha does not have an "on error"
      /* istanbul ignore next */
      log(`Problem with mochawesome: ${e.stack}`, 'error');
    }
  });
}
function Mochawesome(runner, options) {
  // Set the config options
  this.config = conf(options);

  // Reporter options
  const reporterOptions = Object.assign(
    {},
    (options.reporterOptions || {}),
    {
      reportFilename: this.config.reportFilename,
      saveHtml: this.config.saveHtml,
      saveJson: this.config.saveJson
    }
  );

  // Done function will be called before mocha exits
  // This is where we will save JSON and generate the HTML report
  this.done = (failures, exit) => done(
    this.output,
    reporterOptions,
    this.config,
    failures,
    exit
  );

  // Reset total tests counter
  totalTestsRegistered.total = 0;

  // Call the Base mocha reporter
  Base.call(this, runner);

  // Show the Spec Reporter in the console
  new Spec(runner); // eslint-disable-line

  let endCalled = false;

  // Add a unique identifier to each test/hook
  runner.on('test', test => {
    test.uuid = uuid.v4();
  });
  runner.on('hook', hook => {
    hook.uuid = uuid.v4();
  });
  runner.on('pending', test => {
    test.uuid = uuid.v4();
  });

  // Process the full suite
  runner.on('end', () => {
    try {
      /* istanbul ignore else */
      if (!endCalled) {
        // end gets called more than once for some reason
        // so we ensure the suite is processed only once
        endCalled = true;

        const allSuites = mapSuites(this.runner.suite, totalTestsRegistered, this.config);

        const obj = {
          stats: this.stats,
          suites: allSuites,
          copyrightYear: new Date().getFullYear()
        };

        obj.stats.testsRegistered = totalTestsRegistered.total;

        const { passes, failures, pending, tests, testsRegistered } = obj.stats;
        const passPercentage = Math.round((passes / (testsRegistered - pending)) * 1000) / 10;
        const pendingPercentage = Math.round((pending / testsRegistered) * 1000) /10;

        obj.stats.passPercent = passPercentage;
        obj.stats.pendingPercent = pendingPercentage;
        obj.stats.other = (passes + failures + pending) - tests;
        obj.stats.hasOther = obj.stats.other > 0;
        obj.stats.skipped = testsRegistered - tests;
        obj.stats.hasSkipped = obj.stats.skipped > 0;
        obj.stats.failures -= obj.stats.other;
        obj.stats.passPercentClass = getPercentClass(passPercentage);
        obj.stats.pendingPercentClass = getPercentClass(pendingPercentage);

        // Save the final output to be used in the done function
        this.output = obj;
      }
    } catch (e) {
      // required because thrown errors are not handled directly in the
      // event emitter pattern and mocha does not have an "on error"
      /* istanbul ignore next */
      log(`Problem with mochawesome: ${e.stack}`, 'error');
    }
  });
}
function Mochawesome ( runner , options ) { // Set the config options this . config = conf ( options ) ; // Reporter options const reporterOptions = Object . assign ( { } , ( options . reporterOptions || { } ) , { reportFilename : this . config . reportFilename , saveHtml : this . config . saveHtml , saveJson : this . config . saveJson } ) ; // Done function will be called before mocha exits // This is where we will save JSON and generate the HTML report this . done = ( failures , exit ) => done ( this . output , reporterOptions , this . config , failures , exit ) ; // Reset total tests counter totalTestsRegistered . total = 0 ; // Call the Base mocha reporter Base . call ( this , runner ) ; // Show the Spec Reporter in the console new Spec ( runner ) ; // eslint-disable-line let endCalled = false ; // Add a unique identifier to each test/hook runner . on ( 'test' , test => { test . uuid = uuid . v4 ( ) ; } ) ; runner . on ( 'hook' , hook => { hook . uuid = uuid . v4 ( ) ; } ) ; runner . on ( 'pending' , test => { test . uuid = uuid . v4 ( ) ; } ) ; // Process the full suite runner . on ( 'end' , ( ) => { try { /* istanbul ignore else */ if ( ! endCalled ) { // end gets called more than once for some reason // so we ensure the suite is processed only once endCalled = true ; const allSuites = mapSuites ( this . runner . suite , totalTestsRegistered , this . config ) ; const obj = { stats : this . stats , suites : allSuites , copyrightYear : new Date ( ) . getFullYear ( ) } ; obj . stats . testsRegistered = totalTestsRegistered . total ; const { passes , failures , pending , tests , testsRegistered } = obj . stats ; const passPercentage = Math . round ( ( passes / ( testsRegistered - pending ) ) * 1000 ) / 10 ; const pendingPercentage = Math . round ( ( pending / testsRegistered ) * 1000 ) / 10 ; obj . stats . passPercent = passPercentage ; obj . stats . pendingPercent = pendingPercentage ; obj . stats . other = ( passes + failures + pending ) - tests ; obj . stats . hasOther = obj . stats . other > 0 ; obj . stats . skipped = testsRegistered - tests ; obj . stats . hasSkipped = obj . stats . skipped > 0 ; obj . stats . failures -= obj . stats . other ; obj . stats . passPercentClass = getPercentClass ( passPercentage ) ; obj . stats . pendingPercentClass = getPercentClass ( pendingPercentage ) ; // Save the final output to be used in the done function this . output = obj ; } } catch ( e ) { // required because thrown errors are not handled directly in the // event emitter pattern and mocha does not have an "on error" /* istanbul ignore next */ log ( ` ${ e . stack } ` , 'error' ) ; } } ) ; }
Initialize a new reporter.

@param {Runner} runner
@api public
Initialize a new reporter .