<commit_before>var fs = require('fs');
var xmlbuilder = require('xmlbuilder');

function getTestMeta(browser, test) {
  var meta = {
    'name': test.test[test.test.length -1],
    'method': '',
    'type': test.test[0]
  };
  var path = [];
  for (i = 1; i < test.test.length; i++) {
    path.push(test.test[i]);
  }
  meta.method = path.join('.');
  return meta;
}

function getDate() {
  now = new Date();
  var year = "" + now.getFullYear();
  var month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
  var day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
  return year + "-" + month + "-" + day;
}

function getTime() {
  now = new Date();
  var hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
  var minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
  var second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
  return hour + ":" + minute + ":" + second;
}

module.exports = function(wct, pluginOptions) {
  var xml = xmlbuilder.create('assemblies', {version: '1.0', encoding: 'UTF-8'});
  var assembly;
  var collection;
  var currentTest;

  wct.on('browser-start', function(browser, data, stats) {
    assembly = xml.ele('assembly', {
      'name': 'WCT Unit tests [' + browser.browserName + '.' + browser.version + ']',
      'environment': browser.browserName + '.' + browser.version,
      'test-framework': 'web-component-tester',
      'run-date': getDate(),
      'run-time': getTime()
    });
  }.bind(this));

  wct.on('sub-suite-start', function(browser, sharedState, stats) {
    collection = assembly.ele('collection');
  }.bind(this));

  wct.on('sub-suite-end', function(browser, sharedState, stats) {
    collection.att('passed', stats.passing);
    collection.att('failed', stats.failing);
    collection.att('skipped', stats.pending);
  }.bind(this));

  wct.on('test-end', function(browser, test) {
    var meta = getTestMeta(browser, test);
    currentTest = collection.ele('test');
    currentTest.att('name', meta.name);
    currentTest.att('method', meta.method);
    currentTest.att('type', meta.type);

    if(test.state === 'pending') {
      currentTest.att('result', 'Skip');
      return;
    } else if(test.state === 'failing') {
      currentTest.att('result', 'Fail');<commit_msg>Current test variable is only used in test-end<commit_after>var fs = require('fs');
var xmlbuilder = require('xmlbuilder');

function getTestMeta(browser, test) {
  var meta = {
    'name': test.test[test.test.length -1],
    'method': '',
    'type': test.test[0]
  };
  var path = [];
  for (i = 1; i < test.test.length; i++) {
    path.push(test.test[i]);
  }
  meta.method = path.join('.');
  return meta;
}

function getDate() {
  now = new Date();
  var year = "" + now.getFullYear();
  var month = "" + (now.getMonth() + 1); if (month.length == 1) { month = "0" + month; }
  var day = "" + now.getDate(); if (day.length == 1) { day = "0" + day; }
  return year + "-" + month + "-" + day;
}

function getTime() {
  now = new Date();
  var hour = "" + now.getHours(); if (hour.length == 1) { hour = "0" + hour; }
  var minute = "" + now.getMinutes(); if (minute.length == 1) { minute = "0" + minute; }
  var second = "" + now.getSeconds(); if (second.length == 1) { second = "0" + second; }
  return hour + ":" + minute + ":" + second;
}

module.exports = function(wct, pluginOptions) {
  var xml = xmlbuilder.create('assemblies', {version: '1.0', encoding: 'UTF-8'});
  var assembly;
  var collection;

  wct.on('browser-start', function(browser, data, stats) {
    assembly = xml.ele('assembly', {
      'name': 'WCT Unit tests [' + browser.browserName + '.' + browser.version + ']',
      'environment': browser.browserName + '.' + browser.version,
      'test-framework': 'web-component-tester',
      'run-date': getDate(),
      'run-time': getTime()
    });
  }.bind(this));

  wct.on('sub-suite-start', function(browser, sharedState, stats) {
    collection = assembly.ele('collection');
  }.bind(this));

  wct.on('sub-suite-end', function(browser, sharedState, stats) {
    collection.att('passed', stats.passing);
    collection.att('failed', stats.failing);
    collection.att('skipped', stats.pending);
  }.bind(this));

  wct.on('test-end', function(browser, test) {
    var meta = getTestMeta(browser, test);
    var currentTest = collection.ele('test');
    currentTest.att('name', meta.name);
    currentTest.att('method', meta.method);
    currentTest.att('type', meta.type);

    if(test.state === 'pending') {
      currentTest.att('result', 'Skip');
      return;
    } else if(test.state === 'failing') {
      currentTest.att('result', 'Fail');
{'fraction_non_alphanumeric': 0.20567075751163774, 'fraction_numerical': 0.007194244604316547, 'mean_word_length': 3.393122676579926, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '6762196', 'n_tokens_mistral': 1627, 'n_tokens_neox': 1596, 'n_words': 361}