Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: put summary in <Static> #10

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 69 additions & 41 deletions src/Reporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => (
<React.Fragment key={testResult.testFilePath + config.name}>
<ResultHeader config={config} testResult={testResult} />
<VerboseTestList testResult={testResult} globalConfig={globalConfig} />
<TestConsoleOutput
console={testResult.console}
verbose={globalConfig.verbose}
cwd={config.cwd}
/>
<FailureMessage failureMessage={testResult.failureMessage} />
<SnapshotStatus snapshot={testResult.snapshot} afterUpdate={didUpdate} />
</React.Fragment>
));

if (done) {
testOutputs = testOutputs.concat(
<Box paddingTop={1} key="summary">
{summary}
</Box>,
<React.Fragment key="postmessage">
<PostMessage />
</React.Fragment>,
);
}

return (
<Box paddingBottom={1} flexDirection="column">
<Static items={completedTests}>
{({ testResult, config }) => (
<React.Fragment key={testResult.testFilePath + config.name}>
<ResultHeader config={config} testResult={testResult} />
<VerboseTestList
testResult={testResult}
globalConfig={globalConfig}
/>
<TestConsoleOutput
console={testResult.console}
verbose={globalConfig.verbose}
cwd={config.cwd}
/>
<FailureMessage failureMessage={testResult.failureMessage} />
<SnapshotStatus
snapshot={testResult.snapshot}
afterUpdate={didUpdate}
/>
</React.Fragment>
)}
</Static>
<Static items={testOutputs}>{ele => ele}</Static>
</Box>
);
};
Expand Down Expand Up @@ -214,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<Props> = ({
register,
globalConfig,
Expand All @@ -239,32 +268,31 @@ const Reporter: React.FC<Props> = ({
state;
const { estimatedTime = 0 } = options;

const { exit } = useApp();
React.useEffect(() => {
if (done) {
exit();
}
}, [done, exit]);

const summary = (
<Summary
aggregatedResults={aggregatedResults}
options={{ estimatedTime, roundTime: true, width }}
done={done}
/>
);
return (
<Box flexDirection="column">
<CompletedTests
completedTests={completedTests}
globalConfig={globalConfig}
/>
<RunningTests tests={currentTests} width={width} />
<Summary
aggregatedResults={aggregatedResults}
options={{ estimatedTime, roundTime: true, width }}
summary={summary}
done={done}
PostMessage={() => (
<PostMessage
aggregatedResults={aggregatedResults}
globalConfig={globalConfig}
contexts={contexts}
/>
)}
/>
{done ? (
<PostMessage
aggregatedResults={aggregatedResults}
globalConfig={globalConfig}
contexts={contexts}
/>
) : null}
<RunningTests tests={currentTests} width={width} />
{done ? null : summary}
<Exiter done={done} />
</Box>
);
};
Expand Down