Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion apps/fs-experiment/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const SANDBOXED_SUBSTITUTIONS: Record<string, string> = {
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',
Expand Down Expand Up @@ -114,6 +115,7 @@ function App(): React.JSX.Element {
</View>

<SandboxReactNativeView
testID={sandboxReady ? 'sandbox-ready' : undefined}
style={styles.sandboxView}
origin="sandbox.fs-experiment.demo"
componentName="SandboxApp"
Expand All @@ -122,7 +124,12 @@ function App(): React.JSX.Element {
turboModuleSubstitutions={
useSubstitution ? SANDBOXED_SUBSTITUTIONS : undefined
}
onMessage={msg => 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)
}
Expand Down
9 changes: 7 additions & 2 deletions apps/fs-experiment/__tests__/sandbox-isolation.harness.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -85,8 +86,12 @@ describe('Substitution OFF', () => {
beforeAll(async () => {
blockCleanup = true
await render(<App />, {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(
Expand Down
3 changes: 3 additions & 0 deletions apps/fs-experiment/sandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ function installTestCommandHandler() {
function SandboxApp(props) {
useEffect(() => {
installTestCommandHandler()
if (typeof globalThis.postMessage === 'function') {
globalThis.postMessage({cmd: 'ready'})
}
}, [])

return <FileOpsUI testIDPrefix="sandbox" {...props} />
Expand Down
Loading