Skip to content

Commit 724639d

Browse files
nlarchejonathanglasmeyer
authored andcommitted
feat(webpack-dev-server): Validate webpack-dev-server specific fields (#75)
according to the source : https://github.com/webpack/webpack-dev-server/blob/master/bin/webpack-dev-server.js closes #21
1 parent 7e68ac3 commit 724639d

File tree

3 files changed

+130
-1
lines changed

3 files changed

+130
-1
lines changed

src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import pluginsSchema from './properties/plugins'
1010
import resolveSchema from './properties/resolve'
1111
import outputSchema from './properties/output'
1212
import watchOptionsSchema from './properties/watchOptions'
13+
import devServerSchema from './properties/devServer'
1314
import { absolutePath } from './types'
1415

1516
const schema = Joi.object({
@@ -18,7 +19,7 @@ const schema = Joi.object({
1819
cache: Joi.boolean(),
1920
context: contextSchema,
2021
debug: Joi.boolean(),
21-
devServer: Joi.object(),
22+
devServer: devServerSchema,
2223
devtool: devtoolSchema,
2324
entry: entrySchema,
2425
externals: externalsSchema,

src/properties/devServer/index.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import Joi from 'joi'
2+
import watchOptionsSchema from '../watchOptions'
3+
import { notAbsolutePath, urlPart } from '../../types'
4+
5+
export default Joi.object({
6+
lazy: Joi.boolean(),
7+
inline: Joi.boolean(),
8+
stdin: Joi.boolean(),
9+
open: Joi.boolean(),
10+
info: Joi.boolean(),
11+
quiet: Joi.boolean(),
12+
https: Joi.boolean(),
13+
key: Joi.string(),
14+
cert: Joi.string(),
15+
cacert: Joi.string(),
16+
contentBase: [
17+
Joi.object(),
18+
Joi.array(),
19+
Joi.string(),
20+
],
21+
historyApiFallback: Joi.boolean(),
22+
compress: Joi.boolean(),
23+
port: Joi.number(),
24+
public: Joi.string(),
25+
host: Joi.string(),
26+
publicPath: urlPart,
27+
outputPath: urlPart,
28+
filename: notAbsolutePath,
29+
watchOptions: watchOptionsSchema,
30+
hot: Joi.boolean(),
31+
stats: Joi.object(),
32+
noInfo: Joi.boolean(),
33+
proxy: [
34+
Joi.object(),
35+
Joi.array(),
36+
Joi.string(),
37+
],
38+
staticOptions: Joi.object(),
39+
headers: Joi.object(),
40+
})
41+
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import schema from './index'
2+
import { allValid, allInvalid } from '../../../test/utils'
3+
import { urlPart } from '../../types'
4+
5+
const validModuleConfigs = [
6+
// #0
7+
{ lazy: true },
8+
// #1
9+
{ inline: true },
10+
// #2
11+
{ stdin: true },
12+
// #2
13+
{ open: true },
14+
// #4
15+
{ info: true },
16+
// #5
17+
{ quiet: true },
18+
// #6
19+
{ https: true },
20+
// #7
21+
{ key: '/path/to/key' },
22+
// #8
23+
{ cert: 'path/to/cert' },
24+
// #9
25+
{ cacert: 'path/to/cacert' },
26+
// #10
27+
{ contentBase: '/content/base' },
28+
// #11
29+
{ contentBase: { target: '/content/base/' } },
30+
// #12
31+
{ contentBase: ['/content/base/'] },
32+
// #13
33+
{ historyApiFallback: true },
34+
// #14
35+
{ compress: true },
36+
// #15
37+
{ port: 3000 },
38+
// #16
39+
{ public: 'localhost' },
40+
// #17
41+
{ host: '0.0.0.0' },
42+
// #18
43+
{ publicPath: '/public/path/' },
44+
// #19
45+
{ publicPath: 'public/path/' },
46+
// #20
47+
{ outputPath: '/' },
48+
// #21
49+
{ filename: 'bundle.js' },
50+
// #22
51+
{ watchOptions: {} },
52+
// #23
53+
{ hot: true },
54+
// #24
55+
{ stats: {} },
56+
// #25
57+
{ noInfo: true },
58+
// #26
59+
{ proxy: {} },
60+
// #27
61+
{ proxy: 'http://proxy.url/' },
62+
// #28
63+
{ proxy: [] },
64+
// #29
65+
{ staticOptions: {} },
66+
// #30
67+
{ headers: {} },
68+
]
69+
70+
const invalidModuleConfigs = [
71+
// #0
72+
{ input: { publicPath: 'public/path' }, error: { message: `"publicPath" ${urlPart.message}` } },
73+
// #1
74+
{ input: { outputPath: './output/path' }, error: { message: `"outputPath" ${urlPart.message}` } },
75+
// #2
76+
{ input: { watchOptions: true } },
77+
// #3
78+
{ input: { stats: true } },
79+
// #4
80+
{ input: { proxy: true } },
81+
]
82+
83+
describe('output', () => {
84+
allValid(validModuleConfigs, schema)
85+
allInvalid(invalidModuleConfigs, schema)
86+
})
87+

0 commit comments

Comments
 (0)