diff --git a/packages/browser-repl/src/components/shell.spec.tsx b/packages/browser-repl/src/components/shell.spec.tsx index 2ef255001..a2cd7fd67 100644 --- a/packages/browser-repl/src/components/shell.spec.tsx +++ b/packages/browser-repl/src/components/shell.spec.tsx @@ -526,7 +526,7 @@ describe('shell', function () { return {}; }; - const initialEvaluate = 'my command'; + const initialEvaluate = ['command 1', 'command 2']; const onOutputChanged = sinon.spy(); render( { - expect(onOutputChanged).to.have.been.called; + expect(screen.getByText('rs0:primary')).to.exist; }); - - expect(screen.getByText('rs0:primary')).to.exist; }); }); }); diff --git a/packages/browser-repl/src/components/shell.tsx b/packages/browser-repl/src/components/shell.tsx index a47c86287..2b25adada 100644 --- a/packages/browser-repl/src/components/shell.tsx +++ b/packages/browser-repl/src/components/shell.tsx @@ -159,7 +159,11 @@ interface ShellProps { onEditorChanged?: (editor: EditorRef | null) => void; } -const normalizeInitialEvaluate = (initialEvaluate: string | string[]) => { +const normalizeInitialEvaluate = (initialEvaluate?: string | string[]) => { + if (!initialEvaluate) { + return []; + } + return ( Array.isArray(initialEvaluate) ? initialEvaluate : [initialEvaluate] ).filter((line) => { @@ -455,18 +459,22 @@ const _Shell: ForwardRefRenderFunction = ( setIsFirstRun(false); - void updateShellPrompt().then(async () => { - if (initialEvaluate) { - const evalLines = normalizeInitialEvaluate(initialEvaluate); + const evalLines = normalizeInitialEvaluate(initialEvaluate); + if (evalLines.length) { + void (async () => { for (const input of evalLines) { await onInput(input); } - } - }); + })(); + } else { + void updateShellPrompt(); + } }, [initialEvaluate, isFirstRun, onInput, updateShellPrompt]); useEffect(() => { rafraf(() => { + // Scroll to the bottom every time we render so the input/output will be + // in view. scrollToBottom(); }); });