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

var FAILED_DIFF_RE = /^failed_diff_/;
var FILTER_DEFAULT = /\w+/;

// This task will copy ALL test bitmap files (from the most recent test directory) to the reference directory overwriting any existing 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, '');

            let imageFilter = FILTER_DEFAULT;
            if (config.args && config.args.filter) {
              imageFilter = new RegExp(config.args.filter);
            }
            if (imageFilter.test(file)) {
              console.log('> ', file);
              return fs.copy(path.join(src, file), path.join(config.bitmaps_reference, file));
            }
          }
          return true;
        });
      });
    });
  }
};<commit_msg>add promise to approve (#642)<commit_after>var fs = require('../util/fs');
var path = require('path');
var map = require('p-map');

var FAILED_DIFF_RE = /^failed_diff_/;
var FILTER_DEFAULT = /\w+/;

// This task will copy ALL test bitmap files (from the most recent test directory) to the reference directory overwriting any existing 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 new Promise((resolve, reject) => {
      fs.readdir(config.bitmaps_test, (err, list) => {

        if (err) {
          console.log(err.stack);
          reject();
        }
        var src = path.join(config.bitmaps_test, list[list.length - 1]);
        return fs.readdir(src, (err, files) => {
          if (err) {
            console.log(err.stack);
            reject();
          }
          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, '');

              let imageFilter = FILTER_DEFAULT;
              if (config.args && config.args.filter) {
                imageFilter = new RegExp(config.args.filter);
              }
              if (imageFilter.test(file)) {
                console.log('> ', file);
                return fs.copy(path.join(src, file), path.join(config.bitmaps_reference, file));
              }
            }
            return true;
          }).then(resolve).catch(reject);
        });
      });
    });
  }
};
{'fraction_non_alphanumeric': 0.14196176747101222, 'fraction_numerical': 0.0021936696960200563, 'mean_word_length': 2.1020408163265305, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '6114424', 'n_tokens_mistral': 968, 'n_tokens_neox': 947, 'n_words': 226}