Skip to content

Commit

Permalink
fix: add hostname and port to bonjour name to prevent name collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
roblan committed Oct 10, 2019
1 parent 6d1f24f commit 61b949e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/utils/runBonjour.js
Expand Up @@ -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'],
Expand Down
Expand Up @@ -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",
Expand Down
Expand Up @@ -2,6 +2,12 @@

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

jest.mock('os', () => {
return {
hostname: () => 'hostname',
};
});

describe('runBonjour', () => {
let mock;
let publish = jest.fn();
Expand Down Expand Up @@ -32,4 +38,16 @@ 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,
});

expect(publish.mock.calls[0][0].name).not.toEqual(publish.mock.calls[1][0].name);
});
});

0 comments on commit 61b949e

Please sign in to comment.