forked from BrowserSync/browser-sync
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(file-watching): use canLogFileChange() to determine whether file:…
…reload, stream:changed & browser:reload should log to the console - fixes BrowserSync#479
- Loading branch information
1 parent
86191d9
commit 164154e
Showing
3 changed files
with
153 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
"use strict"; | ||
|
||
var browserSync = require("../../../"); | ||
var logger = require("../../../lib/logger").logger; | ||
var callbacks = require("../../../lib/logger").callbacks; | ||
var sinon = require("sinon"); | ||
|
||
describe("Logs file change events following stream:changed", function () { | ||
var spy; | ||
before(function () { | ||
spy = sinon.stub(logger, "info"); | ||
}); | ||
afterEach(function () { | ||
spy.reset(); | ||
}); | ||
after(function () { | ||
logger.info.restore(); | ||
}); | ||
it("should log when straem:changed", function (done) { | ||
browserSync.reset(); | ||
browserSync({ | ||
server: "./app", | ||
files: "*.html", | ||
open: false | ||
}, function (err, bs) { | ||
spy.reset(); | ||
callbacks["stream:changed"](bs, {changed: ["core.css"]}); | ||
sinon.assert.called(spy); | ||
bs.cleanup(done); | ||
}); | ||
}); | ||
it("should NOT log when stream:changed but logFileChanges = false", function (done) { | ||
browserSync.reset(); | ||
browserSync({ | ||
server: "./app", | ||
files: "*.html", | ||
logFileChanges: false, | ||
open: false | ||
}, function (err, bs) { | ||
spy.reset(); | ||
callbacks["stream:changed"](bs, {changed: ["core.css"]}); | ||
sinon.assert.notCalled(spy); | ||
bs.cleanup(done); | ||
}); | ||
}); | ||
it("should log when file:reload", function (done) { | ||
browserSync.reset(); | ||
browserSync({ | ||
server: "./app", | ||
files: "*.html", | ||
open: false | ||
}, function (err, bs) { | ||
spy.reset(); | ||
callbacks["file:reload"](bs, {log: true, path: "style.css", cwd: "/users/shane"}); | ||
sinon.assert.called(spy); | ||
bs.cleanup(done); | ||
}); | ||
}); | ||
it("should NOT log when file:reload but log:false", function (done) { | ||
browserSync.reset(); | ||
browserSync({ | ||
server: "./app", | ||
files: "*.html", | ||
open: false | ||
}, function (err, bs) { | ||
spy.reset(); | ||
callbacks["file:reload"](bs, {log: false, path: "style.css", cwd: "/users/shane"}); | ||
sinon.assert.notCalled(spy); | ||
bs.cleanup(done); | ||
}); | ||
}); | ||
it("should NOT log when options logFileChanges = false", function (done) { | ||
browserSync.reset(); | ||
browserSync({ | ||
server: "./app", | ||
files: "*.html", | ||
logFileChanges: false, | ||
open: false | ||
}, function (err, bs) { | ||
spy.reset(); | ||
callbacks["file:reload"](bs, {log: true, path: "style.css", cwd: "/users/shane"}); | ||
sinon.assert.notCalled(spy); | ||
bs.cleanup(done); | ||
}); | ||
}); | ||
it("should log when browser:reload", function (done) { | ||
browserSync.reset(); | ||
browserSync({ | ||
server: "./app", | ||
files: "*.html", | ||
open: false | ||
}, function (err, bs) { | ||
spy.reset(); | ||
callbacks["browser:reload"](bs); | ||
sinon.assert.called(spy); | ||
bs.cleanup(done); | ||
}); | ||
}); | ||
it("should NOT log when browser:reload but logFileChanges = false", function (done) { | ||
browserSync.reset(); | ||
browserSync({ | ||
server: "./app", | ||
files: "*.html", | ||
logFileChanges: false, | ||
open: false | ||
}, function (err, bs) { | ||
spy.reset(); | ||
callbacks["browser:reload"](bs); | ||
sinon.assert.notCalled(spy); | ||
bs.cleanup(done); | ||
}); | ||
}); | ||
}); |