Skip to content

Commit d8af2d9

Browse files
roblanevilebottnawi
authored andcommitted
fix: add hostname and port to bonjour name to prevent name collisions (#2276)
1 parent 6d1f24f commit d8af2d9

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

lib/utils/runBonjour.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
function runBonjour({ port }) {
44
const bonjour = require('bonjour')();
5+
const os = require('os');
56

67
bonjour.publish({
7-
name: 'Webpack Dev Server',
8+
name: `Webpack Dev Server ${os.hostname()}:${port}`,
89
port,
910
type: 'http',
1011
subtypes: ['webpack'],

test/server/utils/__snapshots__/ runBonjour.test.js.snap test/server/utils/__snapshots__/runBonjour.test.js.snap

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
exports[`runBonjour should call bonjour.publish 1`] = `
44
Object {
5-
"name": "Webpack Dev Server",
5+
"name": "Webpack Dev Server hostname:1111",
66
"port": 1111,
77
"subtypes": Array [
88
"webpack",

test/server/utils/ runBonjour.test.js test/server/utils/runBonjour.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
const runBonjour = require('../../../lib/utils/runBonjour');
44

5+
jest.mock('os', () => {
6+
return {
7+
hostname: () => 'hostname',
8+
};
9+
});
10+
511
describe('runBonjour', () => {
612
let mock;
713
let publish = jest.fn();
@@ -32,4 +38,17 @@ describe('runBonjour', () => {
3238

3339
expect(publish.mock.calls[0][0]).toMatchSnapshot();
3440
});
41+
42+
it('should call bonjour.publish with different name for different ports', () => {
43+
runBonjour({
44+
port: 1111,
45+
});
46+
runBonjour({
47+
port: 2222,
48+
});
49+
50+
const calls = publish.mock.calls;
51+
52+
expect(calls[0][0].name).not.toEqual(calls[1][0].name);
53+
});
3554
});

0 commit comments

Comments
 (0)