diff --git a/apps/fs-experiment/App.tsx b/apps/fs-experiment/App.tsx index 50c6ae2..c28ef7e 100644 --- a/apps/fs-experiment/App.tsx +++ b/apps/fs-experiment/App.tsx @@ -40,6 +40,7 @@ const SANDBOXED_SUBSTITUTIONS: Record = { function App(): React.JSX.Element { const isDarkMode = useColorScheme() === 'dark' const [useSubstitution, setUseSubstitution] = useState(false) + const [sandboxReady, setSandboxReady] = useState(false) const theme = { bg: isDarkMode ? '#000' : '#fff', @@ -114,6 +115,7 @@ function App(): React.JSX.Element { console.log('Host received from sandbox:', msg)} + onMessage={msg => { + const payload = + typeof msg.data === 'string' ? JSON.parse(msg.data) : msg.data + if (payload?.cmd === 'ready') setSandboxReady(true) + console.log('Host received from sandbox:', msg) + }} onError={err => console.log('Host received error from sandbox:', err) } diff --git a/apps/fs-experiment/__tests__/sandbox-isolation.harness.tsx b/apps/fs-experiment/__tests__/sandbox-isolation.harness.tsx index b39c19d..3812644 100644 --- a/apps/fs-experiment/__tests__/sandbox-isolation.harness.tsx +++ b/apps/fs-experiment/__tests__/sandbox-isolation.harness.tsx @@ -15,6 +15,7 @@ import App from '../App' const isIOS = Platform.OS === 'ios' const TEST_TIMEOUT = 60_000 const RENDER_TIMEOUT = 10_000 +const SANDBOX_READY_TIMEOUT = 90_000 async function sleep(ms: number) { return new Promise(r => setTimeout(r, ms)) @@ -85,8 +86,12 @@ describe('Substitution OFF', () => { beforeAll(async () => { blockCleanup = true await render(, {timeout: RENDER_TIMEOUT}) - await sleep(4000) - }, 30_000) + await screen.findByTestId( + 'sandbox-ready', + {}, + {timeout: SANDBOX_READY_TIMEOUT} + ) + }, SANDBOX_READY_TIMEOUT + RENDER_TIMEOUT) if (isIOS) { it( diff --git a/apps/fs-experiment/sandbox.js b/apps/fs-experiment/sandbox.js index e0bc3a3..b116f39 100644 --- a/apps/fs-experiment/sandbox.js +++ b/apps/fs-experiment/sandbox.js @@ -58,6 +58,9 @@ function installTestCommandHandler() { function SandboxApp(props) { useEffect(() => { installTestCommandHandler() + if (typeof globalThis.postMessage === 'function') { + globalThis.postMessage({cmd: 'ready'}) + } }, []) return