( code: string, filePath: string, width?: number, )
| 89 | } |
| 90 | |
| 91 | async function mountHighlightedCode( |
| 92 | code: string, |
| 93 | filePath: string, |
| 94 | width?: number, |
| 95 | ): Promise<MountedHighlightedCode> { |
| 96 | installReplPerfEnvironment() |
| 97 | |
| 98 | const { App } = await import('../components/App.js') |
| 99 | const { HighlightedCode } = await import('../components/HighlightedCode.js') |
| 100 | |
| 101 | const terminal = createFakeTerminal(140, 32) |
| 102 | const frames: FrameEvent[] = [] |
| 103 | const root = await createRoot({ |
| 104 | stdout: terminal.stdout, |
| 105 | stdin: terminal.stdin, |
| 106 | stderr: terminal.stderr, |
| 107 | exitOnCtrlC: false, |
| 108 | patchConsole: false, |
| 109 | onFrame: event => { |
| 110 | frames.push(event) |
| 111 | }, |
| 112 | }) |
| 113 | |
| 114 | root.render( |
| 115 | <App getFpsMetrics={() => undefined} initialState={getDefaultAppState()}> |
| 116 | <Box width={width + 2} flexDirection="column"> |
| 117 | {width === undefined ? <HighlightedCode code={code} filePath={filePath} /> : <HighlightedCode code={code} filePath={filePath} width={width} />} |
| 118 | </Box> |
| 119 | </App>, |
| 120 | ) |
| 121 | |
| 122 | await waitFor( |
| 123 | () => frames.length > 0, |
| 124 | 'HighlightedCode never rendered a frame', |
| 125 | ) |
| 126 | await waitFor(() => { |
| 127 | const ink = getMountedInkProbe(terminal) |
| 128 | return ink |
| 129 | ? readScreenText(ink.frontFrame.screen).includes('export const value_') |
| 130 | : false |
| 131 | }, 'HighlightedCode never painted the rendered file preview') |
| 132 | await Bun.sleep(120) |
| 133 | |
| 134 | return { root, terminal, frames } |
| 135 | } |
| 136 | |
| 137 | async function withPerfEnv<T>(fn: () => Promise<T>): Promise<T> { |
| 138 | const prevNoFlicker = process.env.CLAUDE_CODE_NO_FLICKER |
no test coverage detected