-
Notifications
You must be signed in to change notification settings - Fork 754
/
init.reload.js
79 lines (71 loc) · 2.69 KB
/
init.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
73
74
75
76
77
78
79
"use strict";
var browserSync = require("../../../");
var sinon = require("sinon");
var assert = require("chai").assert;
var File = require("vinyl");
describe("API: .reload()", function () {
var emitterStub, clock, bs;
before(function (done) {
browserSync.reset();
bs = browserSync({logLevel:"silent"}, function () {
emitterStub = sinon.spy(bs.emitter, "emit");
done();
});
clock = sinon.useFakeTimers();
});
afterEach(function () {
emitterStub.reset();
clock.now = 0;
});
after(function () {
bs.cleanup();
clock.restore();
emitterStub.restore();
});
it("should be callable with no args & perform a reload", function () {
browserSync.reload();
sinon.assert.calledWithExactly(emitterStub, "browser:reload");
});
it("should accept a file path as a string", function () {
browserSync.reload("css/core.css");
sinon.assert.calledWithExactly(emitterStub, "file:changed", {
path: "css/core.css",
log: true,
namespace: "core"
});
});
it("only calls reload once if the array contains a filepath that will cause a reload", function () {
browserSync.reload(["css/core.css", "index.html"]);
var calls = emitterStub.withArgs("browser:reload");
assert.equal(calls.callCount, 1);
sinon.assert.calledWithExactly(emitterStub, "browser:reload");
});
it("calls reload multiple times if all items can be injected", function () {
browserSync.reload(["css/core.css", "ie.css"]);
var calls = emitterStub.withArgs("file:changed");
assert.equal(calls.callCount, 2);
sinon.assert.calledWithExactly(emitterStub, "file:changed", {
path: "css/core.css",
log: true,
namespace: "core"
});
sinon.assert.calledWithExactly(emitterStub, "file:changed", {
path: "ie.css",
log: true,
namespace: "core"
});
});
it("should accept an array of file paths as strings", function () {
browserSync.reload(["index.html", "css/core.css"]);
sinon.assert.calledWithExactly(emitterStub, "browser:reload");
});
it("should reload browser if once:true given as arg", function () {
var stream = browserSync.reload({stream: true, once: true});
stream.write(new File({path: "styles.css"}));
stream.write(new File({path: "styles2.css"}));
stream.write(new File({path: "styles3.css"}));
stream.end();
sinon.assert.calledOnce(emitterStub);
sinon.assert.calledWithExactly(emitterStub, "browser:reload");
});
});