diff --git a/app/react/src/server/iframe.html.js b/app/react/src/server/iframe.html.js
index 95193273617c..2aeb77f6e92c 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(assetUrl => re.exec(assetUrl)[1] !== 'map').forEach(assetUrl => {
+ urls[re.exec(assetUrl)[1]].push(assetUrl);
+ });
});
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'],
+ });
+ });
+});