Skip to content

Commit 8283a97

Browse files
authored
test: add more cases for host option (#3298)
1 parent 437c8d3 commit 8283a97

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

test/server/host-option.test.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const path = require('path');
44
const request = require('supertest');
5+
const internalIp = require('internal-ip');
56
const config = require('../fixtures/simple-config/webpack.config');
67
const testServer = require('../helpers/test-server');
78
const port = require('../ports-map')['host-option'];
@@ -200,4 +201,68 @@ describe('host option', () => {
200201

201202
afterAll(testServer.close);
202203
});
204+
205+
describe('is local-ip', () => {
206+
beforeAll((done) => {
207+
server = testServer.start(
208+
config,
209+
{
210+
static: {
211+
directory: staticDirectory,
212+
watch: false,
213+
},
214+
host: 'local-ip',
215+
port,
216+
},
217+
done
218+
);
219+
req = request(server.app);
220+
});
221+
222+
it('server address', () => {
223+
const address = server.server.address();
224+
const networkIP = internalIp.v4.sync();
225+
226+
expect(address.address).toBe(networkIP);
227+
expect(address.port).toBe(port);
228+
});
229+
230+
it('Request to index', (done) => {
231+
req.get('/').expect(200, done);
232+
});
233+
234+
afterAll(testServer.close);
235+
});
236+
237+
describe('is local-ipv4', () => {
238+
beforeAll((done) => {
239+
server = testServer.start(
240+
config,
241+
{
242+
static: {
243+
directory: staticDirectory,
244+
watch: false,
245+
},
246+
host: 'local-ipv4',
247+
port,
248+
},
249+
done
250+
);
251+
req = request(server.app);
252+
});
253+
254+
it('server address', () => {
255+
const address = server.server.address();
256+
const networkIP = internalIp.v4.sync();
257+
258+
expect(address.address).toBe(networkIP);
259+
expect(address.port).toBe(port);
260+
});
261+
262+
it('Request to index', (done) => {
263+
req.get('/').expect(200, done);
264+
});
265+
266+
afterAll(testServer.close);
267+
});
203268
});

0 commit comments

Comments
 (0)