Skip to content

Commit

Permalink
feat(reporter πŸ›): improve CLI output when files have changed but test…
Browse files Browse the repository at this point in the history
… results have not (phenomnomnominal#1184)
  • Loading branch information
camjackson committed Feb 16, 2024
1 parent 6509f95 commit 8c5eddd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
40 changes: 32 additions & 8 deletions packages/reporter/src/components/suite/SuiteSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
testWorse,
unexpectedChanges,
unexpectedChangesInstructions,
stayedTheSameButChanged,
stayedTheSameButChangedInstructions,
updateInstructions
} from '../../messages.js';

Expand Down Expand Up @@ -73,15 +75,22 @@ export const SuiteSummary: FC<SuiteSummaryProps> = memo(function SuiteSummary({
{expired ? <Text color={TEXT_COLOURS.expired}>{testExpired(tests(expired))})</Text> : null}
</Box>
{context.config.ci && suiteSummary.changed.length ? (
<Box flexDirection="column" paddingBottom={1}>
<Text color={TEXT_COLOURS.changed}>{unexpectedChanges()}</Text>
<Box flexDirection="column" padding={1}>
{suiteSummary.changed.map((name) => (
<Text key={name}>"{name}"</Text>
))}
allChangedTestsStayedTheSame(suiteSummary) ? (
<Box flexDirection="column" paddingBottom={1}>
<Text color={TEXT_COLOURS.changed}>{stayedTheSameButChanged()}</Text>
<Text color={TEXT_COLOURS.changed}>{stayedTheSameButChangedInstructions()}</Text>
</Box>
<Text color={TEXT_COLOURS.changed}>{unexpectedChangesInstructions()}</Text>
</Box>
) : (
<Box flexDirection="column" paddingBottom={1}>
<Text color={TEXT_COLOURS.changed}>{unexpectedChanges()}</Text>
<Box flexDirection="column" padding={1}>
{suiteSummary.changed.map((name) => (
<Text key={name}>"{name}"</Text>
))}
</Box>
<Text color={TEXT_COLOURS.changed}>{unexpectedChangesInstructions()}</Text>
</Box>
)
) : null}
</>
);
Expand All @@ -90,3 +99,18 @@ export const SuiteSummary: FC<SuiteSummaryProps> = memo(function SuiteSummary({
function tests(n: number): string {
return n === 1 ? `${n} test` : `${n} tests`;
}

/**
* Given a suiteSummary, is every test name listed in `changed` also present as
* the name of a test listed in `same`? In that case, the supposedly `changed`
* tests did not really change, only their file hash(es) did.
*/
function allChangedTestsStayedTheSame(suiteSummary: BettererSuiteSummary): boolean {
function testStayedTheSame(testName: string): boolean {
const matchingSuite = suiteSummary.same.find((runSummary) => runSummary.name === testName);

return matchingSuite !== undefined;
}

return suiteSummary.changed.every(testStayedTheSame);
}
8 changes: 8 additions & 0 deletions packages/reporter/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ export function unexpectedChangesInstructions(): string {
return 'You should make sure the results file is up-to-date before committing! You might want to run `betterer precommit` in a commit hook. πŸ’';
}

export function stayedTheSameButChanged(): string {
return 'All test results stayed the same, but your code has changed in other ways.';
}

export function stayedTheSameButChangedInstructions(): string {
return 'You should make sure the results file is up-to-date before committing, and also after a rebase! πŸ”ƒ';
}

export function filesChecking(files: number): string {
return `Checking ${files} ${getFiles(files)}... πŸ€”`;
}
Expand Down
7 changes: 2 additions & 5 deletions test/cli/__snapshots__/ci-diff.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ Array [
1 test got checked. πŸ€”
1 test stayed the same. 😐
Unexpected changes detected in these tests while running in CI mode:
\\"test\\"
You should make sure the results file is up-to-date before committing! You might want to run \`betterer precommit\` in a commit hook. πŸ’
All test results stayed the same, but your code has changed in other ways.
You should make sure the results file is up-to-date before committing, and also after a rebase! πŸ”ƒ
",
]
`;
7 changes: 2 additions & 5 deletions test/cli/__snapshots__/ci-env-variable.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ Array [
1 test got checked. πŸ€”
1 test stayed the same. 😐
Unexpected changes detected in these tests while running in CI mode:
\\"test\\"
You should make sure the results file is up-to-date before committing! You might want to run \`betterer precommit\` in a commit hook. πŸ’
All test results stayed the same, but your code has changed in other ways.
You should make sure the results file is up-to-date before committing, and also after a rebase! πŸ”ƒ
",
]
`;

0 comments on commit 8c5eddd

Please sign in to comment.