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(output): always list files at the end of a test run #616

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
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
31 changes: 5 additions & 26 deletions src/modules/essentials/poku.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import process from 'node:process';
import { runTests, runTestsParallel } from '../../services/run-tests.js';
import { Write } from '../../services/write.js';
import { exit } from '../helpers/exit.js';
import { format } from '../../services/format.js';
import { format, showTestResults } from '../../services/format.js';
import { isQuiet } from '../../parsers/output.js';
import { fileResults, finalResults } from '../../configs/files.js';
import { indentation } from '../../configs/indentation.js';
import { finalResults } from '../../configs/files.js';

/* c8 ignore next 3 */ // Process-based
export const onSigint = () => {
Expand Down Expand Up @@ -60,6 +59,8 @@ export async function poku(

finalResults.time = total;

showLogs && showTestResults();

exit(code, configs?.quiet);
return;
}
Expand Down Expand Up @@ -94,29 +95,7 @@ export async function poku(
finalResults.time = total;
}

showLogs && Write.hr();

if (showLogs && fileResults.success.size > 0) {
Write.log(
Array.from(fileResults.success)
.map(
([file, time]) =>
`${indentation.test}${format('✔').success()} ${format(`${file} ${format(`› ${time}ms`).success()}`).dim()}`
)
.join('\n')
);
}

if (showLogs && fileResults.fail.size > 0) {
Write.log(
Array.from(fileResults.fail)
.map(
([file, time]) =>
`${indentation.test}${format('✘').fail()} ${format(`${file} ${format(`› ${time}ms`).fail()}`).dim()}`
)
.join('\n')
);
}
showLogs && showTestResults();

if (configs?.noExit) {
return code;
Expand Down
30 changes: 30 additions & 0 deletions src/services/format.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { fileResults } from '../configs/files.js';
import { indentation } from '../configs/indentation.js';
import { Write } from '../services/write.js';

export const backgroundColor = {
white: 7,
black: 40,
Expand Down Expand Up @@ -89,3 +93,29 @@ export const format = (text: string) => Formatter.create(text);

export const getLargestStringLength = (arr: string[]): number =>
arr.reduce((max, current) => Math.max(max, current.length), 0);

export const showTestResults = () => {
Write.hr();

if (fileResults.success.size > 0) {
Write.log(
Array.from(fileResults.success)
.map(
([file, time]) =>
`${indentation.test}${format('✔').success()} ${format(`${file} ${format(`› ${time}ms`).success()}`).dim()}`
)
.join('\n')
);
}

if (fileResults.fail.size > 0) {
Write.log(
Array.from(fileResults.fail)
.map(
([file, time]) =>
`${indentation.test}${format('✘').fail()} ${format(`${file} ${format(`› ${time}ms`).fail()}`).dim()}`
)
.join('\n')
);
}
};
Loading