var fs = require('../util/fs');
var path = require('path');
var map = require('p-map');

var FAILED_DIFF_RE = /^failed_diff_/;

// This task will copy ALL test bitmap files (from the most recent test directory) to the reference directory overwritting any exisiting files.
module.exports = {
  execute: function (config) {
    // TODO:  IF Exists config.bitmaps_test  &&  list.length > 0n  (otherwise throw)
    console.log('Copying from ' + config.bitmaps_test + ' to ' + config.bitmaps_reference + '.');
    return fs.readdir(config.bitmaps_test, (err, list) => {
      if (err) {
        console.log(err.stack);
      }
      var src = path.join(config.bitmaps_test, list[list.length - 1]);
      return fs.readdir(src, (err, files) => {
        if (err) {
          console.log(err.stack);
        }
        console.log('The following files will be promoted to reference...');
        return map(files, (file) => {
          if (FAILED_DIFF_RE.test(file)) {
            file = file.replace(FAILED_DIFF_RE, '');
            console.log('> ', file);
            return fs.copy(path.join(src, file), path.join(config.bitmaps_reference, file));
          }
          return true;
        });
      });
    });
  }
};

@@ -119,16 +119,44 @@
 _diff_/;
+%0Avar FILTER_DEFAULT = /%5Cw+/;
 %0A%0A// Thi
@@ -1031,24 +1031,242 @@
 FF_RE, '');%0A
+%0A            let imageFilter = FILTER_DEFAULT;%0A            if (config.args && config.args.filter) %7B%0A              imageFilter = new RegExp(config.args.filter);%0A            %7D%0A            if (imageFilter.test(file)) %7B%0A  
             
@@ -1290,16 +1290,18 @@
  file);%0A
+  
         
@@ -1385,16 +1385,30 @@
 file));%0A
+            %7D%0A
         

add --filter arg to approve