<commit_before>// Copyright (c) Microsoft Open Technologies, Inc.  All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
(function () {
    "use strict";

    module.exports = function (grunt) {
        var config = require("../config.js");

        grunt.registerTask("test", function () {
            var parseArgs = require("minimist");
            var args = parseArgs(process.argv);

            if (config.inRazzle) {
                grunt.task.run(["default", "clean:qunit", "shell:runTests"]);
            } else {
                if (args.saucelabs) {
                    grunt.task.run(["release", "connect:saucelabs", "saucelabs-qunit"]);
                } else {
                    grunt.task.run(["default", "connect:localhost"]);
                }
            }
        });

        // Generate QUnit test pages
        grunt.registerTask("build-qunit", function () {
            var fs = require("fs");

            function extractDependencies(path) {
                var fileContents = fs.readFileSync(path, "utf-8");
                var dir = path.substring(0, path.lastIndexOf("/"));
                var deps = [];

                var lines = fileContents.split("\n");
                for (var i = 0; i < lines.length; i++) {
                    var line = lines[i];
                    var processedOne = false;
                    if (line.indexOf("<reference") < 0 || line.indexOf("ms-appx") >= 0) {
                        if (processedOne) {
                            break;
                        } else {
                            continue;
                        }
                    }

                    var startIndex = line.indexOf('path="') + 6;
                    var endIndex = line.indexOf('"', startIndex);
                    deps.push(dir + "/" + line.substring(startIndex, endIndex));

                    processedOne = true;
                }
                return deps;
            }

            function arrayIndexOf(arr, obj) {
                for (var i = 0; i < arr.length; i++) {
                    if (arr[i] === obj) {
                        return i;
                    }
                }
                return -1;
            }

            var testMenuTemplate =
        '<!-- Copyright (c) Microsoft Open Technologies, Inc.  All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->    \r\n\
<!DOCTYPE html>                                                                                                             \r\n\<commit_msg>Updated the test build to verify that dependencies referenced in test files actually exist. Fixes #159.<commit_after>// Copyright (c) Microsoft Open Technologies, Inc.  All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
(function () {
    "use strict";

    module.exports = function (grunt) {
        var config = require("../config.js");

        grunt.registerTask("test", function () {
            var parseArgs = require("minimist");
            var args = parseArgs(process.argv);

            if (config.inRazzle) {
                grunt.task.run(["default", "clean:qunit", "shell:runTests"]);
            } else {
                if (args.saucelabs) {
                    grunt.task.run(["release", "connect:saucelabs", "saucelabs-qunit"]);
                } else {
                    grunt.task.run(["default", "connect:localhost"]);
                }
            }
        });

        // Generate QUnit test pages
        grunt.registerTask("build-qunit", function () {
            var fs = require("fs");

            function extractDependencies(path) {
                var fileContents = fs.readFileSync(path, "utf-8");
                var dir = path.substring(0, path.lastIndexOf("/"));
                var deps = [];

                var lines = fileContents.split("\n");
                for (var i = 0; i < lines.length; i++) {
                    var line = lines[i];
                    var processedOne = false;
                    if (line.indexOf("<reference") < 0 || line.indexOf("ms-appx") >= 0) {
                        if (processedOne) {
                            break;
                        } else {
                            continue;
                        }
                    }

                    var startIndex = line.indexOf('path="') + 6;
                    var endIndex = line.indexOf('"', startIndex);
                    var path = dir + "/" + line.substring(startIndex, endIndex);
                    if (!fs.existsSync(path)) {
                        grunt.fail.warn("Could not find dependency:\n" + line + "in file:\n" + path);
                    }
                    deps.push(path);

                    processedOne = true;
                }
                return deps;
            }

            function arrayIndexOf(arr, obj) {
                for (var i = 0; i < arr.length; i++) {
                    if (arr[i] === obj) {
                        return i;
                    }
                }
                return -1;
            }

            var testMenuTemplate =
        '<!-- Copyright (c) Microsoft Open Technologies, Inc.  All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -->    \r\n\
<!DOCTYPE html>                                                                                                             \r\n\
{'fraction_non_alphanumeric': 0.11602209944751381, 'fraction_numerical': 0.004811976474781679, 'mean_word_length': 1.1904761904761905, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5652010', 'n_tokens_mistral': 1430, 'n_tokens_neox': 1313, 'n_words': 361}