Skip to content

Commit

Permalink
fix: always render a summary, remove progress and estimation when done
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Nov 12, 2019
1 parent a28d62c commit 4bc5cb3
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 48 deletions.
47 changes: 17 additions & 30 deletions src/Reporter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { Config } from '@jest/types';
import { AggregatedResult, TestResult } from '@jest/test-result';
import { BaseReporter, ReporterOnStartOptions } from '@jest/reporters';
import { Test } from '@jest/reporters/build/types';
import SnapshotStatus from './SnapshotStatus';
import Summary from './Summary';
import { SnapshotStatus } from './SnapshotStatus';
import { Summary } from './Summary';
import { DisplayName, FormattedPath } from './utils';
import { PaddedColor } from './shared';

Expand Down Expand Up @@ -91,27 +91,21 @@ const TestConsoleOutput = ({
);
};

const CompletedTests = ({
completedTests,
width,
globalConfig,
done,
}: {
const CompletedTests: React.FC<{
completedTests: Array<{
testResult: TestResult;
config: Config.ProjectConfig;
}>;
width?: number;
globalConfig: Config.GlobalConfig;
done: boolean;
}) => {
}> = ({ completedTests, width, globalConfig }) => {
if (completedTests.length === 0) {
return null;
}
const didUpdate = globalConfig.updateSnapshot === 'all';

return (
<Box paddingBottom={done ? 0 : 1} flexDirection="column">
<Box paddingBottom={1} flexDirection="column">
<Static>
{completedTests.map(({ testResult, config }) => (
<React.Fragment key={testResult.testFilePath}>
Expand Down Expand Up @@ -208,16 +202,6 @@ const reporterReducer: React.Reducer<State, DateEvents> = (
}
};

const AppExiter: React.FC = () => {
const { exit } = useApp();

React.useEffect(() => {
exit();
}, [exit]);

return null;
};

const Reporter: React.FC<Props> = ({
register,
globalConfig,
Expand All @@ -241,13 +225,19 @@ const Reporter: React.FC<Props> = ({
const { currentTests, completedTests, aggregatedResults, done } = state;
const { estimatedTime = 0 } = options;

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

return (
<Box flexDirection="column">
<CompletedTests
completedTests={completedTests}
width={width}
globalConfig={globalConfig}
done={done}
/>
{currentTests.length > 0 && (
<Box paddingBottom={1} flexDirection="column">
Expand All @@ -265,14 +255,11 @@ const Reporter: React.FC<Props> = ({
))}
</Box>
)}
{done ? (
<AppExiter />
) : (
<Summary
aggregatedResults={aggregatedResults}
options={{ estimatedTime, roundTime: true, width }}
/>
)}
<Summary
aggregatedResults={aggregatedResults}
options={{ estimatedTime, roundTime: true, width }}
done={done}
/>
</Box>
);
};
Expand Down
4 changes: 1 addition & 3 deletions src/SnapshotStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const SnapshotOutdated: React.FC = ({ children }) => (
</Color>
);

const SnapshotStatus: React.FC<{
export const SnapshotStatus: React.FC<{
snapshot: TestResult['snapshot'];
afterUpdate: boolean;
}> = ({ snapshot, afterUpdate }) => (
Expand Down Expand Up @@ -73,5 +73,3 @@ const SnapshotStatus: React.FC<{
)}
</>
);

export default SnapshotStatus;
34 changes: 19 additions & 15 deletions src/Summary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ const SummaryHeading: React.FC = ({ children }) => (
</Box>
);

const Summary: React.FC<{
export const Summary: React.FC<{
aggregatedResults: AggregatedResult;
done: boolean;
options?: SummaryOptions;
}> = ({ aggregatedResults, options }) => {
}> = ({ aggregatedResults, done, options }) => {
const { startTime } = aggregatedResults;
const [runTime, setRunTime] = React.useState(0);
const time = useCounter();
Expand Down Expand Up @@ -197,13 +198,15 @@ const Summary: React.FC<{
<Box>
<SummaryHeading>Time</SummaryHeading>

<Time runTime={runTime} estimatedTime={estimatedTime} />
<Time runTime={runTime} done={done} estimatedTime={estimatedTime} />
</Box>
<ProgressBar
runTime={runTime}
estimatedTime={estimatedTime}
width={width}
/>
{done ? null : (
<ProgressBar
runTime={runTime}
estimatedTime={estimatedTime}
width={width}
/>
)}
</Box>
);
};
Expand Down Expand Up @@ -237,10 +240,11 @@ const ProgressBar: React.FC<{
);
};

const Time: React.FC<{ runTime: number; estimatedTime: number }> = ({
runTime,
estimatedTime,
}) => {
const Time: React.FC<{
runTime: number;
estimatedTime: number;
done: boolean;
}> = ({ runTime, estimatedTime, done }) => {
// If we are more than one second over the estimated time, highlight it.
const renderedTime =
estimatedTime && runTime >= estimatedTime + 1 ? (
Expand All @@ -254,9 +258,9 @@ const Time: React.FC<{ runTime: number; estimatedTime: number }> = ({
return (
<Box>
{renderedTime}
{runTime < estimatedTime && <>, estimated {estimatedTime}s</>}
{!done && runTime < estimatedTime ? (
<>, estimated {estimatedTime}s</>
) : null}
</Box>
);
};

export default Summary;

0 comments on commit 4bc5cb3

Please sign in to comment.