<commit_before>'use strict';

var gulp = require('gulp');
var componentHelper = require('gulp-component-helper')(gulp);
var paths = componentHelper.paths;
var runSequence = require('run-sequence');
var connect = require('gulp-connect');
var child_process = require('child_process');
var fs = require('fs');
var resemble = require('node-resemble');
var spawn = child_process.spawn;
var exec = child_process.exec;

gulp.task('screenshot:init', function(cb){

    var npmChild = spawn('npm', ['install'], {cwd: 'bower_components/backstopjs'});
    npmChild.on('close', function (code) {
        var success = code === 0; // Will be 1 in the event of failure
        if (success){  } else {     }

        cb()
    });

});

gulp.task('screenshot:record', function(cb){

    connect.server({
        root: '_site',
        port: 8888
    });

    var casperChild = spawn('casperjs', ['test/casper.js'].concat(['test/casper.js']));

    casperChild.on('close', function (code) {
        var success = code === 0; // Will be 1 in the event of failure

        if (success){

        } else {

        }


        connect.serverClose();
        cb();
    });


});


gulp.task('screenshot:accepted', function(cb){
    return gulp.src('test/screenshots/new/*')
        .pipe(gulp.dest('test/screenshots/reference'))
});

gulp.task('screenshot:compare', function(cb){
    try {
        var img1 = fs.readFileSync('./test/screenshots/reference/body.png');
    } catch(e){
        console.log('The reference shot does not exit. Please copy it across.');
        process.exit(1);
    }
    var img2 = fs.readFileSync('./test/screenshots/new/body.png');
    var api = resemble(img2).compareTo(img1).onComplete(function(data){
        var err = false;
        if (!data.isSameDimensions) {
            if (data.dimensionDifference.width !== 0) {
                console.log('the new image is wider/smaller: ' + data.dimensionDifference.width + 'px different');
            }
            if (data.dimensionDifference.height !== 0) {
                console.log('the new image is taller/smaller: ' + data.dimensionDifference.height + 'px different');
            }
            err = true;
        }
        if (data.misMatchPercentage > 0) {
            console.log('The new image content has changed: ' + data.misMatchPercentage + '% different');
            console.log('Please check the following images and move them to reference directory if they are correct.');
            console.log(__dirname + '/test/screenshots/new/google.png');
            err = true;
        }
        if (err){
            //gulp.src(['./test/screenshots/reference'])
            //    .pipe('./bower_components/backstopjs/bitmaps_reference');
            process.exit(1);
        } else {
            console.log('The new images match the reference shots');
            cb();
        }
    });

});
<commit_msg>half finished spike into screen shotting<commit_after>'use strict';

var gulp = require('gulp');
var componentHelper = require('gulp-component-helper')(gulp);
var paths = componentHelper.paths;
var runSequence = require('run-sequence');
var connect = require('gulp-connect');
var child_process = require('child_process');
var fs = require('fs');
var path = require('path');
var resemble = require('node-resemble');
var spawn = child_process.spawn;
var exec = child_process.exec;

gulp.task('screenshot:init', function(cb){

    var npmChild = spawn('npm', ['install'], {cwd: 'bower_components/backstopjs'});
    npmChild.on('close', function (code) {
        var success = code === 0; // Will be 1 in the event of failure
        if (success){  } else {     }

        cb()
    });

});

gulp.task('screenshot:record', function(cb){

    connect.server({
        root: '_site',
        port: 8888
    });

    var casperChild = spawn('casperjs', ['test/casper.js'].concat(['test/casper.js']));

    casperChild.on('close', function (code) {
        var success = code === 0; // Will be 1 in the event of failure

        if (success){

        } else {

        }


        connect.serverClose();
        cb();
    });


});


gulp.task('screenshot:accepted', function(cb){
    return gulp.src('test/screenshots/new/*')
        .pipe(gulp.dest('test/screenshots/reference'))
});

gulp.task('screenshot:compare', function(cb){
    try {
        var img1 = fs.readFileSync('./test/screenshots/reference/body.png');
    } catch(e){
        console.log('The reference shot does not exit. Please copy it across.');
        process.exit(1);
    }
    var img2 = fs.readFileSync('./test/screenshots/new/body.png');
    var api = resemble(img2).compareTo(img1).onComplete(function(data){
        var err = false;
        if (!data.isSameDimensions) {
            if (data.dimensionDifference.width !== 0) {
                console.log('the new image is wider/smaller: ' + data.dimensionDifference.width + 'px different');
            }
            if (data.dimensionDifference.height !== 0) {
                console.log('the new image is taller/smaller: ' + data.dimensionDifference.height + 'px different');
            }
            err = true;
        }
        if (data.misMatchPercentage > 0) {
            console.log('The new image content has changed: ' + data.misMatchPercentage + '% different');
            console.log('Please check the following images and move them to reference directory if they are correct.');
            console.log(__dirname + '/test/screenshots/new/body.png');
            err = true;
        }
        if (err){

            var image = data.getImageDataUrl().

            process.exit(1);
        } else {
            console.log('The new images match the reference shots');
            cb();
        }
    });

});

{'fraction_non_alphanumeric': 0.15019210618232623, 'fraction_numerical': 0.005937827453719874, 'mean_word_length': 2.4920731707317074, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1241503', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1666, 'n_words': 393}