From 33472f9af2d0de39bb8c66ec4b5e318f40d6208e Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Tue, 27 Jun 2017 02:43:17 +0200 Subject: [PATCH 1/3] fix: allow multiple assets with different types --- app/react/src/server/iframe.html.js | 14 +++++++------- app/react/src/server/iframe.html.test.js | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 app/react/src/server/iframe.html.test.js diff --git a/app/react/src/server/iframe.html.js b/app/react/src/server/iframe.html.js index 95193273617c..0a8b1065fae1 100644 --- a/app/react/src/server/iframe.html.js +++ b/app/react/src/server/iframe.html.js @@ -8,7 +8,7 @@ import url from 'url'; // 'preview.0d2d3d845f78399fd6d5e859daa152a9.css', // 'static/preview.9adbb5ef965106be1cc3.bundle.js.map', // 'preview.0d2d3d845f78399fd6d5e859daa152a9.css.map' ] -const urlsFromAssets = assets => { +export const urlsFromAssets = assets => { if (!assets) { return { js: ['static/preview.bundle.js'], @@ -26,13 +26,13 @@ const urlsFromAssets = assets => { // Don't load the manager script in the iframe .filter(key => key !== 'manager') .forEach(key => { - const asset = assets[key]; - if (typeof asset === 'string') { - urls[re.exec(asset)[1]].push(asset); - } else { - const assetUrl = asset.find(u => re.exec(u)[1] !== 'map'); - urls[re.exec(assetUrl)[1]].push(assetUrl); + let assetList = assets[key]; + if (!Array.isArray(assetList)) { + assetList = [assetList]; } + assetList.filter(u => re.exec(u)[1] !== 'map').forEach(u => { + urls[re.exec(u)[1]].push(u); + }); }); return urls; diff --git a/app/react/src/server/iframe.html.test.js b/app/react/src/server/iframe.html.test.js new file mode 100644 index 000000000000..34cfc2e67669 --- /dev/null +++ b/app/react/src/server/iframe.html.test.js @@ -0,0 +1,21 @@ +import { urlsFromAssets } from './iframe.html'; + +describe('server.urlsFromAssets', () => { + it('should return the default when there are no assets', () => { + expect(urlsFromAssets()).toEqual({ + js: ['static/preview.bundle.js'], + css: [], + }); + }); + + it('should return multiple assets', () => { + const fixture = { + manager: 'static/manager.a.bundle.js', + preview: ['static/preview.x.bundle.js', 'static/preview.y.css', 'static/preview.y.css.map'], + }; + expect(urlsFromAssets(fixture)).toEqual({ + js: ['static/preview.x.bundle.js'], + css: ['static/preview.y.css'], + }); + }); +}); From a9d88cf2f3d2d20683de6f31707e3d2cd4a93e07 Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Wed, 28 Jun 2017 13:05:37 +0200 Subject: [PATCH 2/3] u -> url --- app/react/src/server/iframe.html.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/react/src/server/iframe.html.js b/app/react/src/server/iframe.html.js index 0a8b1065fae1..0cd826603568 100644 --- a/app/react/src/server/iframe.html.js +++ b/app/react/src/server/iframe.html.js @@ -30,8 +30,8 @@ export const urlsFromAssets = assets => { if (!Array.isArray(assetList)) { assetList = [assetList]; } - assetList.filter(u => re.exec(u)[1] !== 'map').forEach(u => { - urls[re.exec(u)[1]].push(u); + assetList.filter(url => re.exec(url)[1] !== 'map').forEach(url => { + urls[re.exec(url)[1]].push(url); }); }); From be7625a7d5fe6bcda37911f42df46ad187aa49c4 Mon Sep 17 00:00:00 2001 From: Joscha Feth Date: Wed, 28 Jun 2017 13:37:26 +0200 Subject: [PATCH 3/3] url -> assetUrl --- app/react/src/server/iframe.html.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/react/src/server/iframe.html.js b/app/react/src/server/iframe.html.js index 0cd826603568..2aeb77f6e92c 100644 --- a/app/react/src/server/iframe.html.js +++ b/app/react/src/server/iframe.html.js @@ -30,8 +30,8 @@ export const urlsFromAssets = assets => { if (!Array.isArray(assetList)) { assetList = [assetList]; } - assetList.filter(url => re.exec(url)[1] !== 'map').forEach(url => { - urls[re.exec(url)[1]].push(url); + assetList.filter(assetUrl => re.exec(assetUrl)[1] !== 'map').forEach(assetUrl => { + urls[re.exec(assetUrl)[1]].push(assetUrl); }); });