MCPcopy Create free account
hub / github.com/Noumena-Network/code / mountMountedComponent

Function mountMountedComponent

src/testing/mountedComponentHarness.tsx:27–84  ·  view source on GitHub ↗
(
  node: React.ReactNode,
  options?: {
    readonly columns?: number
    readonly rows?: number
    readonly settleMs?: number
    readonly wrapInApp?: boolean
    readonly initialState?: AppState
  },
)

Source from the content-addressed store, hash-verified

25}
26
27export async function mountMountedComponent(
28 node: React.ReactNode,
29 options?: {
30 readonly columns?: number
31 readonly rows?: number
32 readonly settleMs?: number
33 readonly wrapInApp?: boolean
34 readonly initialState?: AppState
35 },
36): Promise<MountedComponentHarnessResult> {
37 installReplPerfEnvironment()
38
39 const terminal = createFakeTerminal(
40 options?.columns ?? 80,
41 options?.rows ?? 24,
42 )
43 let frames = 0
44
45 mountedRoot = await createRoot({
46 stdout: terminal.stdout,
47 stdin: terminal.stdin,
48 stderr: terminal.stderr,
49 exitOnCtrlC: false,
50 patchConsole: false,
51 onFrame: () => {
52 frames += 1
53 },
54 })
55
56 const wrappedNode =
57 options?.wrapInApp === false ? (
58 node
59 ) : (
60 <App
61 getFpsMetrics={() => undefined}
62 initialState={options?.initialState ?? getDefaultAppState()}
63 >
64 {node}
65 </App>
66 )
67
68 mountedRoot.render(wrappedNode)
69 await waitFor(
70 () => frames > 0,
71 'mounted component harness never rendered a frame',
72 )
73 await Bun.sleep(options?.settleMs ?? 120)
74
75 const ink = getMountedInkProbe(terminal)
76 if (!ink) {
77 throw new Error('mounted component harness never exposed an ink probe')
78 }
79
80 return {
81 root: mountedRoot,
82 ink,
83 }
84}

Calls 8

getDefaultAppStateFunction · 0.85
getMountedInkProbeFunction · 0.85
sleepMethod · 0.80
createFakeTerminalFunction · 0.50
createRootFunction · 0.50
waitForFunction · 0.50
renderMethod · 0.45

Tested by

no test coverage detected