<commit_before>'use strict';

const fs = require('fs');
const path = require('path');
const ContentReplacerPlugin = require('../index.js');
const expect = require('expect.js');
const webpackMock = require('webpack-mock');

let contentReplacer;
const options = {
  modifiedFile: './file.txt',
  modifications: [
    {
      regex: /%content_to_be_deleted%/g,
      modification: 'new_content',
    },
  ],
};

const invalidOptionsType = '';
const invalidOptionsObj = {};

describe('ContentReplacer plugin', () => {
  before(() => {
    fs.writeFileSync('test/file.txt', '%content_to_be_deleted%');
  });

  after(() => {
    fs.unlinkSync('test/file.txt');
  });

  it('should be instantiated', () => {
    contentReplacer = new ContentReplacerPlugin(options);
    expect(typeof contentReplacer).to.equal('object');
  });

  it('should throw error when no parameters', () => {
    const noParamConstructor = function () {
      // eslint-disable-next-line no-new
      new ContentReplacerPlugin();
    };

    expect(noParamConstructor).to.throwException(/Parameters are invalid/);
  });

  it('should throw error when parameter format is wrong', () => {
    const wrongParamConstructor = function () {
      // eslint-disable-next-line no-new
      new ContentReplacerPlugin({});
    };

    expect(wrongParamConstructor).to.throwException(/Required parameters are missing/);
  });

  it('should have default options', () => {
    expect(contentReplacer.buildTrigger).to.equal('after-emit');
    expect(contentReplacer.silent).to.equal(false);
    expect(contentReplacer.verbose).to.equal(true);
  });

  it('should have valid options', () => {
    expect(ContentReplacerPlugin.hasValidOptions(options)).to.equal(true);
  });

  it('should detect invalid options (string)', () => {
    expect(ContentReplacerPlugin.hasValidOptions(invalidOptionsType)).to.equal(false);
  });<commit_msg>Fix eslint warning (#35)<commit_after>'use strict';

const fs = require('fs');
const path = require('path');
const ContentReplacerPlugin = require('../index.js');
const expect = require('expect.js');
const webpackMock = require('webpack-mock');

let contentReplacer;
const options = {
  modifiedFile: './file.txt',
  modifications: [
    {
      regex: /%content_to_be_deleted%/g,
      modification: 'new_content',
    },
  ],
};

const invalidOptionsType = '';
const invalidOptionsObj = {};

describe('ContentReplacer plugin', () => {
  before(() => {
    fs.writeFileSync('test/file.txt', '%content_to_be_deleted%');
  });

  after(() => {
    fs.unlinkSync('test/file.txt');
  });

  it('should be instantiated', () => {
    contentReplacer = new ContentReplacerPlugin(options);
    expect(typeof contentReplacer).to.equal('object');
  });

  it('should throw error when no parameters', () => {
    const noParamConstructor = () => {
      // eslint-disable-next-line no-new
      new ContentReplacerPlugin();
    };

    expect(noParamConstructor).to.throwException(/Parameters are invalid/);
  });

  it('should throw error when parameter format is wrong', () => {
    const wrongParamConstructor = () => {
      // eslint-disable-next-line no-new
      new ContentReplacerPlugin({});
    };

    expect(wrongParamConstructor).to.throwException(/Required parameters are missing/);
  });

  it('should have default options', () => {
    expect(contentReplacer.buildTrigger).to.equal('after-emit');
    expect(contentReplacer.silent).to.equal(false);
    expect(contentReplacer.verbose).to.equal(true);
  });

  it('should have valid options', () => {
    expect(ContentReplacerPlugin.hasValidOptions(options)).to.equal(true);
  });

  it('should detect invalid options (string)', () => {
    expect(ContentReplacerPlugin.hasValidOptions(invalidOptionsType)).to.equal(false);
  });
{'fraction_non_alphanumeric': 0.1667992574913816, 'fraction_numerical': 0.0005303632988597189, 'mean_word_length': 4.083557951482479, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '6772742', 'n_tokens_mistral': 1143, 'n_tokens_neox': 1123, 'n_words': 201}