From 904bb20eb42082fc2b0685314adc505a8d2bfc17 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Thu, 14 Nov 2019 09:36:24 +0100 Subject: [PATCH 1/2] fix: put summary in `` Fixes #9 --- src/Reporter.tsx | 83 ++++++++++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/src/Reporter.tsx b/src/Reporter.tsx index df93daf..cab4896 100644 --- a/src/Reporter.tsx +++ b/src/Reporter.tsx @@ -89,35 +89,43 @@ const FailureMessage: React.FC<{ const CompletedTests: React.FC<{ completedTests: State['completedTests']; globalConfig: Config.GlobalConfig; -}> = ({ completedTests, globalConfig }) => { + summary: React.ReactElement; + PostMessage: () => React.ReactElement; + done: boolean; +}> = ({ completedTests, globalConfig, summary, PostMessage, done }) => { if (completedTests.length === 0) { return null; } const didUpdate = globalConfig.updateSnapshot === 'all'; + let testOutputs = completedTests.map(({ testResult, config }) => ( + + + + + + + + )); + + if (done) { + testOutputs = testOutputs.concat( + + {summary} + , + + + , + ); + } + return ( - - {({ testResult, config }) => ( - - - - - - - - )} - + {ele => ele} ); }; @@ -242,29 +250,34 @@ const Reporter: React.FC = ({ const { exit } = useApp(); React.useEffect(() => { if (done) { - exit(); + setImmediate(exit); } }, [done, exit]); + const summary = ( + + ); return ( - - ( + + )} /> - {done ? ( - - ) : null} + + {done ? null : summary} ); }; From 55bc253c83fb8c4c9ffc31ea03a2f35f508262ca Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Fri, 15 Nov 2019 12:01:21 +0100 Subject: [PATCH 2/2] 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} + ); };