index.js
function MochaJUnitReporter(runner, options) {
  this._options = configureDefaults(options);
  this._runner = runner;
  this._generateSuiteTitle = this._options.useFullSuiteTitle ? fullSuiteTitle : defaultSuiteTitle;
  this._antId = 0;

  var testsuites = [];

  function lastSuite() {
    return testsuites[testsuites.length - 1].testsuite;
  }

  // get functionality from the Base reporter
  Base.call(this, runner);

  // remove old results
  this._runner.on('start', function() {
    if (fs.existsSync(this._options.mochaFile)) {
      debug('removing report file', this._options.mochaFile);
      fs.unlinkSync(this._options.mochaFile);
    }
  }.bind(this));

  this._runner.on('suite', function(suite) {
    if (!isInvalidSuite(suite)) {
      testsuites.push(this.getTestsuiteData(suite));
    }
  }.bind(this));

  this._runner.on('pass', function(test) {
    lastSuite().push(this.getTestcaseData(test));
  }.bind(this));

  this._runner.on('fail', function(test, err) {
    lastSuite().push(this.getTestcaseData(test, err));
  }.bind(this));

  if (this._options.includePending) {
    this._runner.on('pending', function(test) {
      var testcase = this.getTestcaseData(test);

      testcase.testcase.push({ skipped: null });
      lastSuite().push(testcase);
    }.bind(this));
  }

  this._runner.on('end', function(){
    this.flush(testsuites);
  }.bind(this));
}
function MochaJUnitReporter(runner, options) {
  this._options = configureDefaults(options);
  this._runner = runner;
  this._generateSuiteTitle = this._options.useFullSuiteTitle ? fullSuiteTitle : defaultSuiteTitle;
  this._antId = 0;

  var testsuites = [];

  function lastSuite() {
    return testsuites[testsuites.length - 1].testsuite;
  }

  // get functionality from the Base reporter
  Base.call(this, runner);

  // remove old results
  this._runner.on('start', function() {
    if (fs.existsSync(this._options.mochaFile)) {
      debug('removing report file', this._options.mochaFile);
      fs.unlinkSync(this._options.mochaFile);
    }
  }.bind(this));

  this._runner.on('suite', function(suite) {
    if (!isInvalidSuite(suite)) {
      testsuites.push(this.getTestsuiteData(suite));
    }
  }.bind(this));

  this._runner.on('pass', function(test) {
    lastSuite().push(this.getTestcaseData(test));
  }.bind(this));

  this._runner.on('fail', function(test, err) {
    lastSuite().push(this.getTestcaseData(test, err));
  }.bind(this));

  if (this._options.includePending) {
    this._runner.on('pending', function(test) {
      var testcase = this.getTestcaseData(test);

      testcase.testcase.push({ skipped: null });
      lastSuite().push(testcase);
    }.bind(this));
  }

  this._runner.on('end', function(){
    this.flush(testsuites);
  }.bind(this));
}
function MochaJUnitReporter ( runner , options ) { this . _options = configureDefaults ( options ) ; this . _runner = runner ; this . _generateSuiteTitle = this . _options . useFullSuiteTitle ? fullSuiteTitle : defaultSuiteTitle ; this . _antId = 0 ; var testsuites = [ ] ; function lastSuite ( ) { return testsuites [ testsuites . length - 1 ] . testsuite ; } // get functionality from the Base reporter Base . call ( this , runner ) ; // remove old results this . _runner . on ( 'start' , function ( ) { if ( fs . existsSync ( this . _options . mochaFile ) ) { debug ( 'removing report file' , this . _options . mochaFile ) ; fs . unlinkSync ( this . _options . mochaFile ) ; } } . bind ( this ) ) ; this . _runner . on ( 'suite' , function ( suite ) { if ( ! isInvalidSuite ( suite ) ) { testsuites . push ( this . getTestsuiteData ( suite ) ) ; } } . bind ( this ) ) ; this . _runner . on ( 'pass' , function ( test ) { lastSuite ( ) . push ( this . getTestcaseData ( test ) ) ; } . bind ( this ) ) ; this . _runner . on ( 'fail' , function ( test , err ) { lastSuite ( ) . push ( this . getTestcaseData ( test , err ) ) ; } . bind ( this ) ) ; if ( this . _options . includePending ) { this . _runner . on ( 'pending' , function ( test ) { var testcase = this . getTestcaseData ( test ) ; testcase . testcase . push ( { skipped : null } ) ; lastSuite ( ) . push ( testcase ) ; } . bind ( this ) ) ; } this . _runner . on ( 'end' , function ( ) { this . flush ( testsuites ) ; } . bind ( this ) ) ; }
JUnit reporter for mocha.js.
@module mocha-junit-reporter
@param {EventEmitter} runner - the test runner
@param {Object} options - mocha options
JUnit reporter for mocha . js .