Skip to content

Commit

Permalink
fix(output): always list files at the end of a test run (#616)
Browse files Browse the repository at this point in the history
  • Loading branch information
wellwelwel authored Jul 27, 2024
1 parent 4c3f289 commit bd47ed4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 26 deletions.
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')
);
}
};

0 comments on commit bd47ed4

Please sign in to comment.