From aabc03c8b77f6512769b4deb2c8c7665fe4a1128 Mon Sep 17 00:00:00 2001 From: Shane Osbourne Date: Thu, 28 May 2015 11:15:15 +0100 Subject: [PATCH] fix(plugins): allow module references in options.plugins array - fixes #648 --- lib/async.js | 6 ++- test/specs/plugins/user.plugins.inline.obj.js | 1 - .../user.plugins.inline.obj.reference.js | 50 +++++++++++++++++++ 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 test/specs/plugins/user.plugins.inline.obj.reference.js diff --git a/lib/async.js b/lib/async.js index c70cc31bc..df6d8eca6 100644 --- a/lib/async.js +++ b/lib/async.js @@ -69,7 +69,11 @@ module.exports = { } if (Immutable.Map.isMap(item)) { - loadPlugin(item.get("module"), item.get("options")); + if (item.has("module")) { + loadPlugin(item.get("module"), item.get("options")); + } else { + loadPlugin(item); + } } }); diff --git a/test/specs/plugins/user.plugins.inline.obj.js b/test/specs/plugins/user.plugins.inline.obj.js index 4dd41541f..09f18661f 100644 --- a/test/specs/plugins/user.plugins.inline.obj.js +++ b/test/specs/plugins/user.plugins.inline.obj.js @@ -36,7 +36,6 @@ describe("Plugins: Retrieving user plugins when given inline as object", functio instance.cleanup(); }); it("Should access to only the user-specified plugins", function (done) { - console.log(instance.getUserPlugins()); assert.equal(instance.getUserPlugins().length, 1); done(); }); diff --git a/test/specs/plugins/user.plugins.inline.obj.reference.js b/test/specs/plugins/user.plugins.inline.obj.reference.js new file mode 100644 index 000000000..71c6078ad --- /dev/null +++ b/test/specs/plugins/user.plugins.inline.obj.reference.js @@ -0,0 +1,50 @@ +"use strict"; + +var assert = require("chai").assert; +var sinon = require("sinon"); + +describe("Plugins: Retrieving user plugins when given inline as object reference", function () { + + var instance; + var PLUGIN_NAME_1 = "Test Plugin 1"; + var PLUGIN_NAME_2 = "Test Plugin 2"; + var spy1, spy2; + + before(function (done) { + + var browserSync = require("../../../"); + spy1 = sinon.spy(); + spy2 = sinon.spy(); + browserSync.reset(); + + var bs = browserSync.create(); + + var fake1 = { + plugin: spy1, + "plugin:name": PLUGIN_NAME_1 + }; + var fake2 = { + plugin: spy1, + "plugin:name": PLUGIN_NAME_2 + }; + + var config = { + logLevel: "silent", + plugins: [fake1, fake2] + }; + + instance = bs.init(config, done); + }); + after(function () { + instance.cleanup(); + }); + it("Should access to only the user-specified plugins", function (done) { + assert.equal(instance.getUserPlugins().length, 2); + done(); + }); + it("Should have access to only the user-specified plugins", function (done) { + assert.equal(instance.getUserPlugins()[0].name, PLUGIN_NAME_1); + assert.equal(instance.getUserPlugins()[1].name, PLUGIN_NAME_2); + done(); + }); +});