<commit_before>/* global task:true, desc, jake, fail, complete */

var conf  = require("./server/conf"),
    log   = conf.log,
    color = require("cli-color");


/* TODO: Fix so it works with
 * prerequisites and3 async
 * ====================== */
// Keep old task function
var _task = task;

// Override task function
task = function(name, cb) {
    // If callback is an object (default task) use the old task function
    if (typeof cb === "object") return _task(name, cb);
    
    // Create task with old function
    var t = _task(name, cb);
    
    // Override the callback
    t.action = function() {
        // Inject logTask into callback
        logTask(t);
        
        // Call the real callback with the task as 'this' and the arguments passed by the callback
        cb.apply(t, t.args);
    };
};


desc("Testing stuff");
task("wat", function(strict) {
    if (strict === "true") log.info("STRICT");
    else log.info("NOT STRICT");
});


task("default", ["lint", "test"]);

desc("Lint JavaScript files");
task("lint", function() {
    var lint = require("./server/lib/jake-jshint");
    var files = new jake.FileList();
    
    files.include("**/*.js");
    files.exclude(["node_modules"]);
    
    var pass = lint.run(files.toArray(), conf.lint.options, conf.lint.globals);
    if (!pass) fail("Lint failed");
});

desc("Run tests with Mocha");
task("test", function() {
    var MochaTest = require("mocha");
    var mocha = new MochaTest({ reporter: "spec", ui: "bdd" });
    var files = new jake.FileList();
    
    files.include("./server/test/_*_test.js");
    
    files.forEach(function(file) {
        mocha.addFile(file);
    });
    
    mocha.run(function(failures) {
        if (failures) fail("Mocha test failed");
    });
});


function logTask(t) {
    console.log("\n" + color.blue("===== ") + color.bold.underline.yellow(t.description) + color.blue(" ====="));
}<commit_msg>Fixed support for async tasks<commit_after>/* global task:true, desc, jake, fail, complete */

var conf  = require("./server/conf"),
    log   = conf.log,
    color = require("cli-color");


/* TODO: Fix so it works with
 * prerequisites and3 async
 * ====================== */
// Keep old task function
var _task = task;

// Override task function
task = function() {
    var args = arguments;
    // If callback is an object (default task) use the old task function
    if (typeof args[1] === "object") return _task.apply(this, args);
    
    // Create task with old function
    var t = _task.apply(this, args);
    
    // Find the callback. Last element might be 'opts'
    var cb = typeof args[args.length - 1] === "function" ? args[args.length - 1] : args[args.length - 2];
    
    // Override the callback
    t.action = function() {
        // Inject logTask into callback
        logTask(t);
        
        // Call the real callback with the task as 'this' and the arguments passed by the callback
        cb.apply(t, t.args);
    };
};


task("default", ["lint", "test"]);

desc("Lint JavaScript files");
task("lint", function() {
    var lint = require("./server/lib/jake-jshint");
    var files = new jake.FileList();
    
    files.include("**/*.js");
    files.exclude(["node_modules"]);
    
    var pass = lint.run(files.toArray(), conf.lint.options, conf.lint.globals);
    if (!pass) fail("Lint failed");
});

desc("Run tests with Mocha");
task("test", function() {
    var MochaTest = require("mocha");
    var mocha = new MochaTest({ reporter: "spec", ui: "bdd" });
    var files = new jake.FileList();
    
    files.include("./server/test/_*_test.js");
    
    files.forEach(function(file) {
        mocha.addFile(file);
    });
    
    mocha.run(function(failures) {
        if (failures) fail("Mocha test failed");
        complete();
    });
}, { async: true });


desc("Testing stuff");
task("wat", function(strict) {
    if (strict === "true") log.info("STRICT");
    else log.info("NOT STRICT");
    
    log.info("Y U NO LOG");
});

function logTask(t) {
    console.log("\n" + color.blue("===== ") + color.bold.underline.yellow(t.description) + color.blue(" ====="));
}
{'fraction_non_alphanumeric': 0.18340611353711792, 'fraction_numerical': 0.001455604075691412, 'mean_word_length': 2.8677298311444654, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1910956', 'n_tokens_mistral': 1337, 'n_tokens_neox': 1299, 'n_words': 361}