<commit_before>(function(window) {
  var formatError = function (error) {
    var stack = error.stack;
    var message = error.message;

    if (stack) {
      if (message && stack.indexOf(message) === -1) {
        stack = message + '\n' + stack
      }
      return stack;
    }

    return message;
  };

  var createQooxdooStartFn = function(tc) {

    return function () {

      var suiteResults = {};
      var totalTests;
      var testCount;

      var getTestList = function(testDesc) {
        var list = [];
        testDesc.forEach(function(testClass) {
          list = list.concat(testClass.tests);
        });
        return list;
      };

      var addListeners = function(testResult) {
        testResult.addListener("startTest", function(e) {
          var testName = e.getData().getFullName();
          // if we aready have a result, this is a resumed async test
          if (!suiteResults[testName]) {
            suiteResults[testName] = {
              startTime: Date.now(),
              exceptions: []
            };
          }
          suiteResults[testName].status = "startTest";
        });

        testResult.addListener("failure", function(e) {
          e.getData().forEach(function(errMap) {
            var suiteResult = suiteResults[errMap.test.getFullName()];
            suiteResult.status = "failure";
            suiteResult.exceptions.push(formatError(errMap.exception));
          });
        });

        testResult.addListener("error", function(e) {
          e.getData().forEach(function(errMap) {
            window.console.warn(errMap.test.getFullName() + " : Unexpected exception");

            var suiteResult = suiteResults[errMap.test.getFullName()];
            suiteResult.status = "error";
            suiteResult.exceptions.push(errMap.exception);
          });
        });

        testResult.addListener("skip", function(e) {
          e.getData().forEach(function(errMap) {
            window.console.warn(errMap.test.getFullName() + " skipped: " + errMap.exception.toString());

            var suiteResult = suiteResults[errMap.test.getFullName()];
            suiteResult.status = "skip";
            suiteResult.exceptions.push(errMap.exception);
          });
        });

        testResult.addListener("wait", function(e) {
          var testName = e.getData().getFullName();

          //window.console.debug(testName + " wait");
          suiteResults[testName].status = "wait";
        });

        testResult.addListener("endTest", function(e) {
          testCount--;
          var testName = e.getData().getFullName();
          //window.console.debug(testName, "endTest");

          var suiteResult = suiteResults[testName];

          var log = suiteResult.exceptions.map(function(ex) {
            return ex.toString();
          });

          var suite, description;
          var match = /(.*?)\.([a-zA-Z]+:.*)/.exec(testName);
          if (match) {
            suite = [match[1]];
            description = match[2];
          } else {
            suite = [];
            description = testName;
          }

          var result = {
            id : (totalTests-testCount),
            description: description,
            suite: suite,
            success: (suiteResult.status == "startTest"),
            skipped: suiteResult.status == "skip",
            log: log,
            time: Date.now() - suiteResult.startTime
          };

          tc.result(result);
          if (testCount == 0) {
            tc.info({ total: totalTests });
            tc.complete({
              coverage: window.__coverage__
            });
          }
        });
      };

      window.onload = function() {
        qx.event.Timer.once(function() {
          var loader = qx.core.Init.getApplication();

          var testDesc = JSON.parse(loader.getTestDescriptions());

          var testList = getTestList(testDesc);
          totalTests = testCount = testList.length;
          tc.info({total: totalTests});

          var testResult = new qx.dev.unit.TestResult();
          addListeners(testResult);
          loader.getSuite().runAsync(testResult);
        }, this, 0);
      };
    };
  };

  window.__karma__.start = createQooxdooStartFn(window.__karma__);

})(window);<commit_msg>format stacktraces + run all tests sequentially<commit_after>
(function(window) {
  var parser = window.document.createElement("a");

  var formatError = function (error) {
    var stack = error.stack;
    var message = error.message;

    if (stack) {
      var trace = [];
      var lines = stack.split("\n");
      if (message && stack.indexOf(message) === -1) {
        trace.push(message.trim());
      }
      lines.forEach(function(line, i) {
        var parts = /^[\t\s]*at\s([^\(]+)\s\((.+)\)$/.exec(line);
        if (!parts) {
          trace.push(line);
          return;
        }
        var errorLine = "\tat "+parts[1];

        if (parts[2].indexOf("/") > -1) {
          // strip down url
          var sourceLine = /^(.+):([0-9]+):([0-9]+)$/.exec(parts[2]);
          var urlString = sourceLine ? sourceLine[1] : parts[2];

          parser.href = urlString;
          errorLine += " -> " + parser.pathname.substring(1);
          if (sourceLine.length === 4 && sourceLine[2]) {
            errorLine += ":" + sourceLine[2]+":"+sourceLine[3];
          }
        } else {
          errorLine += " -> ("+parts[2]+")";
        }
        trace.push(errorLine);
      });

      return trace.join("\n");
    }
    return message;
  };

  var createQooxdooStartFn = function(tc) {

    return function () {

      var suiteResults = {};
      var totalTests;
      var testCount;
      var testList = [];
      var testResult;

      var getTestList = function(testDesc) {
        var list = [];
        testDesc.forEach(function(testClass) {
          list = list.concat(testClass.tests);
        });
        return list;
      };

      var runNext = function() {
        var currentTest = testList.shift();

        setTimeout(function() {
            currentTest.run(testResult);
        }, 0);
      }.bind(this);

      var addListeners = function(testResult) {
        testResult.addListener("startTest", function(e) {
          var testName = e.getData().getFullName();
          // if we aready have a result, this is a resumed async test
          if (!suiteResults[testName]) {
            suiteResults[testName] = {
              startTime: Date.now(),
              exceptions: []
            };
          } else if (suiteResults[testName].status !== "wait") {
            // test was executed before, clear old exceptions
            suiteResults[testName].exceptions = [];
          }
          suiteResults[testName].status = "startTest";
        });

        testResult.addListener("failure", function(e) {
          e.getData().forEach(function(errMap) {
            var suiteResult = suiteResults[errMap.test.getFullName()];
            suiteResult.status = "failure";
            suiteResult.exceptions.push(formatError(errMap.exception));
          });
        });

        testResult.addListener("error", function(e) {
          e.getData().forEach(function(errMap) {
            window.console.warn(errMap.test.getFullName() + " : Unexpected exception");

            var suiteResult = suiteResults[errMap.test.getFullName()];
            suiteResult.status = "error";
            suiteResult.exceptions.push(errMap.exception);
          });
        });

        testResult.addListener("skip", function(e) {
          e.getData().forEach(function(errMap) {
            window.console.warn(errMap.test.getFullName() + " skipped: " + errMap.exception.toString());

            var suiteResult = suiteResults[errMap.test.getFullName()];
            suiteResult.status = "skip";
            suiteResult.exceptions.push(errMap.exception);
          });
        });

        testResult.addListener("wait", function(e) {
          var testName = e.getData().getFullName();

          suiteResults[testName].status = "wait";
        });

        testResult.addListener("endTest", function(e) {
          testCount--;
          var testName = e.getData().getFullName();

          var suiteResult = suiteResults[testName];

          var log = suiteResult.exceptions.map(function(ex) {
            return ex.toString();
          });

          var suite, description;
          var match = /(.*?)\.([a-zA-Z]+:.*)/.exec(testName);
          if (match) {
            suite = [match[1]];
            description = match[2];
          } else {
            suite = [];
            description = testName;
          }
          var skipped = suiteResult.status === "skip";
          var success = suiteResult.status === "startTest";

          var result = {
            id : (totalTests-testCount),
            description: description,
            suite: suite,
            success: success,
            skipped: skipped,
            log: success ? [] : log,
            time: skipped ? 0 : Date.now() - suiteResult.startTime
          };

          tc.result(result);

          if (testCount === 0) {
            tc.complete({
              coverage: window.__coverage__
            });
          } else {
            runNext();
          }
        });
      };

      window.onload = function() {
        qx.event.Timer.once(function() {
          var loader = qx.core.Init.getApplication();

          var testDesc = JSON.parse(loader.getTestDescriptions());

          var classes = loader.getSuite().getTestClasses();

          var filter = window.__karma__.config.testClass ? window.__karma__.config.testClass : null;

          for (var i=0; i<classes.length; i++) {

            if (!filter || classes[i].getName().startsWith(filter)) {
              var methods = classes[i].getTestMethods();
              for (var j = 0; j < methods.length; j++) {
                testList.push(methods[j]);
              }
            }
          }
          totalTests = testCount = testList.length;
          tc.info({
            total: totalTests
          });


          testResult = new qx.dev.unit.TestResult();
          addListeners(testResult);
          runNext();
        }, this, 0);
      };
    };
  };

  window.__karma__.start = createQooxdooStartFn(window.__karma__);

})(window);
{'fraction_non_alphanumeric': 0.14096830643593233, 'fraction_numerical': 0.0029165856503986, 'mean_word_length': 1.8206745270085, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 6, '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': '2051909', 'n_tokens_mistral': 2872, 'n_tokens_neox': 2808, 'n_words': 515}