Skip to content
This repository has been archived by the owner on Oct 13, 2018. It is now read-only.

Allow to access browserSync instance from a plugin #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ exports.init = function (options) {

var browserSync = new BrowserSync(options);

// Expose browserSync instance to allow runtime extensions
BS.use = function (cb) {
cb(browserSync);
};

// Always init on page load
ghostMode.init(browserSync);
codeSync.init(browserSync);
Expand Down
17 changes: 16 additions & 1 deletion test/client-new/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe("Init method", function(){
var ghostMode = window.__bs_ghost_mode__;
var bs = window.__bs_stub__;
var codeSync = window.__bs_code_sync__;
var BrowserSync = window.__bs;
var notifySpy;
var notifyFlashSpy;
var ghostStub;
Expand All @@ -16,17 +17,31 @@ describe("Init method", function(){
ghostStub = sinon.stub(ghostMode, "init");
codeSyncStub = sinon.stub(codeSync, "init");
});
beforeEach(function () {
window.___browserSync___ = {};
});
afterEach(function (){
delete window.___browserSync___;
});
after(function () {
notifySpy.restore();
notifyFlashSpy.restore();
ghostStub.restore();
codeSyncStub.restore();
});
it("should initilize", function(){
it("should initialize", function(){
index.init(bs.options);
sinon.assert.called(notifySpy);
sinon.assert.called(notifyFlashSpy);
sinon.assert.called(ghostStub);
sinon.assert.called(codeSyncStub);
});
it("should expose browserSync instance", function(){
var spy = sinon.spy();
var BS = window.___browserSync___;
index.init(bs.options);
assert.equal(typeof BS.use === "function", true);
BS.use(spy);
sinon.assert.calledWith(spy, sinon.match.instanceOf(BrowserSync));
});
});