From f9c79e88d1a07addc24ccca611781bf7a3bfaebc Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Thu, 1 Sep 2022 16:35:53 +0200 Subject: [PATCH 1/4] Add args to console logging in integration tests --- test/playwright/test.ts | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/test/playwright/test.ts b/test/playwright/test.ts index b3ea49ca31e..bf2724002ca 100644 --- a/test/playwright/test.ts +++ b/test/playwright/test.ts @@ -18,14 +18,21 @@ const IGNORED_ERRORS = [ export const test = base.extend({ page: async ({ page }, use) => { - const entries: ConsoleEntry[] = []; + const entriePromises: Promise[] = []; const consoleHandler = (msg: ConsoleMessage) => { - entries.push({ - type: msg.type(), - text: msg.text(), - location: msg.location(), - }); + entriePromises.push( + Promise.all( + msg.args().map(async (argHandle) => argHandle.jsonValue().catch(() => '')), + ).then((args) => { + return { + type: msg.type(), + text: msg.text(), + location: msg.location(), + args, + }; + }), + ); }; page.on('console', consoleHandler); @@ -34,6 +41,7 @@ export const test = base.extend({ page.off('console', consoleHandler); + const entries = await Promise.all(entriePromises); for (const entry of entries) { if (entry.type === 'error' && !IGNORED_ERRORS.some((regex) => regex.test(entry.text))) { // Currently a catch-all for console error messages. Expecting us to add a way of blacklisting From 17d8a1268e189c998992947861f093f1ef48fd57 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Thu, 1 Sep 2022 16:37:18 +0200 Subject: [PATCH 2/4] more info --- test/playwright/test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/playwright/test.ts b/test/playwright/test.ts index bf2724002ca..c4451c5e70a 100644 --- a/test/playwright/test.ts +++ b/test/playwright/test.ts @@ -10,6 +10,7 @@ interface ConsoleEntry { lineNumber: number; columnNumber: number; }; + args: any[]; } const IGNORED_ERRORS = [ @@ -46,7 +47,7 @@ export const test = base.extend({ if (entry.type === 'error' && !IGNORED_ERRORS.some((regex) => regex.test(entry.text))) { // Currently a catch-all for console error messages. Expecting us to add a way of blacklisting // expected error messages at some point here - throw new Error(`Console error message detected\n${entry.text}`); + throw new Error(`Console error message detected\n${JSON.stringify(entry, null, 2)}`); } } }, From 997802a76490de378de14add66b542d036beab50 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Thu, 1 Sep 2022 17:00:12 +0200 Subject: [PATCH 3/4] wait for bridge to set up event handler --- .../src/toolpad/AppEditor/PageEditor/EditorCanvasHost.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/EditorCanvasHost.tsx b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/EditorCanvasHost.tsx index 3aa56c6b7d0..f713360c2a6 100644 --- a/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/EditorCanvasHost.tsx +++ b/packages/toolpad-app/src/toolpad/AppEditor/PageEditor/EditorCanvasHost.tsx @@ -160,8 +160,7 @@ export default React.forwardRef( () => { return { getViewCoordinates(clientX, clientY) { - invariant(bridge, 'bridge not initialized'); - return bridge.getViewCoordinates(clientX, clientY); + return bridge?.getViewCoordinates(clientX, clientY) || null; }, getPageViewState() { invariant(bridge, 'bridge not initialized'); @@ -199,12 +198,12 @@ export default React.forwardRef( }, [contentWindow]); React.useEffect(() => { - if (!contentWindow) { + if (!contentWindow || !bridge) { return undefined; } return setEventHandler(contentWindow, handleRuntimeEvent); - }, [handleRuntimeEvent, contentWindow]); + }, [handleRuntimeEvent, contentWindow, bridge]); return ( From 5d3cc8a48a5f6d2a339782c900bf7a17d7b0c8c1 Mon Sep 17 00:00:00 2001 From: Jan Potoms <2109932+Janpot@users.noreply.github.com> Date: Thu, 1 Sep 2022 17:07:22 +0200 Subject: [PATCH 4/4] typo --- test/playwright/test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/playwright/test.ts b/test/playwright/test.ts index c4451c5e70a..49197906e4e 100644 --- a/test/playwright/test.ts +++ b/test/playwright/test.ts @@ -19,10 +19,10 @@ const IGNORED_ERRORS = [ export const test = base.extend({ page: async ({ page }, use) => { - const entriePromises: Promise[] = []; + const entryPromises: Promise[] = []; const consoleHandler = (msg: ConsoleMessage) => { - entriePromises.push( + entryPromises.push( Promise.all( msg.args().map(async (argHandle) => argHandle.jsonValue().catch(() => '')), ).then((args) => { @@ -42,7 +42,7 @@ export const test = base.extend({ page.off('console', consoleHandler); - const entries = await Promise.all(entriePromises); + const entries = await Promise.all(entryPromises); for (const entry of entries) { if (entry.type === 'error' && !IGNORED_ERRORS.some((regex) => regex.test(entry.text))) { // Currently a catch-all for console error messages. Expecting us to add a way of blacklisting