Skip to content

Commit 028ceee

Browse files
fix(regression): host and port can be undefined or null (#1779)
1 parent f5ea174 commit 028ceee

6 files changed

+458
-25
lines changed

lib/options.json

+21-11
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,27 @@
1717
"type": "boolean"
1818
},
1919
"host": {
20-
"type": "string"
20+
"anyOf": [
21+
{
22+
"type": "string"
23+
},
24+
{
25+
"type": "null"
26+
}
27+
]
28+
},
29+
"port": {
30+
"anyOf": [
31+
{
32+
"type": "number"
33+
},
34+
{
35+
"type": "string"
36+
},
37+
{
38+
"type": "null"
39+
}
40+
]
2141
},
2242
"allowedHosts": {
2343
"type": "array",
@@ -41,16 +61,6 @@
4161
"publicPath": {
4262
"type": "string"
4363
},
44-
"port": {
45-
"anyOf": [
46-
{
47-
"type": "number"
48-
},
49-
{
50-
"type": "string"
51-
}
52-
]
53-
},
5464
"socket": {
5565
"type": "string"
5666
},

test/BeforeAndAfter.test.js

+12-12
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,38 @@ describe('Before And After options', () => {
1212
server = helper.start(
1313
config,
1414
{
15-
before: (app, server, compiler) => {
16-
if (!app) {
15+
before: (appArg, serverArg, compilerArg) => {
16+
if (!appArg) {
1717
throw new Error('app is not defined');
1818
}
1919

20-
if (!server) {
20+
if (!serverArg) {
2121
throw new Error('server is not defined');
2222
}
2323

24-
if (!compiler) {
24+
if (!compilerArg) {
2525
throw new Error('compiler is not defined');
2626
}
2727

28-
app.get('/before/some/path', (req, res) => {
29-
res.send('before');
28+
appArg.get('/before/some/path', (_, response) => {
29+
response.send('before');
3030
});
3131
},
32-
after: (app, server, compiler) => {
33-
if (!app) {
32+
after: (appArg, serverArg, compilerArg) => {
33+
if (!appArg) {
3434
throw new Error('app is not defined');
3535
}
3636

37-
if (!server) {
37+
if (!serverArg) {
3838
throw new Error('server is not defined');
3939
}
4040

41-
if (!compiler) {
41+
if (!compilerArg) {
4242
throw new Error('compiler is not defined');
4343
}
4444

45-
app.get('/after/some/path', (req, res) => {
46-
res.send('after');
45+
appArg.get('/after/some/path', (_, response) => {
46+
response.send('after');
4747
});
4848
},
4949
},

test/CreateConfig.test.js

+58
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ describe('createConfig', () => {
6868
expect(config).toMatchSnapshot();
6969
});
7070

71+
it('host option (undefined)', () => {
72+
const config = createConfig(
73+
webpackConfig,
74+
Object.assign({}, argv, {
75+
// eslint-disable-next-line no-undefined
76+
host: undefined,
77+
}),
78+
{ port: 8080 }
79+
);
80+
81+
expect(config).toMatchSnapshot();
82+
});
83+
84+
it('host option (null)', () => {
85+
const config = createConfig(
86+
webpackConfig,
87+
Object.assign({}, argv, {
88+
// eslint-disable-next-line no-undefined
89+
host: null,
90+
}),
91+
{ port: 8080 }
92+
);
93+
94+
expect(config).toMatchSnapshot();
95+
});
96+
7197
it('host option (devServer config)', () => {
7298
const config = createConfig(
7399
Object.assign({}, webpackConfig, { devServer: { host: 'example.dev' } }),
@@ -893,6 +919,38 @@ describe('createConfig', () => {
893919
expect(config).toMatchSnapshot();
894920
});
895921

922+
it('port option (same) (string)', () => {
923+
const config = createConfig(
924+
webpackConfig,
925+
Object.assign({}, argv, { port: '9090' }),
926+
{ port: '9090' }
927+
);
928+
929+
expect(config).toMatchSnapshot();
930+
});
931+
932+
it('port option (same) (null)', () => {
933+
const config = createConfig(
934+
webpackConfig,
935+
Object.assign({}, argv, { port: null }),
936+
{ port: null }
937+
);
938+
939+
expect(config).toMatchSnapshot();
940+
});
941+
942+
it('port option (same) (undefined)', () => {
943+
const config = createConfig(
944+
webpackConfig,
945+
// eslint-disable-next-line no-undefined
946+
Object.assign({}, argv, { port: undefined }),
947+
// eslint-disable-next-line no-undefined
948+
{ port: undefined }
949+
);
950+
951+
expect(config).toMatchSnapshot();
952+
});
953+
896954
it('port option (difference)', () => {
897955
const config = createConfig(
898956
webpackConfig,

0 commit comments

Comments
 (0)