-
Notifications
You must be signed in to change notification settings - Fork 757
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reload): Add reload-delay and reload-debounce to cli - fixes #329
- Loading branch information
1 parent
a75dd5a
commit 42cac56
Showing
4 changed files
with
111 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
"use strict"; | ||
|
||
var browserSync = require("../../../"); | ||
var sinon = require("sinon"); | ||
var assert = require("chai").assert; | ||
|
||
describe("File Watcher Module - reloadDebounce = 0", function () { | ||
var bs, clock, stub, data; | ||
before(function (done) { | ||
browserSync.reset(); | ||
var config = { | ||
server: "test/fixtures", | ||
open: false, | ||
logLevel: "silent", | ||
reloadDebounce: 0, | ||
online: false | ||
}; | ||
clock = sinon.useFakeTimers(); | ||
bs = browserSync(config, function () { | ||
stub = sinon.stub(bs.io.sockets, "emit"); | ||
done(); | ||
}).instance; | ||
}); | ||
beforeEach(function () { | ||
data = {path: "/index.html"}; | ||
clock.now = 0; | ||
}); | ||
after(function () { | ||
clock.restore(); | ||
bs.io.sockets.emit.restore(); | ||
bs.cleanup(); | ||
}); | ||
afterEach(function () { | ||
stub.reset(); | ||
}); | ||
it("Fires as fast as possible with no debounce", function (done) { | ||
bs.events.emit("file:reload", data); | ||
clock.tick(); | ||
bs.events.emit("file:reload", data); | ||
clock.tick(); | ||
assert.isTrue(stub.withArgs("browser:reload").calledTwice); // should be called for each | ||
done(); | ||
}); | ||
}); | ||
|
||
describe("File Watcher Module - reloadDebounce = 1000", function () { | ||
var bs, clock, stub, data; | ||
before(function (done) { | ||
browserSync.reset(); | ||
var config = { | ||
server: "test/fixtures", | ||
open: false, | ||
logLevel: "silent", | ||
reloadDebounce: 1000, | ||
online: false | ||
}; | ||
clock = sinon.useFakeTimers(); | ||
bs = browserSync(config, function () { | ||
stub = sinon.stub(bs.io.sockets, "emit"); | ||
done(); | ||
}).instance; | ||
}); | ||
beforeEach(function () { | ||
data = {path: "/index.html"}; | ||
clock.now = 0; | ||
}); | ||
after(function () { | ||
clock.restore(); | ||
bs.io.sockets.emit.restore(); | ||
bs.cleanup(); | ||
}); | ||
afterEach(function () { | ||
stub.reset(); | ||
}); | ||
it("limits events to a 1000 interval", function (done) { | ||
bs.events.emit("file:reload", data); | ||
clock.tick(50); | ||
bs.events.emit("file:reload", data); | ||
clock.tick(50); | ||
bs.events.emit("file:reload", data); | ||
clock.tick(50); | ||
bs.events.emit("file:reload", data); | ||
clock.tick(1000); | ||
assert.isTrue(stub.withArgs("browser:reload").calledOnce); | ||
done(); | ||
}); | ||
}); |