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 authored and evilebottnawi committed Oct 14, 2019
1 parent 6d1f24f commit d8af2d9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/utils/runBonjour.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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,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);
});
});

0 comments on commit d8af2d9

Please # to comment.