<commit_before>/* global phantom, console, casper:true */

var EX_OK = 0,
    EX_USAGE = 64;

if (!phantom.casperLoaded) {
    console.log('This script must be invoked using the casperjs executable');
    phantom.exit(EX_USAGE);
}

specter = function() {

    /*
    casper.test.assertScreenshot = function (selector, filename, description) {
        var completed = false;
        var fn = this.currentTestFile;
        var i = this.currentTestFile.indexOf(casper.specter.baseline + '/');
        if (i === 0) {
            fn = this.currentTestFile.substring(casper.specter.baseline.length + 1);
        }
        var dir = fn.split(fs.separator),
            testfile = dir.pop().replace(/\.js$/, '').replace(/^test-/, ''),
            parent = dir.join(fs.separator),
            path = [
                    dir.join(fs.separator),
                    testfile + '-' + filename + '.png'
                ].join(fs.separator),
            result = false;
        //var fn = this.currentTestFile.replace(casper.specter.baseline, '');
        //console.log(fn);
        console.log(baseline + fs.separator + path);

        //casper.wait(5000, function() {
            if (fs.exists(baseline + fs.separator + path)) {
                // do diff
                casper.captureSelector(casper.specter.diffbase + fs.separator + path, selector);
                //var completed = false;
                //compare(
                //    casper.specter.diffbase + fs.separator + path,
                //    casper.specter.baseline + fs.separator + path,
                //    function (same, mismatch) {
                //        completed = true;
                //        result = same;
                //        console.log(same);
                //        console.log(mismatch);
                //    }
                //);
                result = true;
            } else {
                // capture baseline
                casper.captureSelector(baseline + fs.separator + path, selector);
            }
                casper.waitFor(function() {
                    return completed;
                }, function() {
                    this.test.assert(result, description, {
                        type: "assertScreenshot",
                        standard: description,
                        values: {
                            subject: selector,
                            filename: filename,
                            description: description
                        }
                    });
                });
        //});
    };
    */

    return {

        tmp: function () {
            if (arguments.length) {
                tmp = arguments[0];
            }
            return tmp;
        },

        baseline: function () {
            if (arguments.length) {
                baseline = arguments[0];
            }
            return baseline;
        },

        turn_off_animations: function() {
            casper.evaluate(function() {
                window.addEventListener('load', function(){
                    var css = document.createElement("style");
                    css.type = "text/css";
                    css.innerHTML = "* { -webkit-transition: none !important; transition: none !important; }";
                    document.body.appendChild(css);

                    if(jQuery){
                        jQuery.finish();
                        jQuery.fx.off = true;
                    }
                },false);
            });
        },

        screenshot: function(selector, filename, waittime) {
            var fn = casper.test.currentTestFile;
            if (fn.indexOf(fs.workingDirectory + '/') === 0) {
                fn = fn.substring(fs.workingDirectory.length + 1);
            }
            var dir = fn.split(fs.separator),
                testfile = dir.pop().replace(/\.js$/, '').replace(/^test-/, ''),
                path = [
                        dir.join(fs.separator),
                        testfile + '-' + filename + '.png'
                    ].join(fs.separator);

            casper.evaluate(function() {
                if(jQuery) {
                    $.finish();
                }
            });

            casper.captureBase64('png'); // force pre-render
            casper.wait(waittime || 250, function() {
                try{
                    if (casper.specter.rebase || !fs.exists(casper.specter.baseline + fs.separator + path)) {
                        casper.echo('capturing baseline: ' + path, 'INFO', 80);
                        casper.captureSelector(
                            casper.specter.baseline + fs.separator + path,
                            selector
                        );
                    } else {
                        casper.captureSelector(
                            casper.specter.diffbase + fs.separator + path,
                            selector
                        );
                    }
                }
                catch(ex){
                    casper.echo("Screenshot failed: " + ex.message, 'ERROR');
                    return false;
                }
            });
        }
    };
}();

casper.test.done();
<commit_msg>turning off animations moved into a casper event handler<commit_after>/* global phantom, console, casper:true */

var EX_OK = 0,
    EX_USAGE = 64;

