diff --git a/lib/utils/runBonjour.js b/lib/utils/runBonjour.js index 8085eb8215..3add365d53 100644 --- a/lib/utils/runBonjour.js +++ b/lib/utils/runBonjour.js @@ -2,9 +2,10 @@ function runBonjour({ port }) { const bonjour = require('bonjour')(); + const os = require('os'); bonjour.publish({ - name: 'Webpack Dev Server', + name: `Webpack Dev Server ${os.hostname()}:${port}`, port, type: 'http', subtypes: ['webpack'], diff --git a/test/server/utils/__snapshots__/ runBonjour.test.js.snap b/test/server/utils/__snapshots__/runBonjour.test.js.snap similarity index 80% rename from test/server/utils/__snapshots__/ runBonjour.test.js.snap rename to test/server/utils/__snapshots__/runBonjour.test.js.snap index e0dab41696..ce580fbb82 100644 --- a/test/server/utils/__snapshots__/ runBonjour.test.js.snap +++ b/test/server/utils/__snapshots__/runBonjour.test.js.snap @@ -2,7 +2,7 @@ exports[`runBonjour should call bonjour.publish 1`] = ` Object { - "name": "Webpack Dev Server", + "name": "Webpack Dev Server hostname:1111", "port": 1111, "subtypes": Array [ "webpack", diff --git a/test/server/utils/ runBonjour.test.js b/test/server/utils/runBonjour.test.js similarity index 63% rename from test/server/utils/ runBonjour.test.js rename to test/server/utils/runBonjour.test.js index 66730dc326..e416a7fa62 100644 --- a/test/server/utils/ runBonjour.test.js +++ b/test/server/utils/runBonjour.test.js @@ -2,6 +2,12 @@ const runBonjour = require('../../../lib/utils/runBonjour'); +jest.mock('os', () => { + return { + hostname: () => 'hostname', + }; +}); + describe('runBonjour', () => { let mock; let publish = jest.fn(); @@ -32,4 +38,17 @@ describe('runBonjour', () => { expect(publish.mock.calls[0][0]).toMatchSnapshot(); }); + + it('should call bonjour.publish with different name for different ports', () => { + runBonjour({ + port: 1111, + }); + runBonjour({ + port: 2222, + }); + + const calls = publish.mock.calls; + + expect(calls[0][0].name).not.toEqual(calls[1][0].name); + }); });