-
Notifications
You must be signed in to change notification settings - Fork 754
/
http.reload.js
72 lines (55 loc) · 2.3 KB
/
http.reload.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"use strict";
var browserSync = require("../../../index");
var request = require("request");
var assert = require("chai").assert;
var sinon = require("sinon");
var proto = require("../../../lib/http-protocol");
describe("HTTP protocol", function () {
var bs, spy;
before(function (done) {
browserSync.reset();
var config = {
server: "test/fixtures",
logLevel: "info",
open: false,
online: false
};
bs = browserSync.init(config, done).instance;
spy = sinon.spy(bs.events, "emit");
});
afterEach(function () {
spy.reset();
});
after(function () {
bs.cleanup();
});
it("responds to reload event with no args", function (done) {
var url = proto.getUrl({method: "reload"}, bs.options.getIn(["urls", "local"]));
request(url, function (e, r, body) {
sinon.assert.calledWith(spy, "browser:reload");
assert.include(body, "Called public API method `.reload()`");
assert.include(body, "With args: undefined");
done();
});
});
it("responds to reload event with multi file paths", function (done) {
var url = proto.getUrl({method: "reload", args: ["core.min.css", "core.css"]}, bs.options.getIn(["urls", "local"]));
request(url, function (e, r, body) {
sinon.assert.calledWith(spy, "file:changed");
sinon.assert.calledWithExactly(spy, "file:changed", {path: "core.min.css", log: true, namespace: "core"});
assert.include(body, "Called public API method `.reload()`");
assert.include(body, "With args: [\"core.min.css\",\"core.css\"]");
done();
});
});
it("responds to reload event with single file path", function (done) {
var url = proto.getUrl({method: "reload", args: "somefile.php"}, bs.options.getIn(["urls", "local"]));
request(url, function (e, r, body) {
sinon.assert.calledWith(spy, "file:changed");
sinon.assert.calledWithExactly(spy, "file:changed", {path: "somefile.php", log: true, namespace: "core"});
assert.include(body, "Called public API method `.reload()`");
assert.include(body, "With args: \"somefile.php\"");
done();
});
});
});