<commit_before>const td              = require('testdouble');
const mockProject     = require('../../fixtures/corber-mock/project');
const path            = require('path');
const contains        = td.matchers.contains;

const initValidator = function() {
  const ValidateWebpack  = require('../../../lib/validators/webpack-plugin');
  return new ValidateWebpack();
};

describe('Validate Webpack Plugin', function() {
  let validator;
  let warnDouble;

  beforeEach(function() {
    let logDouble = td.replace('../../../lib/utils/logger');
    warnDouble = td.replace(logDouble, 'warn');
  });

  afterEach(function() {
    td.reset();
  });

  context('when framework is Vue', function() {
    beforeEach(function() {
      validator = initValidator();
      validator.framework = 'vue';
      validator.configPath = path.join(mockProject.project.root, 'vue.config.js');
    });

    context('when configureWebpack property missing', function () {
      beforeEach(function() {
        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './'
        }));
      });

      it('warns and resolves', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(contains('vue.config.js')));
          done();
        }).catch(done);
      });
    });

    context('when plugins property missing', function () {
      beforeEach(function() {
        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './',
          configureWebpack: {}
        }));
      });

      it('warns and resolves', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(contains('vue.config.js')));
          done();
        }).catch(done);
      });
    });

    context('when plugins property missing webpack plugin', function () {
      beforeEach(function() {
        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './',
          configureWebpack: {
            plugins: []
          }
        }));
      });

      it('warns and resolves', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(contains('vue.config.js')));
          done();
        }).catch(done);
      });
    });

    context('when plugins property includes webpack plugin', function () {
      beforeEach(function() {
        function CorberWebpackPlugin() {}

        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './',
          configureWebpack: {
            plugins: [new CorberWebpackPlugin()]
          }
        }));
      });

      it('resolves silently', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(), { times: 0, ignoreExtraArgs: true });
          done();
        }).catch(done);
      });
    });
  });

  context('when framework is other framework', function() {
    beforeEach(function() {
      validator = initValidator();
      validator.framework = 'react';
      validator.configPath = path.join(
        mockProject.project.root,
        'build',
        'webpack-with-plugin.dev.conf.js'<commit_msg>feat(webpack-plugin): Update test to assert Vue CLI 2 support<commit_after>const td              = require('testdouble');
const mockProject     = require('../../fixtures/corber-mock/project');
const path            = require('path');
const contains        = td.matchers.contains;

const initValidator = function() {
  const ValidateWebpack  = require('../../../lib/validators/webpack-plugin');
  return new ValidateWebpack();
};

describe('Validate Webpack Plugin', function() {
  let validator;
  let warnDouble;

  beforeEach(function() {
    let logDouble = td.replace('../../../lib/utils/logger');
    warnDouble = td.replace(logDouble, 'warn');
  });

  afterEach(function() {
    td.reset();
  });

  context('when config path from Vue CLI v3', function() {
    beforeEach(function() {
      validator = initValidator();
      validator.root = mockProject.project.root;
      validator.framework = 'vue';
      validator.configPath = path.join(mockProject.project.root, 'vue.config.js');
    });

    context('when configureWebpack property missing', function () {
      beforeEach(function() {
        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './'
        }));
      });

      it('warns and resolves', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(contains('vue.config.js')));
          done();
        }).catch(done);
      });
    });

    context('when plugins property missing', function () {
      beforeEach(function() {
        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './',
          configureWebpack: {}
        }));
      });

      it('warns and resolves', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(contains('vue.config.js')));
          done();
        }).catch(done);
      });
    });

    context('when plugins property missing webpack plugin', function () {
      beforeEach(function() {
        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './',
          configureWebpack: {
            plugins: []
          }
        }));
      });

      it('warns and resolves', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(contains('vue.config.js')));
          done();
        }).catch(done);
      });
    });

    context('when plugins property includes webpack plugin', function () {
      beforeEach(function() {
        function CorberWebpackPlugin() {}

        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './',
          configureWebpack: {
            plugins: [new CorberWebpackPlugin()]
          }
        }));
      });

      it('resolves silently', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(), { times: 0, ignoreExtraArgs: true });
          done();
        }).catch(done);
      });
    });
  });

  context('when config path from Vue CLI v2', function() {
    beforeEach(function() {
      validator = initValidator();
      validator.root = mockProject.project.root;
      validator.framework = 'vue';
      validator.configPath = path.join(
        mockProject.project.root,
        'build',
        'webpack.dev.conf'
      );
    });

    context('when plugins property missing', function () {
      beforeEach(function() {
        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './',
        }));
      });

      it('warns and resolves', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(contains('build/webpack.dev.conf')));
          done();
        }).catch(done);
      });
    });

    context('when plugins property missing webpack plugin', function () {
      beforeEach(function() {
        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './',
          plugins: []
        }));
      });

      it('warns and resolves', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(contains('build/webpack.dev.conf')));
          done();
        }).catch(done);
      });
    });

    context('when plugins property includes webpack plugin', function () {
      beforeEach(function() {
        function CorberWebpackPlugin() {}

        td.replace(validator, 'getConfig', () => new Object({
          baseUrl: './',
          plugins: [new CorberWebpackPlugin()]
        }));
      });

      it('resolves silently', function(done) {
        validator.run().then(function() {
          td.verify(warnDouble(), { times: 0, ignoreExtraArgs: true });
          done();
        }).catch(done);
      });
    });
  });

  context('when config path is not from Vue CLI', function() {
    beforeEach(function() {
      validator = initValidator();
      validator.root = mockProject.project.root;
      validator.framework = 'react';
      validator.configPath = path.join(
        mockProject.project.root,
        'config',
        'webpack.config.dev.js'
{'fraction_non_alphanumeric': 0.16597051597051596, 'fraction_numerical': 0.0007371007371007371, 'mean_word_length': 2.272106109324759, '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': '6046', 'n_tokens_mistral': 2253, 'n_tokens_neox': 2237, 'n_words': 425}