<commit_before>/* global Mocha */
var allTestFiles = [];
var TEST_REGEXP = /tests(?:\/.*)?\/.*[-_]test\.js$/i;
// We need to exclude wed_test.js.
var WED_REGEXP = /\/wed_test\.js$/i;

// Get a list of all the test files to include.
Object.keys(window.__karma__.files).forEach(function each(file) {
  "use strict";
  if (TEST_REGEXP.test(file) && !WED_REGEXP.test(file)) {
    var normalizedTestModule =
        file.replace(/^\/base\/build\/standalone\/lib\/|\.js$/g, "");
    allTestFiles.push(normalizedTestModule);
  }
});

// Chai is already loaded.
define("chai", function factory() {
  "use strict";
  return window.chai;
});

// This turns on logic used only in testing.
window.__WED_TESTING = {
  testing: true,
};

require.config({
  baseUrl: "/base/build/standalone/lib/",
  paths: {
    sinon: "../../../node_modules/sinon/pkg/sinon",
    "sinon-chai": "../../../node_modules/sinon-chai/lib/sinon-chai",
    "blueimp-md5": "../../../node_modules/blueimp-md5/js/md5",
    qs: "../../../node_modules/qs/dist/qs",
  },
  map: {
    "*": {
      "tests/dloc_test_data/source_converted.xml": "text!tests/dloc_test_data/source_converted.xml",
      "tests/guiroot_test_data/source_converted.xml": "text!tests/guiroot_test_data/source_converted.xml",
      "tests/tree_updater_test_data/source_converted.xml": "text!tests/tree_updater_test_data/source_converted.xml",
    },
  },
});

require(
  ["require", "last-resort", "wed/onerror"],
  function loaded(require, lr, onerror) {
    "use strict";

    before(function before() {
      // We need to do this in a before hook because the listener is not added
      // until Mocha starts.
      Mocha.process.removeListener("uncaughtException");
      // We also have to eradicate Karma's on error handler.
      window.onerror = undefined;
    });

    beforeEach(function beforeEach() {
      // We want to reinstall with each test so that the state of the onError
      // object is fresh.
      var onError = lr.install(window, { force: true });
      onError.register(onerror.handler);
    });

    // The effect of the beforeEach handler above is to overwrite Mocha's
    // default unhandled exception handler. So we want to perform our on check
    // after each test.
    afterEach(function afterEach() {
      if (onerror.is_terminating()) {
        this.test.error(new Error("test generated an uncaught exception"));
      }
    });

    require(allTestFiles, window.__karma__.start);
  });<commit_msg>Improve the global afterEach check.<commit_after>/* global Mocha */
var allTestFiles = [];
var TEST_REGEXP = /tests(?:\/.*)?\/.*[-_]test\.js$/i;
// We need to exclude wed_test.js.
var WED_REGEXP = /\/wed_test\.js$/i;

// Get a list of all the test files to include.
Object.keys(window.__karma__.files).forEach(function each(file) {
  "use strict";
  if (TEST_REGEXP.test(file) && !WED_REGEXP.test(file)) {
    var normalizedTestModule =
        file.replace(/^\/base\/build\/standalone\/lib\/|\.js$/g, "");
    allTestFiles.push(normalizedTestModule);
  }
});

// Chai is already loaded.
define("chai", function factory() {
  "use strict";
  return window.chai;
});

// This turns on logic used only in testing.
window.__WED_TESTING = {
  testing: true,
};

require.config({
  baseUrl: "/base/build/standalone/lib/",
  paths: {
    sinon: "../../../node_modules/sinon/pkg/sinon",
    "sinon-chai": "../../../node_modules/sinon-chai/lib/sinon-chai",
    "blueimp-md5": "../../../node_modules/blueimp-md5/js/md5",
    qs: "../../../node_modules/qs/dist/qs",
  },
  map: {
    "*": {
      "tests/dloc_test_data/source_converted.xml": "text!tests/dloc_test_data/source_converted.xml",
      "tests/guiroot_test_data/source_converted.xml": "text!tests/guiroot_test_data/source_converted.xml",
      "tests/tree_updater_test_data/source_converted.xml": "text!tests/tree_updater_test_data/source_converted.xml",
    },
  },
});

require(
  ["require", "last-resort", "wed/onerror"],
  function loaded(require, lr, onerror) {
    "use strict";

    before(function before() {
      // We need to do this in a before hook because the listener is not added
      // until Mocha starts.
      Mocha.process.removeListener("uncaughtException");
      // We also have to eradicate Karma's on error handler.
      window.onerror = undefined;
    });

    beforeEach(function beforeEach() {
      // We want to reinstall with each test so that the state of the onError
      // object is fresh.
      var onError = lr.install(window, { force: true });
      onError.register(onerror.handler);
    });

    // The effect of the beforeEach handler above is to overwrite Mocha's
    // default unhandled exception handler. So we want to perform our on check
    // after each test.
    afterEach(function afterEach() {
      // We read the state, reset, and do the assertion later so that if the
      // assertion fails, we still have our reset.
      var wasTerminating = onerror.is_terminating();

      // We don't reload our page so we need to do this.
      onerror.__test.reset();

      if (wasTerminating) {
        throw new Error("test caused an unhandled exception to occur");
      }
    });

    require(allTestFiles, window.__karma__.start);
  });
{'fraction_non_alphanumeric': 0.15387567152724482, 'fraction_numerical': 0.0011511895625479663, 'mean_word_length': 2.96425855513308, 'pattern_counts': {'":': 12, '<': 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': '5489018', 'n_tokens_mistral': 1723, 'n_tokens_neox': 1695, 'n_words': 409}