<commit_before>var fs  = require('fs');
var sys = require('sys')
var ansi = require('jessie/ansi').ansi

exports.reporter = function(format, callback) {
  format = format || 'progress'
  this.callback = callback
  try {
    this.formatter = require('jessie/formatters/' + format).formatter
  } catch(e) {
    sys.puts(ansi.red + "Failed to load " + format + " formatter. Defaulting to progress formatter" + ansi.none)
    this.formatter = require('jessie/formatters/progress').formatter
  }
  var formatter = this.formatter
  this.formatter.reporter = this;  
}

// Wrapper around the formatter to log
exports.reporter.prototype.log    = function(suite)  { 
  if (this.formatter.log)
    this.formatter.log() 
}

// Wrapper around the formatter to render spec starting
exports.reporter.prototype.reportSpecStarting    = function(spec)  { 
  if (this.formatter.specStart)
    this.formatter.specStart(spec) 
  if (this.formatter.reportSpecStarting)
    this.formatter.reportSpecStarting(spec)
};

// Wrapper around the formatter to render suite starting
exports.reporter.prototype.reportSuiteStarting   = function(suite)  { 
  if (this.formatter.suiteStart)
    this.formatter.suiteStart(suite) 
  if (this.formatter.reportSuiteResults)
    this.formatter.reportSuiteResults(suite) 
};

// Wrapper around the formatter to render runner starting
exports.reporter.prototype.reportRunnerStarting  = function(runner) {
  this.start_time = Number(new Date)
  if (this.formatter.start)
    this.formatter.start()
  if (this.formatter.reportRunnerStarting)
    this.formatter.reportRunnerStarting(runner) 
}

// Wrapper around the formatter to render single spec results
exports.reporter.prototype.reportSpecResults   = function(spec) {
  if (this.formatter.spec) {
    var result = {
      fail: spec.results().failedCount > 0
    }
    this.formatter.spec(result, spec)
  }
  if (this.formatter.reportSpecResults)
    this.formatter.reportSpecResults(spec) 
}

// Wrapper around the formatter to render suite results starting
exports.reporter.prototype.reportSuiteResults  = function(suite) {
  if (this.formatter.suite)
    this.formatter.suite({}, suite) 
  if (this.formatter.reportSuiteResults)
    this.formatter.reportSuiteResults(suite) 
}

// Wrapper around the formatter to render run results
// Extracts useful info before passing it to the formatter
// Additionally, call the finish callback of present
exports.reporter.prototype.reportRunnerResults = function(runner) {
  var results = runner.results();    
  var result = {
    failures: this.extractFailures(runner),
    total: results.totalCount
  }
  result.duration = (Number(new Date) - this.start_time)
  result.failed = result.failures.length
  
  if (this.formatter.finish)
    this.formatter.finish(result, runner); 
  if (this.formatter.reportRunnerResults)
    this.formatter.reportRunnerResults(runner); <commit_msg>Corrected reported to return the correct number of specs<commit_after>var fs  = require('fs');
var sys = require('sys')
var ansi = require('jessie/ansi').ansi

exports.reporter = function(format, callback) {
  format = format || 'progress'
  this.callback = callback
  try {
    this.formatter = require('jessie/formatters/' + format).formatter
  } catch(e) {
    sys.puts(ansi.red + "Failed to load " + format + " formatter. Defaulting to progress formatter" + ansi.none)
    this.formatter = require('jessie/formatters/progress').formatter
  }
  var formatter = this.formatter
  this.formatter.reporter = this;  
}

// Wrapper around the formatter to log
exports.reporter.prototype.log    = function(suite)  { 
  if (this.formatter.log)
    this.formatter.log() 
}

// Wrapper around the formatter to render spec starting
exports.reporter.prototype.reportSpecStarting    = function(spec)  { 
  if (this.formatter.specStart)
    this.formatter.specStart(spec) 
  if (this.formatter.reportSpecStarting)
    this.formatter.reportSpecStarting(spec)
};

// Wrapper around the formatter to render suite starting
exports.reporter.prototype.reportSuiteStarting   = function(suite)  { 
  if (this.formatter.suiteStart)
    this.formatter.suiteStart(suite) 
  if (this.formatter.reportSuiteResults)
    this.formatter.reportSuiteResults(suite) 
};

// Wrapper around the formatter to render runner starting
exports.reporter.prototype.reportRunnerStarting  = function(runner) {
  this.start_time = Number(new Date)
  if (this.formatter.start)
    this.formatter.start()
  if (this.formatter.reportRunnerStarting)
    this.formatter.reportRunnerStarting(runner) 
}

// Wrapper around the formatter to render single spec results
exports.reporter.prototype.reportSpecResults   = function(spec) {
  if (this.formatter.spec) {
    var result = {
      fail: spec.results().failedCount > 0
    }
    this.formatter.spec(result, spec)
  }
  if (this.formatter.reportSpecResults)
    this.formatter.reportSpecResults(spec) 
}

// Wrapper around the formatter to render suite results starting
exports.reporter.prototype.reportSuiteResults  = function(suite) {
  if (this.formatter.suite)
    this.formatter.suite({}, suite) 
  if (this.formatter.reportSuiteResults)
    this.formatter.reportSuiteResults(suite) 
}

// Wrapper around the formatter to render run results
// Extracts useful info before passing it to the formatter
// Additionally, call the finish callback of present
exports.reporter.prototype.reportRunnerResults = function(runner) {
  var results = runner.results();    
  var suites = runner.suites();
  var result = {
    failures: this.extractFailures(runner),
  }
  result.total = 0
  suites.forEach(function(suite) {
    result.total += suite.specs().length
  });
  result.duration = (Number(new Date) - this.start_time)
  result.failed = result.failures.length
  
  if (this.formatter.finish)
    this.formatter.finish(result, runner); 
  if (this.formatter.reportRunnerResults)
    this.formatter.reportRunnerResults(runner); 
{'fraction_non_alphanumeric': 0.10784313725490197, 'fraction_numerical': 0.0005070993914807302, 'mean_word_length': 4.087704213241617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3477230', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1724, 'n_words': 396}