From 7d11de281ec63ef43e22448c6bc983c6d5b64b36 Mon Sep 17 00:00:00 2001 From: Nick Wesselman <27013789+nickwesselman@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:51:39 -0400 Subject: [PATCH] test fixes --- src/components/App.tsx | 9 +++++++-- src/ink.tsx | 1 + test/errors.tsx | 7 +++++-- test/helpers/create-stdout.ts | 1 + 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/components/App.tsx b/src/components/App.tsx index 7ad36a6a6..bc7c52cd8 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -22,6 +22,7 @@ type Props = { readonly writeToStderr: (data: string) => void; readonly exitOnCtrlC: boolean; readonly onExit: (error?: Error) => void; + readonly debug: boolean; }; type State = { @@ -127,11 +128,15 @@ export default class App extends PureComponent { } override componentDidMount() { - cliCursor.hide(this.props.stdout); + if (!this.props.debug) { + cliCursor.hide(this.props.stdout); + } } override componentWillUnmount() { - cliCursor.show(this.props.stdout); + if (!this.props.debug) { + cliCursor.show(this.props.stdout); + } // ignore calling setRawMode on an handle stdin it cannot be called if (this.isRawModeSupported()) { diff --git a/src/ink.tsx b/src/ink.tsx index 5d79b69fe..eacfc640c 100644 --- a/src/ink.tsx +++ b/src/ink.tsx @@ -209,6 +209,7 @@ export default class Ink { writeToStdout={this.writeToStdout} writeToStderr={this.writeToStderr} exitOnCtrlC={this.options.exitOnCtrlC} + debug={this.options.debug} onExit={this.unmount} > {node} diff --git a/test/errors.tsx b/test/errors.tsx index 6da4a9f48..31c11647a 100644 --- a/test/errors.tsx +++ b/test/errors.tsx @@ -22,7 +22,10 @@ test('catch and display error', t => { throw new Error('Oh no'); }; - render(, {stdout}); + render(, { + stdout, + debug: true, + }); t.deepEqual( stripAnsi((stdout.write as any).lastCall.args[0] as string) @@ -40,7 +43,7 @@ test('catch and display error', t => { " 22: throw new Error('Oh no');", ' 23: };', ' 24:', - ' 25: render(, {stdout});', + ' 25: render(, {', '', ' - Test (test/errors.tsx:22:9)', ], diff --git a/test/helpers/create-stdout.ts b/test/helpers/create-stdout.ts index d9d8655c6..0028c1116 100644 --- a/test/helpers/create-stdout.ts +++ b/test/helpers/create-stdout.ts @@ -12,6 +12,7 @@ const createStdout = (columns?: number): FakeStdout => { const write = spy(); stdout.write = write; + stdout.isTTY = true; stdout.get = () => write.lastCall.args[0] as string;