diff --git a/modules/index.js b/modules/index.js index 40d39cf..b830126 100644 --- a/modules/index.js +++ b/modules/index.js @@ -40,6 +40,7 @@ const PLUGINS = { // Martech martech: { url: `${pluginBasePath}/martech.js`, when: ({ urlParameters }) => urlParameters.size > 0 }, onetrust: { url: `${pluginBasePath}/onetrust.js`, when: () => (document.querySelector('#onetrust-consent-sdk') || hasCookieKey('OptanonAlertBoxClosed')), isBlockDependent: true }, + // test: broken-plugin }; const PLUGIN_PARAMETERS = { @@ -59,16 +60,12 @@ function loadPlugin(key, params) { return null; } if (!pluginCache.has(key)) { - try { - pluginCache.set(key, import(`${plugin.url || plugin}`)); - /* c8 ignore next 3 */ - } catch (e) { - return null; - } + pluginCache.set(key, import(`${plugin.url || plugin}`)); } const pluginLoadPromise = pluginCache.get(key); return pluginLoadPromise - .then((p) => (p.default && p.default(params)) || (typeof p === 'function' && p(params))); + .then((p) => (p.default && p.default(params)) || (typeof p === 'function' && p(params))) + .catch(() => { /* silent plugin error catching */ }); } function loadPlugins(filter = () => true, params = PLUGIN_PARAMETERS) { diff --git a/test/it/broken-plugin.test.html b/test/it/broken-plugin.test.html new file mode 100644 index 0000000..d70bde3 --- /dev/null +++ b/test/it/broken-plugin.test.html @@ -0,0 +1,62 @@ + + + + Test Runner + + + +

Some content

+ + + + \ No newline at end of file diff --git a/web-test-runner.config.js b/web-test-runner.config.js index 74f5b7e..9352fed 100644 --- a/web-test-runner.config.js +++ b/web-test-runner.config.js @@ -46,6 +46,15 @@ export default { // rewriting dynamic plugins base url .replace(/document\.currentScript\.src/g, '"http://localhost:8000/plugins"'); return true; + } else if (context.url.startsWith('/modules/index-broken.js')) { + const [_, search] = context.url.split('?'); + context.url = `/modules/index.js?${search}`; + await next(); + context.body = context.body + // rewriting dynamic plugins base url + .replace(/document\.currentScript\.src/g, '"http://localhost:8000/plugins"') + .replace(/\/\/ test: broken-plugin/g, 'foo: "foo.js",'); + return true; } else if (context.url.startsWith('/.rum')) { if (context.url.startsWith('/.rum/@adobe/helix-rum-js@%5E2/dist/') || context.url.startsWith('/.rum/@adobe/helix-rum-js@^2/dist/')