Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kocal committed Mar 1, 2019
1 parent 9892516 commit 49a4258
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -1144,4 +1144,36 @@ describe('WebpackConfig object', () => {
}).to.throw('Argument 1 to configureWatchOptions() must be a callback function.');
});
});

describe('configureLoaderRule()', () => {
it('works properly', () => {
const config = createConfig();
const callback = (loader) => {};

expect(config.loaderConfigurationCallbacks['eslint']).to.not.equal(callback);

config.configureLoaderRule('eslint', callback);
expect(config.loaderConfigurationCallbacks['eslint']).to.equal(callback);
});

it('Call method with a not supported loader', () => {
const config = createConfig();

expect(() => {
config.configureLoaderRule('vue');
}).to.throw('Loader "vue" is not configurable. Either open an issue or a pull request.');
});

it('Call method with not a valid callback', () => {
const config = createConfig();

expect(() => {
config.configureLoaderRule('eslint');
}).to.throw('Argument 2 to configureLoaderRule() must be a callback function.');

expect(() => {
config.configureLoaderRule('eslint', {});
}).to.throw('Argument 2 to configureLoaderRule() must be a callback function.');
});
});
});
27 changes: 27 additions & 0 deletions test/loaders/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
const expect = require('chai').expect;
const WebpackConfig = require('../../lib/WebpackConfig');
const RuntimeConfig = require('../../lib/config/RuntimeConfig');
const configGenerator = require('../../lib/config-generator');
const eslintLoader = require('../../lib/loaders/eslint');
const isWindows = (process.platform === 'win32');

function createConfig() {
const runtimeConfig = new RuntimeConfig();
Expand Down Expand Up @@ -77,4 +79,29 @@ describe('loaders/eslint', () => {
const actualOptions = eslintLoader.getOptions(config);
expect(actualOptions).to.deep.equals({ foo: true });
});

it('configure ESLint loader rule', () => {
const config = createConfig();
config.outputPath = isWindows ? 'C:\\tmp\\public' : '/tmp/public';
config.setPublicPath('/');
config.enableEslintLoader();
config.configureLoaderRule('eslint', (loader) => {
loader.test = /\.(jsx?|vue)/;
});

const webpackConfig = configGenerator(config);
const eslintLoader = webpackConfig.module.rules.find(rule => rule.loader === 'eslint-loader');

expect(eslintLoader).to.deep.equals({
test: /\.(jsx?|vue)/,
enforce: 'pre',
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
cache: true,
emitWarning: true,
parser: 'babel-eslint'
}
});
});
});

0 comments on commit 49a4258

Please sign in to comment.