Skip to content

Commit

Permalink
fix(file-watcher): defer to default callback should fn property be …
Browse files Browse the repository at this point in the history
…absent from file watching object literals - fixes #643
  • Loading branch information
shakyShane committed May 26, 2015
1 parent c5e6309 commit 9f826cb
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/file-watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ module.exports.plugin = function (bs) {

if (jsItem.objs.length) {
jsItem.objs.forEach(function (item) {
if (!_.isFunction(item.fn)) {
item.fn = fn;
}
var watcher = watch(item.match, item.options || defaultWatchOptions, item.fn.bind(bs.publicInstance));
if (!map[namespace]) {
map[namespace] = {
Expand Down
39 changes: 39 additions & 0 deletions test/specs/files/files.watching.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var merge = require("../../../lib/cli/cli-options").merge;

var events = require("events");
var path = require("path");
var sinon = require("sinon");
var assert = require("chai").assert;

var outpath = path.join(__dirname, "../../fixtures");
Expand Down Expand Up @@ -91,4 +92,42 @@ describe("File Watcher Module", function () {
bs.watchers.core.watchers[0]._events.all("change", tempFile);
});
});
it("should allow obj literal with match & options, but without callback fn", function (done) {

var tempFile = path.join(outpath, "watch-func.txt");

// assert: it works if it calls done
var bs = browserSync.create();

bs.init({
files: [
{
options: {
ignoreInitial: true
},
match: tempFile
}
],
ui: false,
online: false,
logSnippet: false,
logLevel: "silent"
}, function (err, bs) {

var spy = sinon.spy(bs.events, "emit");

bs.watchers.core.watchers[0]._events.all("change", tempFile);

var callArgs = spy.getCall(0).args;

assert.equal(callArgs[0], "file:changed");
assert.equal(callArgs[1].basename, "watch-func.txt");
assert.equal(callArgs[1].event, "change");
assert.equal(callArgs[1].namespace, "core");

bs.cleanup();

done();
});
});
});

0 comments on commit 9f826cb

Please sign in to comment.