diff --git a/test/WebpackConfig.js b/test/WebpackConfig.js index 6d2f1ffc..8dea504b 100644 --- a/test/WebpackConfig.js +++ b/test/WebpackConfig.js @@ -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.'); + }); + }); }); diff --git a/test/loaders/eslint.js b/test/loaders/eslint.js index 1160e326..77957ede 100644 --- a/test/loaders/eslint.js +++ b/test/loaders/eslint.js @@ -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(); @@ -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' + } + }); + }); });