diff --git a/hugo/v2/core/bookshop_component_browser.html b/hugo/v2/core/bookshop_component_browser.html
index 974e5b92..ad9427df 100644
--- a/hugo/v2/core/bookshop_component_browser.html
+++ b/hugo/v2/core/bookshop_component_browser.html
@@ -30,6 +30,6 @@
{{- end -}}
\ No newline at end of file
diff --git a/javascript-modules/browser/lib/app/svelte/browser.svelte b/javascript-modules/browser/lib/app/svelte/browser.svelte
index 280bc6b8..293a62fd 100644
--- a/javascript-modules/browser/lib/app/svelte/browser.svelte
+++ b/javascript-modules/browser/lib/app/svelte/browser.svelte
@@ -1,49 +1,49 @@
-
-
{@html iconSvg("folder_open")} Components
+
@@ -67,7 +82,7 @@
position: absolute;
z-index: 999999999;
background-color: #fff;
- border-right: solid 2px #AAA;
+ border-right: solid 2px #aaa;
width: 300px;
min-width: 300px;
max-height: 100vh;
diff --git a/javascript-modules/engines/hugo-engine/lib/engine.js b/javascript-modules/engines/hugo-engine/lib/engine.js
index af689b5a..c840d11d 100644
--- a/javascript-modules/engines/hugo-engine/lib/engine.js
+++ b/javascript-modules/engines/hugo-engine/lib/engine.js
@@ -31,11 +31,12 @@ export class Engine {
}
async initializeHugo() {
+ const useLocalHugo = window.CloudCannon?.isMocked || /localhost|127\.0\.0\.1/i.test(window.location.host);
// When this script is run locally, the hugo wasm is loaded as binary rather than output as a file.
if (hugoWasm?.constructor === Uint8Array) {
await this.initializeInlineHugo();
} else {
- if (window.CloudCannon?.isMocked) {
+ if (useLocalHugo) {
await this.initializeLocalHugo();
} else {
await this.initializeRemoteHugo();
@@ -73,7 +74,7 @@ export class Engine {
async initializeLocalHugo() {
const go = new Go();
- const wasmOrigin = this.origin.replace(/\/[^\.\/]+\.js$/, hugoWasm.replace(/^\./, ''));
+ const wasmOrigin = this.origin.replace(/\/[^\.\/]+\.js/, hugoWasm.replace(/^\./, ''));
const response = await fetch(wasmOrigin);
const buffer = await response.arrayBuffer();
const result = await WebAssembly.instantiate(buffer, go.importObject);
@@ -121,6 +122,7 @@ export class Engine {
async render(target, name, props, globals, cloudcannonInfo, meta) {
while (!window.renderHugo) await sleep(10);
+ await sleep(2000);
window.loadHugoBookshopData(JSON.stringify(cloudcannonInfo));
let source = this.getComponent(name);
diff --git a/javascript-modules/integration-tests/features/hugo/component_browser/hugo_bookshop_browser_granules.feature b/javascript-modules/integration-tests/features/hugo/component_browser/hugo_bookshop_browser_granules.feature
index d93baa6d..696d197f 100644
--- a/javascript-modules/integration-tests/features/hugo/component_browser/hugo_bookshop_browser_granules.feature
+++ b/javascript-modules/integration-tests/features/hugo/component_browser/hugo_bookshop_browser_granules.feature
@@ -71,10 +71,10 @@ Feature: Hugo Bookshop Component Browser Granular Steps
@web
Scenario: Bookshop component browser renders a component
When 🌐 I load my site
+ And 🌐 "typeof window.BookshopBrowser !== 'undefined'" evaluates
And 🌐 "window.bookshopBrowser?.hasRendered === true" evaluates
- And 🌐 "window.bookshopBrowser.hasRendered = true" evaluates
And 🌐 I trigger a mousedown on li:nth-of-type(2)>button
- And 🌐 "window.bookshopBrowser.hasRendered === true" evaluates
+ And 🌐 "window.bookshopComponentHasRendered === true" evaluates
Then 🌐 There should be no errors
* 🌐 There should be no logs
* 🌐 The selector h1 should contain "Hello There, World"
diff --git a/javascript-modules/integration-tests/support/steps.js b/javascript-modules/integration-tests/support/steps.js
index 0c52cbd7..cc9f2b02 100644
--- a/javascript-modules/integration-tests/support/steps.js
+++ b/javascript-modules/integration-tests/support/steps.js
@@ -212,6 +212,10 @@ const p_retry = async (fn, wait, attempts) => {
const loadPage = async (url, world) => {
await ensurePage(world);
+ world.page
+ .on('console', message => world.trackPuppeteerLog(`${message.type().toUpperCase()}: ${message.text()}`))
+ .on('pageerror', ({ message }) => world.trackPuppeteerError(message))
+ .on('requestfailed', request => world.trackPuppeteerError(`${request.failure().errorText} ${request.url()}`));
await p_retry(
() => world.page.goto(world.replacePort(url), {
waitUntil: 'networkidle0',
@@ -219,10 +223,6 @@ const loadPage = async (url, world) => {
500, // ms between attempts
20 // attempts
);
- world.page
- .on('console', message => world.trackPuppeteerLog(`${message.type().toUpperCase()}: ${message.text()}`))
- .on('pageerror', ({ message }) => world.trackPuppeteerError(message))
- .on('requestfailed', request => world.trackPuppeteerError(`${request.failure().errorText} ${request.url()}`));
}
const readyCloudCannon = async (data, world) => {
@@ -240,6 +240,14 @@ const readyCloudCannon = async (data, world) => {
await p_sleep(50);
}
+// This flag is used in some tests to determine whether to load a remote file
+const readyEmptyCloudCannon = async (world) => {
+ if (!world.page) throw Error("No page open");
+ const script = `window.CloudCannon = { isMocked : true };`;
+ await world.page.addScriptTag({ content: script });
+ await p_sleep(50);
+}
+
/* * * * * * * * * *
* *
* PUPPETEER STEPS *
@@ -282,7 +290,8 @@ When(/^🌐 "(.+)" evaluates$/i, { timeout: 5 * 1000 }, async function (statemen
try {
await this.page.waitForFunction(statement, { timeout: 4 * 1000 });
} catch (e) {
- this.trackPuppeteerError(`${statement} didn't evaluate within 4s`);
+ this.trackPuppeteerError(`${statement} failed:\n${e.toString()}`);
+ assert.deepEqual(this.puppeteerErrors(), []);
}
});
@@ -341,7 +350,8 @@ Then(/^🌐 "(.+)" should evaluate$/i, { timeout: 5 * 1000 }, async function (st
try {
await this.page.waitForFunction(statement, { timeout: 4 * 1000 });
} catch (e) {
- throw Error(`${statement} didn't evaluate within 4s`)
+ this.trackPuppeteerError(`${statement} failed:\n${e.toString()}`);
+ assert.deepEqual(this.puppeteerErrors(), []);
}
});
@@ -417,6 +427,8 @@ Given(/^🌐 I (?:have loaded|load) my site( in CloudCannon)?$/i, { timeout: 60
this.trackPuppeteerError(e.toString());
this.trackPuppeteerError(`Bookshop didn't do an initial render within 4s`);
}
+ } else {
+ await readyEmptyCloudCannon(this);
}
assert.deepEqual(this.puppeteerErrors(), []);