<commit_before>define(['litmus'], function (litmus) {

   /**
    * Namespace: litmus.browser - Litmus running in a browser
    *
    * Functions for running tests and formatting results in a browser.
    */

    var ns = {};

    var body = document.getElementsByTagName('body')[0];

   /**
    * Private function: addToBody
    *
    * Format a TestResult/SuiteResult and add it to the document body.
    */

    function addToBody (run) {
        var formatter = new litmus.StaticHtmlFormatter();
        var element = document.createElement('div');
        element.setAttribute('class', 'litmus-results');
        element.innerHTML = formatter.format(run);
        body.appendChild(element);
    }

   /**
    * Private function: getTests
    *
    * Get an array containing the the Suites and Tests passed on the query or the default.
    *
    * Arguments:
    *   defaultTest - (required string) name of the test package to run.
    *
    * Returns: an array of test package names to run.
    */

    function getTests (defaultTest) {
        if (location.search) {
            var tests = location.search.substr(1).split('&');
            for (var i = 0, l = tests.length; i < l; i++) {
                if (! /^\w+(?:\.\w+)*$/.test(tests[i])) {
                    throw 'invalid package name passed on query string: ' + tests[i];
                }
            }
            return tests;
        }
        else {
            return [defaultTest];
        }
    }

   /**
    * Function: runStatic
    *
    * Run and format the results of suites and tests. The default Suite or Test
    * is passed in and can be overridden by specifying them in the query string
    * separated by &'s. For example, if the page is index.html, then the tests
    * can be specified by loading "index.html?my.test1&my.suite1".
    *
    * Arguments:
    *   defaultTest - (required string) name of the test package to run.
    */

    ns.runStatic = function (defaultTest) {

        var tests = getTests(defaultTest);

        for (var i = 0, l = tests.length; i < l; i++) {
            require([tests[i]], function (test) {
                var run = test.createRun();
                run.finished.then(function () {
                    addToBody(run);
                });
                run.start();
            });
        }
    };

    return ns;
});
<commit_msg>Added dep on formatting module (like commandline). Moved test run logic to run method.<commit_after>define(['litmus', 'formatting'], function (litmus, formatting) {

   /**
    * Namespace: litmus.browser - Litmus running in a browser
    *
    * Functions for running tests and formatting results in a browser.
    */

    var ns = {};

    var body = document.getElementsByTagName('body')[0];

   /**
    * Private function: addToBody
    *
    * Format a TestResult/SuiteResult and add it to the document body.
    */

    function addToBody (run) {
        var formatter = new formatting.StaticHtmlFormatter();
        var element = document.createElement('div');
        element.setAttribute('class', 'litmus-results');
        element.innerHTML = formatter.format(run);
        body.appendChild(element);
    }

   /**
    * Private function: getTests
    *
    * Get an array containing the the Suites and Tests passed on the query or the default.
    *
    * Arguments:
    *   defaultTest - (required string) name of the test package to run.
    *
    * Returns: an array of test package names to run.
    */

    function getTests (defaultTest) {
        if (location.search) {
            var tests = location.search.substr(1).split('&');
            for (var i = 0, l = tests.length; i < l; i++) {
                if (! /^\w+(?:\.\w+)*$/.test(tests[i])) {
                    throw 'invalid package name passed on query string: ' + tests[i];
                }
            }
            return tests;
        }
        else {
            return [defaultTest];
        }
    }

   /**
    * Function: runStatic
    *
    * Run and format the results of suites and tests. The default Suite or Test
    * is passed in and can be overridden by specifying them in the query string
    * separated by &'s. For example, if the page is index.html, then the tests
    * can be specified by loading "index.html?my.test1&my.suite1".
    *
    * Arguments:
    *   defaultTest - (required string) name of the test package to run.
    */

    ns.runStatic = function (defaultTest) {

        var tests = getTests(defaultTest);

        for (var i = 0, l = tests.length; i < l; i++) {
            require([tests[i]], function (test) {
                ns.run(test);
            });
        }
    };

    ns.run = function (test) {
        console.log(test);
        var run = test.createRun();
        run.finished.then(function () {
            addToBody(run);
        });
        run.start();
    }

    return ns;
});

{'fraction_non_alphanumeric': 0.11689909762100081, 'fraction_numerical': 0.002461033634126333, 'mean_word_length': 1.9099045346062054, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '5166111', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1344, 'n_words': 442}