Skip to content

Commit 2b8f313

Browse files
author
Shane Osbourne
committed
fix(callbacks): Bind public instance to callbacks - fixes BrowserSync#674
1 parent f0004d1 commit 2b8f313

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/browser-sync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ BrowserSync.prototype.callback = function (name) {
5959
var cb = bs.options.getIn(["callbacks", name]);
6060

6161
if (_.isFunction(cb)) {
62-
cb.apply(bs, _.toArray(arguments).slice(1));
62+
cb.apply(bs.publicInstance, _.toArray(arguments).slice(1));
6363
}
6464
};
6565

test/specs/e2e/e2e.options.callbacks.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
"use strict";
22

33
var browserSync = require("../../../");
4+
var assert = require("chai").assert;
45

56
describe("E2E options test - ready callback as option", function () {
67

7-
it("Sets the available port", function (done) {
8+
it("Calls the ready callback when read", function (done) {
89
browserSync.reset();
910
browserSync({
1011
server: {
@@ -20,4 +21,24 @@ describe("E2E options test - ready callback as option", function () {
2021
}
2122
});
2223
});
24+
it("It has public instance bound to `this`", function (done) {
25+
browserSync.reset();
26+
browserSync({
27+
server: {
28+
baseDir: "test/fixtures"
29+
},
30+
open: false,
31+
logLevel: "silent",
32+
callbacks: {
33+
ready: function () {
34+
var bs = this;
35+
assert.isFunction(bs.reload);
36+
assert.isFunction(bs.notify);
37+
assert.isFunction(bs.watch);
38+
bs.cleanup();
39+
done();
40+
}
41+
}
42+
});
43+
});
2344
});

0 commit comments

Comments
 (0)