diff --git a/src/modules/essentials/poku.ts b/src/modules/essentials/poku.ts index 6003de8f..710fba72 100644 --- a/src/modules/essentials/poku.ts +++ b/src/modules/essentials/poku.ts @@ -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 = () => { @@ -60,6 +59,8 @@ export async function poku( finalResults.time = total; + showLogs && showTestResults(); + exit(code, configs?.quiet); return; } @@ -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; diff --git a/src/services/format.ts b/src/services/format.ts index d7f94c75..c13cc479 100644 --- a/src/services/format.ts +++ b/src/services/format.ts @@ -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, @@ -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') + ); + } +};