Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #23 from education/change-output-wording
Browse files Browse the repository at this point in the history
Fix formatting of output
  • Loading branch information
ashishkeshan authored Feb 14, 2024
2 parents 4ef13fe + 8711311 commit fad0095
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 29 deletions.
2 changes: 0 additions & 2 deletions src/aggregate-results.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) + "%";
Expand Down
59 changes: 32 additions & 27 deletions src/console-results.js
Original file line number Diff line number Diff line change
@@ -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)
}
};
}

0 comments on commit fad0095

Please sign in to comment.