diff --git a/lib/browser-sync.js b/lib/browser-sync.js index e20fe6f04..d306537f2 100644 --- a/lib/browser-sync.js +++ b/lib/browser-sync.js @@ -709,7 +709,7 @@ BrowserSync.prototype.cleanup = function (cb) { if (bs.watchers) { Object.keys(bs.watchers).forEach(function (key) { bs.watchers[key].watchers.forEach(function (watcher) { - watcher.close(); + watcher.close(); }); }); } diff --git a/test/specs/e2e/e2e.options.js b/test/specs/e2e/e2e.options.js index 6c7f1b9bf..61c75e882 100644 --- a/test/specs/e2e/e2e.options.js +++ b/test/specs/e2e/e2e.options.js @@ -4,151 +4,85 @@ var browserSync = require("../../../"); var assert = require("chai").assert; var sinon = require("sinon"); -var portScanner = require("portscanner"); describe("e2e options test", function () { - beforeEach(function () { + it("Sets the available port", function (done) { browserSync.reset(); - }); - - describe("E2E options test", function () { - - var instance, port; - - before(function (done) { - - browserSync.reset(); - - portScanner.findAPortNotInUse(3000, 4000, { - host: "localhost", - timeout: 1000 - }, function (err, _port) { - - port = _port; - - var config = { - server: { - baseDir: "test/fixtures" - }, - port: port, - open: false, - logLevel: "silent" - }; - - instance = browserSync(config, done).instance; - - }); - }); - after(function () { - instance.cleanup(); - }); - - it("Sets the available port", function () { - var match = /\d{2,5}/.exec(instance.options.get("port"))[0]; + var config = { + server: { + baseDir: "test/fixtures" + }, + open: false, + logLevel: "silent" + }; + browserSync(config, function (err, bs) { + var match = /\d{2,5}/.exec(bs.options.get("port"))[0]; assert.isNotNull(match); - }); - it("Uses the given port the available port", function () { - var match = /\d{2,5}/.exec(instance.options.get("port"))[0]; - assert.equal(match, port); + bs.cleanup(); + done(); }); }); - describe("E2E options test", function () { - - var instance; - - before(function (done) { - browserSync.reset(); - var config = { - server: { - baseDir: "test/fixtures" - }, - files: ["*.html"], - ports: { - min: 3500 - }, - logLevel: "silent", - open: false - }; - - instance = browserSync(config, done).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the available port", function () { - var match = /\d{2,5}/.exec(instance.options.get("port"))[0]; + it("Sets the available port", function (done) { + browserSync.reset(); + var config = { + server: { + baseDir: "test/fixtures" + }, + files: ["*.html"], + ports: { + min: 3500 + }, + logLevel: "silent", + open: false + }; + browserSync(config, function (err, bs) { + var match = /\d{2,5}/.exec(bs.options.get("port"))[0]; assert.isNotNull(match); - }); - it("Uses the given port the available port", function () { - var match = /\d{2,5}/.exec(instance.options.get("port"))[0]; - assert.equal(match, 3500); - }); - it("set's the files option", function () { - assert.deepEqual(instance.options.get("files").toJS(), { + assert.equal(match, 3500, "Uses the given port the available port"); + assert.deepEqual(bs.options.get("files").toJS(), { core: { globs: ["*.html"], objs: [] } - }); + }, "set's the files option"); + bs.cleanup(); + done(); }); }); - describe("E2E NO OPTIONS test with snippet", function () { - - var instance; - var stub; - - before(function (done) { - stub = sinon.spy(console, "log"); - instance = browserSync([], null, done).instance; - }); - - after(function () { - instance.cleanup(); - console.log.restore(); - }); - - it("Sets the available port", function () { - var match = /\d{2,5}/.exec(instance.options.get("port"))[0]; + it("Sets the available port", function (done) { + browserSync.reset(); + sinon.spy(console, "log"); + browserSync([], null, function (err, bs) { + var match = /\d{2,5}/.exec(bs.options.get("port"))[0]; assert.isNotNull(match); - }); - it("sets the open options to false", function () { - assert.deepEqual(instance.options.get("open"), false); + assert.deepEqual(bs.options.get("open"), false); + console.log.restore(); + bs.cleanup(); + done(); }); }); - describe("E2E NO OPTIONS", function () { - - var instance; - - before(function (done) { - instance = browserSync([], {logLevel: "silent"}, done).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the ghostMode options", function () { + it("Sets the ghostMode options", function (done) { + browserSync.reset(); + browserSync([], {logLevel: "silent"}, function (err, bs) { - var ghostMode = instance.options.get("ghostMode").toJS(); + var ghostMode = bs.options.get("ghostMode").toJS(); assert.deepEqual(ghostMode.clicks, true); assert.deepEqual(ghostMode.scroll, true); assert.deepEqual(ghostMode.forms.submit, true); assert.deepEqual(ghostMode.forms.inputs, true); assert.deepEqual(ghostMode.forms.toggles, true); + bs.cleanup(); + done(); }); }); - describe("E2E GHOST OPTIONS", function () { - - var instance; - + it("Sets the ghostMode options", function (done) { + browserSync.reset(); var config = { ghostMode: { links: true, @@ -156,20 +90,10 @@ describe("e2e options test", function () { submit: false } }, - logLevel: "silent" + logLevel: "silent" }; - - before(function (done) { - instance = browserSync([], config, done).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the ghostMode options", function () { - - var ghostMode = instance.options.get("ghostMode").toJS(); + browserSync([], config, function (err, bs) { + var ghostMode = bs.options.get("ghostMode").toJS(); assert.deepEqual(ghostMode.links, true); assert.deepEqual(ghostMode.clicks, true); @@ -177,213 +101,142 @@ describe("e2e options test", function () { assert.deepEqual(ghostMode.forms.submit, false); assert.deepEqual(ghostMode.forms.inputs, true); assert.deepEqual(ghostMode.forms.toggles, true); + bs.cleanup(); + done(); }); }); - describe("E2E GHOST OPTIONS (NO GHOSTMODE)", function () { - - var instance; - + it("Sets the ghostMode options in shorthand", function (done) { + browserSync.reset(); var config = { ghostMode: false, - logLevel: "silent" + logLevel: "silent" }; - - before(function (done) { - instance = browserSync(config, done).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the ghostMode options in shorthand", function () { - var ghostMode = instance.options.get("ghostMode").toJS(); + browserSync(config, function (err, bs) { + var ghostMode = bs.options.get("ghostMode").toJS(); assert.deepEqual(ghostMode.forms.submit, false); assert.deepEqual(ghostMode.forms.inputs, false); assert.deepEqual(ghostMode.forms.toggles, false); + bs.cleanup(); + done(); }); }); - describe("E2E GHOST OPTIONS (WITH GHOSTMODE)", function () { - - var instance; - + it("Sets the ghostMode options in shorthand", function (done) { + browserSync.reset(); var config = { ghostMode: true, - logLevel: "silent" + logLevel: "silent" }; - - before(function (done) { - instance = browserSync(config, done).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the ghostMode options in shorthand", function () { - var ghostMode = instance.options.get("ghostMode").toJS(); + browserSync(config, function (err, bs) { + var ghostMode = bs.options.get("ghostMode").toJS(); assert.deepEqual(ghostMode.clicks, true); assert.deepEqual(ghostMode.scroll, true); assert.deepEqual(ghostMode.forms.submit, true); assert.deepEqual(ghostMode.forms.inputs, true); assert.deepEqual(ghostMode.forms.toggles, true); + bs.cleanup(); + done(); }); }); - describe("E2E GHOST OPTIONS (NO FORMS)", function () { - - var instance; - + it("Sets the ghostMode options in shorthand", function (done) { + browserSync.reset(); var config = { ghostMode: { forms: false }, - logLevel: "silent" + logLevel: "silent" }; - - before(function (done) { - instance = browserSync(config, done).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the ghostMode options in shorthand", function () { - var ghostMode = instance.options.get("ghostMode").toJS(); + browserSync(config, function (err, bs) { + var ghostMode = bs.options.get("ghostMode").toJS(); assert.deepEqual(ghostMode.forms.submit, false); assert.deepEqual(ghostMode.forms.inputs, false); assert.deepEqual(ghostMode.forms.toggles, false); + bs.cleanup(); + done(); }); }); - describe("E2E GHOST OPTIONS (ALL FORMS)", function () { - - var instance; - + it("Sets the ghostMode options in shorthand", function (done) { + browserSync.reset(); var config = { ghostMode: { forms: true }, - logLevel: "silent" + logLevel: "silent" }; - - before(function (done) { - instance = browserSync(config, done).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the ghostMode options in shorthand", function () { - var ghostMode = instance.options.get("ghostMode").toJS(); + browserSync(config, function (err, bs) { + var ghostMode = bs.options.get("ghostMode").toJS(); assert.deepEqual(ghostMode.forms.submit, true); assert.deepEqual(ghostMode.forms.inputs, true); assert.deepEqual(ghostMode.forms.toggles, true); + bs.cleanup(); + done(); }); }); - describe("E2E HOST OPTIONS + localhost", function () { - - var instance; - + it("Sets the ghostMode options", function (done) { + browserSync.reset(); var config = { - host: "localhost", + host: "localhost", logLevel: "silent" }; - - before(function (done) { - instance = browserSync(config, done).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the ghostMode options", function () { - assert.ok(instance.options.get("port").toString().match(/\d\d\d\d/)); - assert.ok(instance.options.getIn(["urls", "local"]).match(/\d{4,5}$/)); + browserSync(config, function (err, bs) { + assert.ok(bs.options.get("port").toString().match(/\d\d\d\d/)); + assert.ok(bs.options.getIn(["urls", "local"]).match(/\d{4,5}$/)); + bs.cleanup(); + done(); }); }); - describe("E2E OLD API FILES OPTION", function () { - - var instance; - + it("Sets the files option with the old API", function (done) { + browserSync.reset(); var config = { - host: "localhost", - online: false, + host: "localhost", + online: false, logLevel: "silent" }; - before(function (done) { - instance = browserSync.init(["*.html"], config, done).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the files option with the old API", function () { - assert.deepEqual(instance.options.get("files").toJS(), { + browserSync.init(["*.html"], config, function (err, bs) { + assert.deepEqual(bs.options.get("files").toJS(), { core: { globs: ["*.html"], objs: [] } }); - }); + bs.cleanup(); + done() + }) }); - describe("E2E OLD API FILES OPTION", function () { - - var instance; - - before(function (done) { - browserSync.emitter.on("init", function () { - done(); - }); - instance = browserSync.init(["*.html"]).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the files option with the old API", function () { - assert.deepEqual(instance.options.get("files").toJS(), { + it("Sets the files option with the old API", function (done) { + browserSync.reset(); + browserSync.emitter.on("init", function () { + assert.deepEqual(bs.options.get("files").toJS(), { core: { globs: ["*.html"], objs: [] } }); + bs.cleanup(); + done(); }); + var bs = browserSync.init(["*.html"]).instance; }); - describe("E2E OLD API FILES OPTION", function () { - - var instance; - - before(function (done) { - browserSync.emitter.on("init", function () { - done(); - }); - instance = browserSync.init(["*.html"], {}).instance; - }); - - after(function () { - instance.cleanup(); - }); - - it("Sets the files option with the old API", function () { - assert.deepEqual(instance.options.get("files").toJS(), { + it("Sets the files option with the old API", function (done) { + browserSync.reset(); + browserSync.emitter.on("init", function () { + assert.deepEqual(bs.options.get("files").toJS(), { core: { globs: ["*.html"], objs: [] } }); + bs.cleanup(); + done(); }); + var bs = browserSync.init(["*.html"], {}).instance; }); }); diff --git a/test/specs/e2e/e2e.options.logPrefix.js b/test/specs/e2e/e2e.options.logPrefix.js index 29709ec3b..8c8210478 100644 --- a/test/specs/e2e/e2e.options.logPrefix.js +++ b/test/specs/e2e/e2e.options.logPrefix.js @@ -8,68 +8,47 @@ var stripColor = require("chalk").stripColor; var logger = require("../../../lib/logger").logger; describe("E2E `logPrefix` option", function () { - - beforeEach(function () { + it("Can set the log prefix when given in options", function (done) { browserSync.reset(); - }); - - describe("E2E `logPrefix` option", function () { - - var instance; - var spy; - - before(function (done) { - var config = { - open: false, - logPrefix: "BS2", - logLevel: "info", - ui: false - }; - logger.mute(false); - spy = sinon.spy(console, "log"); - instance = browserSync(config, done).instance; - }); - - after(function () { - instance.cleanup(); - console.log.restore(); - }); - - it("Can set the log prefix when given in options", function () { + var config = { + open: false, + logPrefix: "BS2", + logLevel: "info", + ui: false + }; + logger.mute(false); + var spy = sinon.spy(console, "log"); + browserSync(config, function (err, bs) { + console.log(err); var arg = spy.getCall(0).args[0]; assert.include(stripColor(arg), "[BS2]"); assert.notInclude(stripColor(arg), "[BS]"); - }); - }); - describe("E2E `logPrefix` option (function)", function () { - - var instance; - var spy; - - before(function (done) { - var config = { - open: false, - logPrefix: function () { - return this.compile("AWESOME"); - }, - logLevel: "info", - online: false, - ui: false - }; - logger.mute(false); - spy = sinon.spy(console, "log"); - instance = browserSync(config, done).instance; - }); - - after(function () { - instance.cleanup(); console.log.restore(); + bs.cleanup(); + done(); }); + }); - it("Can set the log prefix with a function when given in options", function () { + it("Can set the log prefix with a function when given in options", function (done) { + browserSync.reset(); + var config = { + open: false, + logPrefix: function () { + return this.compile("AWESOME"); + }, + logLevel: "info", + online: false, + ui: false + }; + logger.mute(false); + var spy = sinon.spy(console, "log"); + browserSync(config, function (err, bs) { var arg = spy.getCall(0).args[0]; assert.include(stripColor(arg), "AWESOME"); assert.notInclude(stripColor(arg), "[BS]"); + console.log.restore(); + bs.cleanup(); + done(); }); }); }); diff --git a/test/specs/files/files.watching.js b/test/specs/files/files.watching.js index d530f2d84..61e3e2b1f 100644 --- a/test/specs/files/files.watching.js +++ b/test/specs/files/files.watching.js @@ -10,7 +10,7 @@ var path = require("path"); var sinon = require("sinon"); var assert = require("chai").assert; -var outpath = path.join(__dirname, "../../fixtures"); +var outpath = path.join(__dirname, "../../fixtures"); describe("File Watcher Module", function () { @@ -61,6 +61,8 @@ describe("File Watcher Module", function () { var tempFile = path.join(outpath, "watch-func.txt"); var called = false; + browserSync.reset(); + // assert: it works if it calls done var bs = browserSync.create(); @@ -94,6 +96,8 @@ describe("File Watcher Module", function () { }); it("should allow obj literal with match & options, but without callback fn", function (done) { + browserSync.reset(); + var tempFile = path.join(outpath, "watch-func.txt"); // assert: it works if it calls done