From 4e65eb612086320971a64ce5be0581e74bbe6661 Mon Sep 17 00:00:00 2001 From: Jeff Posnick Date: Mon, 8 Apr 2019 12:31:52 -0400 Subject: [PATCH] Fixes opts passed to the BCU Plugin. --- .../src/lib/runtime-caching-converter.js | 7 ++----- .../node/lib/runtime-caching-converter.js | 15 +++++++-------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/packages/workbox-build/src/lib/runtime-caching-converter.js b/packages/workbox-build/src/lib/runtime-caching-converter.js index fe4203c3b..6a4b5d66d 100644 --- a/packages/workbox-build/src/lib/runtime-caching-converter.js +++ b/packages/workbox-build/src/lib/runtime-caching-converter.js @@ -81,11 +81,8 @@ function getOptionsString(options = {}) { case 'broadcastUpdate': { const channelName = pluginConfig.channelName; - pluginCode = `new ${pluginString}(${JSON.stringify(channelName)}`; - if ('options' in pluginConfig) { - pluginCode += `, ${stringifyWithoutComments(pluginConfig.options)}`; - } - pluginCode += `)`; + const opts = Object.assign({channelName}, pluginConfig.options); + pluginCode = `new ${pluginString}(${stringifyWithoutComments(opts)})`; break; } diff --git a/test/workbox-build/node/lib/runtime-caching-converter.js b/test/workbox-build/node/lib/runtime-caching-converter.js index 7e0a5b01a..8dd6fc619 100644 --- a/test/workbox-build/node/lib/runtime-caching-converter.js +++ b/test/workbox-build/node/lib/runtime-caching-converter.js @@ -115,15 +115,14 @@ function validate(runtimeCachingOptions, convertedOptions) { if (options.broadcastUpdate) { if ('options' in options.broadcastUpdate) { - expect( - globalScope.workbox.broadcastUpdate.Plugin.calledWith( - options.broadcastUpdate.channelName, options.broadcastUpdate.options) - ).to.be.true; + const expectedOptions = Object.assign( + {channelName: options.broadcastUpdate.channelName}, + options.broadcastUpdate.options); + expect(globalScope.workbox.broadcastUpdate.Plugin.calledWith(expectedOptions)) + .to.be.true; } else { - expect( - globalScope.workbox.broadcastUpdate.Plugin.calledWith( - options.broadcastUpdate.channelName) - ).to.be.true; + expect(globalScope.workbox.broadcastUpdate.Plugin.calledWith( + {channelName: options.broadcastUpdate.channelName})).to.be.true; } } }