forked from import-js/eslint-plugin-import
-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.js
158 lines (128 loc) · 5.61 KB
/
config.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
'use strict';
const chai = require('chai');
const expect = chai.expect;
const path = require('path');
const resolve = require('../index').resolve;
const file = path.join(__dirname, 'files', 'src', 'jsx', 'dummy.js');
const extensionFile = path.join(__dirname, 'config-extensions', 'src', 'dummy.js');
const absoluteSettings = {
config: path.join(__dirname, 'files', 'some', 'absolute.path.webpack.config.js'),
};
describe('config', function () {
it('finds webpack.config.js in parent directories', function () {
expect(resolve('main-module', file)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'));
});
it('finds absolute webpack.config.js files', function () {
expect(resolve('foo', file, absoluteSettings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js'));
});
it('finds compile-to-js configs', function () {
const settings = {
config: path.join(__dirname, './files/webpack.config.babel.js'),
};
expect(resolve('main-module', file, settings))
.to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'));
});
it('finds compile-to-js config in parent directories', function () {
expect(resolve('main-module', extensionFile))
.to.have.property('path')
.and.equal(path.join(__dirname, 'config-extensions', 'src', 'main-module.js'));
});
it('finds the first config with a resolve section', function () {
const settings = {
config: path.join(__dirname, './files/webpack.config.multiple.js'),
};
expect(resolve('main-module', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'));
});
it('finds the config at option config-index', function () {
const settings = {
config: path.join(__dirname, './files/webpack.config.multiple.js'),
'config-index': 2,
};
expect(resolve('foo', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'foo.js'));
});
it("doesn't swallow config load errors (#435)", function () {
const settings = {
config: path.join(__dirname, './files/webpack.config.garbage.js'),
};
expect(function () { resolve('foo', file, settings); }).to.throw(Error);
});
it('finds config object when config is an object', function () {
const settings = {
config: require(path.join(__dirname, 'files', 'some', 'absolute.path.webpack.config.js')),
};
expect(resolve('foo', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js'));
});
it('finds config object when config uses a path relative to working dir', function () {
const settings = {
config: './test/files/some/absolute.path.webpack.config.js',
};
expect(resolve('foo', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'absolutely', 'goofy', 'path', 'foo.js'));
});
it('finds the first config with a resolve section when config is an array of config objects', function () {
const settings = {
config: require(path.join(__dirname, './files/webpack.config.multiple.js')),
};
expect(resolve('main-module', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'src', 'main-module.js'));
});
it('finds the config at option config-index when config is an array of config objects', function () {
const settings = {
config: require(path.join(__dirname, './files/webpack.config.multiple.js')),
'config-index': 2,
};
expect(resolve('foo', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'foo.js'));
});
it('finds the config at option env when config is a function', function () {
const settings = {
config: require(path.join(__dirname, './files/webpack.function.config.js')),
env: {
dummy: true,
},
};
expect(resolve('bar', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'bar.js'));
});
it('finds the config at option env when config is an array of functions', function () {
const settings = {
config: require(path.join(__dirname, './files/webpack.function.config.multiple.js')),
env: {
dummy: true,
},
};
expect(resolve('bar', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'bar.js'));
});
it('passes argv to config when it is a function', function () {
const settings = {
config: require(path.join(__dirname, './files/webpack.function.config.js')),
argv: {
mode: 'test',
},
};
expect(resolve('baz', file, settings)).to.have.property('path')
.and.equal(path.join(__dirname, 'files', 'some', 'bar', 'bar.js'));
});
it('passes a default empty argv object to config when it is a function', function () {
const settings = {
config: require(path.join(__dirname, './files/webpack.function.config.js')),
argv: undefined,
};
expect(function () { resolve('baz', file, settings); }).to.not.throw(Error);
});
it('prevents async config using', function () {
const settings = {
config: require(path.join(__dirname, './files/webpack.config.async.js')),
};
const result = resolve('foo', file, settings);
expect(result).not.to.have.property('path');
expect(result).to.have.property('found').to.be.false;
});
});