Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(regression): host and port can be undefined or null #1779

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 21 additions & 11 deletions lib/options.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,27 @@
"type": "boolean"
},
"host": {
"type": "string"
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
]
},
"port": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
},
{
"type": "null"
}
]
},
"allowedHosts": {
"type": "array",
Expand All @@ -41,16 +61,6 @@
"publicPath": {
"type": "string"
},
"port": {
"anyOf": [
{
"type": "number"
},
{
"type": "string"
}
]
},
"socket": {
"type": "string"
},
Expand Down
24 changes: 12 additions & 12 deletions test/BeforeAndAfter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,38 @@ describe('Before And After options', () => {
server = helper.start(
config,
{
before: (app, server, compiler) => {
if (!app) {
before: (appArg, serverArg, compilerArg) => {
if (!appArg) {
throw new Error('app is not defined');
}

if (!server) {
if (!serverArg) {
throw new Error('server is not defined');
}

if (!compiler) {
if (!compilerArg) {
throw new Error('compiler is not defined');
}

app.get('/before/some/path', (req, res) => {
res.send('before');
appArg.get('/before/some/path', (_, response) => {
response.send('before');
});
},
after: (app, server, compiler) => {
if (!app) {
after: (appArg, serverArg, compilerArg) => {
if (!appArg) {
throw new Error('app is not defined');
}

if (!server) {
if (!serverArg) {
throw new Error('server is not defined');
}

if (!compiler) {
if (!compilerArg) {
throw new Error('compiler is not defined');
}

app.get('/after/some/path', (req, res) => {
res.send('after');
appArg.get('/after/some/path', (_, response) => {
response.send('after');
});
},
},
Expand Down
58 changes: 58 additions & 0 deletions test/CreateConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ describe('createConfig', () => {
expect(config).toMatchSnapshot();
});

it('host option (undefined)', () => {
const config = createConfig(
webpackConfig,
Object.assign({}, argv, {
// eslint-disable-next-line no-undefined
host: undefined,
}),
{ port: 8080 }
);

expect(config).toMatchSnapshot();
});

it('host option (null)', () => {
const config = createConfig(
webpackConfig,
Object.assign({}, argv, {
// eslint-disable-next-line no-undefined
host: null,
}),
{ port: 8080 }
);

expect(config).toMatchSnapshot();
});

it('host option (devServer config)', () => {
const config = createConfig(
Object.assign({}, webpackConfig, { devServer: { host: 'example.dev' } }),
Expand Down Expand Up @@ -893,6 +919,38 @@ describe('createConfig', () => {
expect(config).toMatchSnapshot();
});

it('port option (same) (string)', () => {
const config = createConfig(
webpackConfig,
Object.assign({}, argv, { port: '9090' }),
{ port: '9090' }
);

expect(config).toMatchSnapshot();
});

it('port option (same) (null)', () => {
const config = createConfig(
webpackConfig,
Object.assign({}, argv, { port: null }),
{ port: null }
);

expect(config).toMatchSnapshot();
});

it('port option (same) (undefined)', () => {
const config = createConfig(
webpackConfig,
// eslint-disable-next-line no-undefined
Object.assign({}, argv, { port: undefined }),
// eslint-disable-next-line no-undefined
{ port: undefined }
);

expect(config).toMatchSnapshot();
});

it('port option (difference)', () => {
const config = createConfig(
webpackConfig,
Expand Down