File tree 2 files changed +62
-0
lines changed
2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -315,6 +315,24 @@ function create(name, emitter) {
315
315
}
316
316
});
317
317
318
+ /**
319
+ * Access to client-side socket for emitting events
320
+ *
321
+ * @property sockets
322
+ */
323
+ Object.defineProperty(instance, "sockets", {
324
+ get: function () {
325
+ if (!browserSync.active) {
326
+ return {
327
+ emit: function () {},
328
+ on: function () {}
329
+ };
330
+ } else {
331
+ return browserSync.io.sockets;
332
+ }
333
+ }
334
+ });
335
+
318
336
instances.push(instance);
319
337
320
338
return instance;
Original file line number Diff line number Diff line change
1
+ "use strict";
2
+
3
+ var browserSync = require("../../../");
4
+
5
+ var assert = require("chai").assert;
6
+
7
+ describe("API: .sockets", function () {
8
+
9
+ it("has access before Browsersync is running via stubs", function (done) {
10
+ browserSync.reset();
11
+ var bs = browserSync.create();
12
+ bs.init({
13
+ logLevel: "silent"
14
+ }, function (err, bs) {
15
+ bs.cleanup();
16
+ done();
17
+ });
18
+ assert.isFunction(bs.sockets.on);
19
+ assert.isFunction(bs.sockets.emit);
20
+ });
21
+ it("has access after Browsersync is running", function (done) {
22
+ browserSync.reset();
23
+ var bs = browserSync.create();
24
+ bs.init({
25
+ logLevel: "silent"
26
+ }, function (err, _bs) {
27
+ assert.isFunction(bs.sockets.emit);
28
+ assert.isFunction(bs.sockets.on);
29
+ _bs.cleanup();
30
+ done();
31
+ });
32
+ });
33
+ it("has access before Browsersync is running via main module export + stubs", function (done) {
34
+ browserSync.reset();
35
+ var bs = browserSync({
36
+ logLevel: "silent"
37
+ }, function (err, bs) {
38
+ bs.cleanup();
39
+ done();
40
+ });
41
+ assert.isFunction(bs.sockets.on);
42
+ assert.isFunction(bs.sockets.emit);
43
+ });
44
+ });
You can’t perform that action at this time.
0 commit comments