if (!phantom.casperLoaded) {
    console.log('This script must be invoked using the casperjs executable');
    phantom.exit(EX_USAGE);
}

specter = function() {

    /*
    casper.test.assertScreenshot = function (selector, filename, description) {
        var completed = false;
        var fn = this.currentTestFile;
        var i = this.currentTestFile.indexOf(casper.specter.baseline + '/');
        if (i === 0) {
            fn = this.currentTestFile.substring(casper.specter.baseline.length + 1);
        }
        var dir = fn.split(fs.separator),
            testfile = dir.pop().replace(/\.js$/, '').replace(/^test-/, ''),
            parent = dir.join(fs.separator),
            path = [
                    dir.join(fs.separator),
                    testfile + '-' + filename + '.png'
                ].join(fs.separator),
            result = false;
        //var fn = this.currentTestFile.replace(casper.specter.baseline, '');
        //console.log(fn);
        console.log(baseline + fs.separator + path);

        //casper.wait(5000, function() {
            if (fs.exists(baseline + fs.separator + path)) {
                // do diff
                casper.captureSelector(casper.specter.diffbase + fs.separator + path, selector);
                //var completed = false;
                //compare(
                //    casper.specter.diffbase + fs.separator + path,
                //    casper.specter.baseline + fs.separator + path,
                //    function (same, mismatch) {
                //        completed = true;
                //        result = same;
                //        console.log(same);
                //        console.log(mismatch);
                //    }
                //);
                result = true;
            } else {
                // capture baseline
                casper.captureSelector(baseline + fs.separator + path, selector);
            }
                casper.waitFor(function() {
                    return completed;
                }, function() {
                    this.test.assert(result, description, {
                        type: "assertScreenshot",
                        standard: description,
                        values: {
                            subject: selector,
                            filename: filename,
                            description: description
                        }
                    });
                });
        //});
    };
    */

    return {

        tmp: function () {
            if (arguments.length) {
                tmp = arguments[0];
            }
            return tmp;
        },

        baseline: function () {
            if (arguments.length) {
                baseline = arguments[0];
            }
            return baseline;
        },

        turn_off_animations: function() {
            casper.on('load.finished', function() {
                this.evaluate(function(){
                    var css = document.createElement("style");
                    css.type = "text/css";
                    css.innerHTML = "* { -webkit-transition: none !important; transition: none !important; }";
                    document.body.appendChild(css);
                    if(jQuery){
                        jQuery.fx.off = true;
                        jQuery("*").finish();
                    }
                });
            });
        },

        screenshot: function(selector, filename, waittime) {
            var fn = casper.test.currentTestFile;
            if (fn.indexOf(fs.workingDirectory + '/') === 0) {
                fn = fn.substring(fs.workingDirectory.length + 1);
            }
            var dir = fn.split(fs.separator),
                testfile = dir.pop().replace(/\.js$/, '').replace(/^test-/, ''),
                path = [
                        dir.join(fs.separator),
                        testfile + '-' + filename + '.png'
                    ].join(fs.separator);

            casper.evaluate(function() {
                if(jQuery) {
                    $.finish();
                }
            });

            casper.captureBase64('png'); // force pre-render
            casper.wait(waittime || 250, function() {
                try{
                    if (casper.specter.rebase || !fs.exists(casper.specter.baseline + fs.separator + path)) {
                        casper.echo('capturing baseline: ' + path, 'INFO', 80);
                        casper.captureSelector(
                            casper.specter.baseline + fs.separator + path,
                            selector
                        );
                    } else {
                        casper.captureSelector(
                            casper.specter.diffbase + fs.separator + path,
                            selector
                        );
                    }
                }
                catch(ex){
                    casper.echo("Screenshot failed: " + ex.message, 'ERROR');
                    return false;
                }
            });
        }
    };
}();

casper.test.done();

{'fraction_non_alphanumeric': 0.12024221453287197, 'fraction_numerical': 0.0038446751249519417, 'mean_word_length': 1.0897770636674031, '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': '1623019', 'n_tokens_mistral': 2715, 'n_tokens_neox': 2460, 'n_words': 463}