From da53dc21c6f7afd801a9f00489a6df2ab46156bb Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Fri, 13 Mar 2015 16:01:07 +0000 Subject: [PATCH] fix(reload): Allow multiple instances to call their own `.reload()` method - fixes #511 --- index.js | 6 ++++-- test/specs/api/init.reload.multi.js | 16 +++++++++++----- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 2b0477d08..feaa1e0ee 100755 --- a/index.js +++ b/index.js @@ -234,8 +234,10 @@ function getSingle(name) { */ function create(name, emitter) { - name = name || new Date().getTime(); - var browserSync = new BrowserSync(emitter || newEmitter(), name); + name = name || new Date().getTime(); + emitter = emitter || newEmitter(); + + var browserSync = new BrowserSync(emitter, name); var instance = { name: name, diff --git a/test/specs/api/init.reload.multi.js b/test/specs/api/init.reload.multi.js index cbf8f80b2..0a1b6f5ce 100644 --- a/test/specs/api/init.reload.multi.js +++ b/test/specs/api/init.reload.multi.js @@ -7,16 +7,20 @@ var assert = require("chai").assert; describe("API: .reload() with multi instances", function () { - var clock, bs1, bs2; + var clock, bs1, bs2, emitter1, emitter2; before(function (done) { browserSync.reset(); - bs1 = browserSync.create("Server 1").init({logLevel:"silent"}, function () { - bs2 = browserSync.create("Server 2").init({logLevel: "silent"}, function () { + browserSync.create("Server 1").init({logLevel:"silent"}, function (err, bs) { + bs1 = bs; + emitter1 = sinon.spy(bs.events, "emit"); + browserSync.create("Server 2").init({logLevel: "silent"}, function (err, bs) { + bs2 = bs; + emitter2 = sinon.spy(bs.events, "emit"); done(); - }).instance; - }).instance; + }); + }); clock = sinon.useFakeTimers(); }); @@ -26,6 +30,8 @@ describe("API: .reload() with multi instances", function () { }); after(function () { + bs1.cleanup(); + bs2.cleanup(); clock.restore(); });