<commit_before>var _ = require('lodash');
var xmlBuilder = require('xmlbuilder');
var path = require('path');
var mkdirp = require('mkdirp');
var fs = require('fs');
var TestSuite = require('./test_suite');
var TestCase = require('./test_case');

function JUnitReportBuilder(factory) {
  this._factory = factory;
  this._testSuitesAndCases = [];
}

JUnitReportBuilder.prototype.writeTo = function (reportPath) {
  mkdirp.sync(path.dirname(reportPath));
  fs.writeFileSync(reportPath, this.build(), 'utf8');
};

JUnitReportBuilder.prototype.build = function () {
  var xmlTree = xmlBuilder.create('testsuites', { encoding: 'UTF-8' });
  _.forEach(this._testSuitesAndCases, function (suiteOrCase) {
    suiteOrCase.build(xmlTree);
  });
  return xmlTree.end({ pretty: true });
};

JUnitReportBuilder.prototype.testSuite = function () {
  var suite = this._factory.newTestSuite();
  this._testSuitesAndCases.push(suite);
  return suite;
};

JUnitReportBuilder.prototype.testCase = function () {
  var testCase = this._factory.newTestCase();
  this._testSuitesAndCases.push(testCase);
  return testCase;
};

JUnitReportBuilder.prototype.newBuilder = function () {
  return this._factory.newBuilder();
};

module.exports = JUnitReportBuilder;<commit_msg>Enable emoji encoding<commit_after>var _ = require('lodash');
var xmlBuilder = require('xmlbuilder');
var path = require('path');
var mkdirp = require('mkdirp');
var fs = require('fs');
var TestSuite = require('./test_suite');
var TestCase = require('./test_case');

function JUnitReportBuilder(factory) {
  this._factory = factory;
  this._testSuitesAndCases = [];
}

JUnitReportBuilder.prototype.writeTo = function (reportPath) {
  mkdirp.sync(path.dirname(reportPath));
  fs.writeFileSync(reportPath, this.build(), 'utf8');
};

JUnitReportBuilder.prototype.build = function () {
  var xmlTree = xmlBuilder.create('testsuites', { encoding: 'UTF-8', allowSurrogateChars: true });
  _.forEach(this._testSuitesAndCases, function (suiteOrCase) {
    suiteOrCase.build(xmlTree);
  });
  return xmlTree.end({ pretty: true });
};

JUnitReportBuilder.prototype.testSuite = function () {
  var suite = this._factory.newTestSuite();
  this._testSuitesAndCases.push(suite);
  return suite;
};

JUnitReportBuilder.prototype.testCase = function () {
  var testCase = this._factory.newTestCase();
  this._testSuitesAndCases.push(testCase);
  return testCase;
};

JUnitReportBuilder.prototype.newBuilder = function () {
  return this._factory.newBuilder();
};

module.exports = JUnitReportBuilder;
{'fraction_non_alphanumeric': 0.1476510067114094, 'fraction_numerical': 0.0015791551519936833, 'mean_word_length': 5.686015831134565, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '2795479', 'n_tokens_mistral': 794, 'n_tokens_neox': 793, 'n_words': 141}