-
-
Notifications
You must be signed in to change notification settings - Fork 198
/
eslint.js
94 lines (75 loc) · 2.67 KB
/
eslint.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* This file is part of the Symfony Webpack Encore package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
'use strict';
const expect = require('chai').expect;
const WebpackConfig = require('../../lib/WebpackConfig');
const RuntimeConfig = require('../../lib/config/RuntimeConfig');
const eslintLoader = require('../../lib/loaders/eslint');
function createConfig() {
const runtimeConfig = new RuntimeConfig();
runtimeConfig.context = __dirname;
runtimeConfig.babelRcFileExists = false;
return new WebpackConfig(runtimeConfig);
}
describe('loaders/eslint', () => {
it('getOptions() full usage', () => {
const config = createConfig();
config.enableEslintLoader();
const actualOptions = eslintLoader.getOptions(config);
expect(actualOptions).to.deep.equal({
cache: true,
emitWarning: true
});
});
it('getOptions() with extra options', () => {
const config = createConfig();
config.enableEslintLoader((options) => {
options.extends = 'airbnb';
});
const actualOptions = eslintLoader.getOptions(config);
expect(actualOptions).to.deep.equal({
cache: true,
emitWarning: true,
extends: 'airbnb'
});
});
it('getOptions() with an overridden option', () => {
const config = createConfig();
config.enableEslintLoader((options) => {
options.emitWarning = false;
});
const actualOptions = eslintLoader.getOptions(config);
expect(actualOptions).to.deep.equal({
cache: true,
emitWarning: false
});
});
it('getOptions() with a callback that returns an object', () => {
const config = createConfig();
config.enableEslintLoader((options) => {
options.custom_option = 'foo';
return { foo: true };
});
const actualOptions = eslintLoader.getOptions(config);
expect(actualOptions).to.deep.equals({ foo: true });
});
it('getTest() base behavior', () => {
const config = createConfig();
const actualTest = eslintLoader.getTest(config);
expect(actualTest.toString()).to.equals(/\.(jsx?)$/.toString());
});
it('getTest() with Vue', () => {
const config = createConfig();
config.enableEslintLoader(() => {}, {
lintVue: true,
});
const actualTest = eslintLoader.getTest(config);
expect(actualTest.toString()).to.equals(/\.(jsx?|vue)$/.toString());
});
});