<commit_before>/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
*/

var fs = require('fs'),
    util = require('util'),
    _path = require('path'),
    tests = [],
    packager = require('../build/packager'),
    exec = require('child_process').exec;

function collect(path, files, matches) {
    matches = matches || function (path) {
        return path.match(/test\.(\w|-)+\.js$/);
    };

    if (fs.statSync(path).isDirectory()) {
        fs.readdirSync(path).forEach(function (item) {
            collect(_path.join(path, item), files, matches);
        });
    } else if (matches(path)) {
        files.push(path);
    }
}

module.exports = {
    node: function(callback) {
        console.log('starting node-based tests')
        var jas = require("../thirdparty/jasmine/jasmine"),
            TerminalReporter = require('./reporter').TerminalReporter,
            jsdom, document, window;

        try {
            jsdom = require("jsdom").jsdom;
            document = jsdom("<html><head></head></html>");
            window = document.createWindow();
        } catch (e) {
            //no jsDom (some people don't have compilers)
            throw new Error("can't run tests in node: run grunt btest instead, or install jsdom via: npm install");
        }

        //Put jasmine in scope
        Object.keys(jas).forEach(function (key) {
            this[key] = window[key] = global[key] = jas[key];
        });

        //load in our modules
        var testLibName = _path.join(__dirname, '..', 'pkg', 'cordova.test.js')
        var testLib     = fs.readFileSync(testLibName, 'utf8')
        try {
            eval(testLib);
        }
        catch (e) {
            console.log("error eval()ing " + testLibName + ": " + e)
            console.log(e.stack)
            throw e
        }

        //hijack require
        require = window.cordova.require;
        define  = window.cordova.define;

        //load in our tests
        collect(__dirname, tests);
        for (var x in tests) {
            eval(fs.readFileSync(tests[x], "utf-8"));
        }

        var env = jasmine.getEnv();
        env.addReporter(new TerminalReporter({
            color: true,
            onComplete: function() { callback(true); }
        }));

        console.log("------------");
        console.log("Unit Tests:");
        env.execute();
    },<commit_msg>Make grunt fail if tests fail.<commit_after>/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
*/

var fs = require('fs'),
    util = require('util'),
    _path = require('path'),
    tests = [],
    packager = require('../build/packager'),
    exec = require('child_process').exec;

function collect(path, files, matches) {
    matches = matches || function (path) {
        return path.match(/test\.(\w|-)+\.js$/);
    };

    if (fs.statSync(path).isDirectory()) {
        fs.readdirSync(path).forEach(function (item) {
            collect(_path.join(path, item), files, matches);
        });
    } else if (matches(path)) {
        files.push(path);
    }
}

module.exports = {
    node: function(callback) {
        console.log('starting node-based tests')
        var jas = require("../thirdparty/jasmine/jasmine"),
            TerminalReporter = require('./reporter').TerminalReporter,
            jsdom, document, window;

        try {
            jsdom = require("jsdom").jsdom;
            document = jsdom("<html><head></head></html>");
            window = document.createWindow();
        } catch (e) {
            //no jsDom (some people don't have compilers)
            throw new Error("can't run tests in node: run grunt btest instead, or install jsdom via: npm install");
        }

        //Put jasmine in scope
        Object.keys(jas).forEach(function (key) {
            this[key] = window[key] = global[key] = jas[key];
        });

        //load in our modules
        var testLibName = _path.join(__dirname, '..', 'pkg', 'cordova.test.js')
        var testLib     = fs.readFileSync(testLibName, 'utf8')
        try {
            eval(testLib);
        }
        catch (e) {
            console.log("error eval()ing " + testLibName + ": " + e)
            console.log(e.stack)
            throw e
        }

        //hijack require
        require = window.cordova.require;
        define  = window.cordova.define;

        //load in our tests
        collect(__dirname, tests);
        for (var x in tests) {
            eval(fs.readFileSync(tests[x], "utf-8"));
        }

        var env = jasmine.getEnv();
        env.addReporter(new TerminalReporter({
            color: true,
            onComplete: function(runner) { callback(runner.results().passed()); }
        }));

        console.log("------------");
        console.log("Unit Tests:");
        env.execute();
    },
{'fraction_non_alphanumeric': 0.1314367450731087, 'fraction_numerical': 0.0019071837253655435, 'mean_word_length': 2.2354755784061697, 'pattern_counts': {'":': 2, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6223542', 'n_tokens_mistral': 1762, 'n_tokens_neox': 1722, 'n_words': 527}