/
config.js
146 lines (119 loc) · 5.21 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
var chai = require('chai')
, expect = chai.expect
, path = require('path')
var resolve = require('../index').resolve
var file = path.join(__dirname, 'files', 'src', 'jsx', 'dummy.js')
var extensionFile = path.join(__dirname, 'config-extensions', 'src', 'dummy.js')
var 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 () {
var 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 () {
var 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 () {
var 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 () {
var 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 () {
var 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 $PWD path placeholder", function () {
var settings = {
config: './resolvers/webpack/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 () {
var 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 () {
var 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() {
var 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() {
var 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() {
var 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() {
var settings = {
config: require(path.join(__dirname, './files/webpack.function.config.js')),
argv: undefined
}
expect(function () { resolve('baz', file, settings) }).to.not.throw(Error)
})
})