Skip to content

Commit

Permalink
fix(regression): host and port can be undefined or null
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Apr 9, 2019
1 parent f5ea174 commit 9f19116
Show file tree
Hide file tree
Showing 6 changed files with 504 additions and 24 deletions.
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
Loading

0 comments on commit 9f19116

Please sign in to comment.