<commit_before>'use strict';

var fs = require('fs');
var os = require('os');
var path = require('path');
var assign = require('object-assign');
var expect = require('expect.js');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');
var webpack = require('webpack');

describe('Filesystem Cache', function() {

  this.timeout(3000);

  var cacheDir = path.resolve(__dirname, 'output/cache/cachefiles');
  var outputDir = path.resolve(__dirname, './output/cache/');
  var babelLoader = path.resolve(__dirname, '../');
  var globalConfig = {
    entry: './test/fixtures/basic.js',
    output: {
      path: outputDir,
      filename: '[id].cache.js',
    },
    module: {
      loaders: [
        {
          test: /\.jsx?/,
          loader: babelLoader,
          exclude: /node_modules/,
        },
      ],
    },
  };

  // Clean generated cache files before each test
  // so that we can call each test with an empty state.
  beforeEach(function(done) {
    rimraf(outputDir, function(err) {
      if (err) { return done(err); }
      mkdirp(cacheDir, done);
    });
  });

  it('should output files to cache directory', function(done) {

    var loader = babelLoader;
    var config = assign({}, globalConfig, {
      module: {
        loaders: [
          {
            test: /\.jsx?/,
            loader: loader,
            exclude: /node_modules/,
            query: {
              cacheDirectory: cacheDir,
              presets: ['es2015'],
            },
          },
        ],
      },
    });

    webpack(config, function(err, stats) {
      expect(err).to.be(null);

      fs.readdir(cacheDir, function(err, files) {
        expect(err).to.be(null);
        expect(files).to.not.be.empty();
        done();
      });
    });
  });

  it('should output files to OS\'s tmp dir', function(done) {
    var config = assign({}, globalConfig, {
      module: {
        loaders: [
          {
            test: /\.jsx?/,
            loader: babelLoader,
            exclude: /node_modules/,
            query: {
              cacheDirectory: cacheDir,
              presets: ['es2015'],
            },
          },
        ],
      },
    });

    webpack(config, function(err, stats) {
      expect(err).to.be(null);

      fs.readdir(os.tmpdir(), function(err, files) {

        files = files.filter(function(file) {<commit_msg>fix cache directory setting in the test<commit_after>'use strict';

var fs = require('fs');
var os = require('os');
var path = require('path');
var assign = require('object-assign');
var expect = require('expect.js');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');
var webpack = require('webpack');

describe('Filesystem Cache', function() {

  this.timeout(3000);

  var cacheDir = path.resolve(__dirname, 'output/cache/cachefiles');
  var outputDir = path.resolve(__dirname, './output/cache/');
  var babelLoader = path.resolve(__dirname, '../');
  var globalConfig = {
    entry: './test/fixtures/basic.js',
    output: {
      path: outputDir,
      filename: '[id].cache.js',
    },
    module: {
      loaders: [
        {
          test: /\.jsx?/,
          loader: babelLoader,
          exclude: /node_modules/,
        },
      ],
    },
  };

  // Clean generated cache files before each test
  // so that we can call each test with an empty state.
  beforeEach(function(done) {
    rimraf(outputDir, function(err) {
      if (err) { return done(err); }
      mkdirp(cacheDir, done);
    });
  });

  it('should output files to cache directory', function(done) {

    var loader = babelLoader;
    var config = assign({}, globalConfig, {
      module: {
        loaders: [
          {
            test: /\.jsx?/,
            loader: loader,
            exclude: /node_modules/,
            query: {
              cacheDirectory: cacheDir,
              presets: ['es2015'],
            },
          },
        ],
      },
    });

    webpack(config, function(err, stats) {
      expect(err).to.be(null);

      fs.readdir(cacheDir, function(err, files) {
        expect(err).to.be(null);
        expect(files).to.not.be.empty();
        done();
      });
    });
  });

  it('should output files to OS\'s tmp dir', function(done) {
    var config = assign({}, globalConfig, {
      module: {
        loaders: [
          {
            test: /\.jsx?/,
            loader: babelLoader,
            exclude: /node_modules/,
            query: {
              cacheDirectory: true,
              presets: ['es2015'],
            },
          },
        ],
      },
    });

    webpack(config, function(err, stats) {
      expect(err).to.be(null);

      fs.readdir(os.tmpdir(), function(err, files) {
        files = files.filter(function(file) {
{'fraction_non_alphanumeric': 0.1562566165572729, 'fraction_numerical': 0.005081515985602371, 'mean_word_length': 1.9561952440550687, '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': '6467665', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1395, 'n_words': 318}