diff --git a/src/aggregate-results.js b/src/aggregate-results.js index 6e4ca94..32c9982 100644 --- a/src/aggregate-results.js +++ b/src/aggregate-results.js @@ -27,8 +27,6 @@ function AggregateResults(runnerResults) { colWidths: [20, 13, 13], }); - console.log(COLORS.magenta, "Test runner summary", COLORS.reset); - const totals = getTableTotals(runnerResults, (row) => table.push(row)); // const totalPercent = totals.reduce(totalPercentageReducer, 0).toFixed(2) + "%"; diff --git a/src/console-results.js b/src/console-results.js index 5fe4c55..508ac9f 100644 --- a/src/console-results.js +++ b/src/console-results.js @@ -1,48 +1,53 @@ -const { COLORS } = require("./colors"); -const { AggregateResults } = require("./aggregate-results"); - +const {COLORS} = require('./colors') +const {AggregateResults} = require('./aggregate-results') +const {getTestScore, getMaxScoreForTest} = require('./helpers/test-helpers') exports.ConsoleResults = function ConsoleResults(runnerResults) { try { - let grandTotalPassedTests = 0; - let grandTotalTests = 0; + let grandTotalPassedTests = 0 + let grandTotalTests = 0 - runnerResults.forEach(({ runner, results }, index) => { + runnerResults.forEach(({runner, results}, index) => { // Fun transition to new runner + const maxScore = getMaxScoreForTest(results) + // const weight = getTestWeight(maxScore, totalMaxScore); + const score = getTestScore(results) if (index > 0) { - console.log(`${COLORS.magenta}🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀${COLORS.reset}\n`); + console.log(`${COLORS.magenta}🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀${COLORS.reset}\n`) } - console.log(`🔄 Processing: ${runner}`); - let passedTests = 0; - const totalTests = results.tests.length; + console.log(`🔄 Processing: ${runner}`) + let passedTests = 0 + const totalTests = results.tests.length results.tests.forEach((test) => { - if (test.status === "pass") { - console.log(`${COLORS.green}✅ ${test.name}\n${COLORS.reset}`); - passedTests += 1; - } else if (test.status === "error") { - console.log(`Error: ${test.message || `Failed to run test '${test.name}'`}\n${COLORS.reset}`); + if (test.status === 'pass') { + console.log(`${COLORS.green}✅ ${test.name}${COLORS.reset}`) + passedTests += 1 + } else if (test.status === 'error') { + console.log(`Error: ${test.message || `Failed to run test '${test.name}'`}\n${COLORS.reset}`) } else { - console.log(`${COLORS.red}❌ ${test.name}\n`); - console.log(`${test.message || ""}\n${COLORS.reset}`); + console.log(`${COLORS.red}❌ ${test.name}\n`) + console.log(`${test.message || ''}\n${COLORS.reset}`) } - }); + }) // Update grand totals - grandTotalPassedTests += passedTests; - grandTotalTests += totalTests; + grandTotalPassedTests += passedTests + grandTotalTests += totalTests // Calculate and display points for the current runner - const points = (passedTests / totalTests) * 100; - console.log(`Total points for ${runner}: ${points.toFixed(2)}/100\n`); - }); + console.log(`Total points for ${runner}: ${score.toFixed(2)}/${maxScore}\n`) + }) + + console.log(`${COLORS.magenta}Test runner summary${COLORS.magenta}`) // Calculate and display grand total points - const grandTotalPoints = (grandTotalPassedTests / grandTotalTests) * 100; AggregateResults(runnerResults) - console.log(`${COLORS.cyan}🏆 Grand total points: ${grandTotalPassedTests}/${grandTotalTests}${COLORS.reset}\n`); + console.log( + `${COLORS.cyan}🏆 Grand total tests passed: ${grandTotalPassedTests}/${grandTotalTests}${COLORS.reset}\n`, + ) } catch (error) { - throw new Error(error.message); + throw new Error(error.message) } -}; +}