From b04ddc30247ab097c59cb05921568bb59cf7e69b Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 15 Nov 2019 12:01:21 +0100 Subject: [PATCH] chore: use 2 effects instead --- src/Reporter.tsx | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Reporter.tsx b/src/Reporter.tsx index cab4896..69d3951 100644 --- a/src/Reporter.tsx +++ b/src/Reporter.tsx @@ -222,6 +222,27 @@ const RunningTests: React.FC<{ ); }; +const Exiter: React.FC<{ done: boolean }> = ({ done }) => { + const { exit } = useApp(); + + const [shouldExit, setShouldExit] = React.useState(false); + + // use a separate effect to ensure output is properly flushed. This _might_ be a bug in Ink, not sure + React.useEffect(() => { + if (done) { + setShouldExit(true); + } + }, [done, exit]); + + React.useEffect(() => { + if (shouldExit) { + exit(); + } + }, [exit, shouldExit]); + + return null; +}; + const Reporter: React.FC = ({ register, globalConfig, @@ -247,13 +268,6 @@ const Reporter: React.FC = ({ state; const { estimatedTime = 0 } = options; - const { exit } = useApp(); - React.useEffect(() => { - if (done) { - setImmediate(exit); - } - }, [done, exit]); - const summary = ( = ({ /> {done ? null : summary} + ); };