Skip to content

Commit 49a4258

Browse files
committed
add tests
1 parent 9892516 commit 49a4258

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

test/WebpackConfig.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,4 +1144,36 @@ describe('WebpackConfig object', () => {
11441144
}).to.throw('Argument 1 to configureWatchOptions() must be a callback function.');
11451145
});
11461146
});
1147+
1148+
describe('configureLoaderRule()', () => {
1149+
it('works properly', () => {
1150+
const config = createConfig();
1151+
const callback = (loader) => {};
1152+
1153+
expect(config.loaderConfigurationCallbacks['eslint']).to.not.equal(callback);
1154+
1155+
config.configureLoaderRule('eslint', callback);
1156+
expect(config.loaderConfigurationCallbacks['eslint']).to.equal(callback);
1157+
});
1158+
1159+
it('Call method with a not supported loader', () => {
1160+
const config = createConfig();
1161+
1162+
expect(() => {
1163+
config.configureLoaderRule('vue');
1164+
}).to.throw('Loader "vue" is not configurable. Either open an issue or a pull request.');
1165+
});
1166+
1167+
it('Call method with not a valid callback', () => {
1168+
const config = createConfig();
1169+
1170+
expect(() => {
1171+
config.configureLoaderRule('eslint');
1172+
}).to.throw('Argument 2 to configureLoaderRule() must be a callback function.');
1173+
1174+
expect(() => {
1175+
config.configureLoaderRule('eslint', {});
1176+
}).to.throw('Argument 2 to configureLoaderRule() must be a callback function.');
1177+
});
1178+
});
11471179
});

test/loaders/eslint.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
const expect = require('chai').expect;
1313
const WebpackConfig = require('../../lib/WebpackConfig');
1414
const RuntimeConfig = require('../../lib/config/RuntimeConfig');
15+
const configGenerator = require('../../lib/config-generator');
1516
const eslintLoader = require('../../lib/loaders/eslint');
17+
const isWindows = (process.platform === 'win32');
1618

1719
function createConfig() {
1820
const runtimeConfig = new RuntimeConfig();
@@ -77,4 +79,29 @@ describe('loaders/eslint', () => {
7779
const actualOptions = eslintLoader.getOptions(config);
7880
expect(actualOptions).to.deep.equals({ foo: true });
7981
});
82+
83+
it('configure ESLint loader rule', () => {
84+
const config = createConfig();
85+
config.outputPath = isWindows ? 'C:\\tmp\\public' : '/tmp/public';
86+
config.setPublicPath('/');
87+
config.enableEslintLoader();
88+
config.configureLoaderRule('eslint', (loader) => {
89+
loader.test = /\.(jsx?|vue)/;
90+
});
91+
92+
const webpackConfig = configGenerator(config);
93+
const eslintLoader = webpackConfig.module.rules.find(rule => rule.loader === 'eslint-loader');
94+
95+
expect(eslintLoader).to.deep.equals({
96+
test: /\.(jsx?|vue)/,
97+
enforce: 'pre',
98+
exclude: /node_modules/,
99+
loader: 'eslint-loader',
100+
options: {
101+
cache: true,
102+
emitWarning: true,
103+
parser: 'babel-eslint'
104+
}
105+
});
106+
});
80107
});

0 commit comments

Comments
 (0)