Skip to content

Commit

Permalink
Merge pull request #221 from RemiBardon/no-color-if-zero
Browse files Browse the repository at this point in the history
Color summary results only when value is greater than 0
  • Loading branch information
mishushakov authored Jun 5, 2024
2 parents 85766bc + 6a64853 commit 7f1f808
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/render.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk'
import chalk, { Chalk } from 'chalk'
import { highlight, Theme } from 'cli-highlight'
import { StepResult, WorkflowResult } from '@stepci/runner'
import { HTTPStepRequest, HTTPStepResponse } from '@stepci/runner/dist/steps/http'
Expand Down Expand Up @@ -182,8 +182,12 @@ export function renderSummary (result: WorkflowResult['result']) {
const skippedSteps = steps.filter(step => step.skipped).length
const failedSteps = steps.filter(step => !step.passed).length

console.log(`\n${chalk.bold('Tests:')} ${chalk.redBright.bold(failedTests + ' failed')}, ${chalk.greenBright.bold(passedTests + ' passed')}, ${result.tests.length} total`)
console.log(`${chalk.bold('Steps:')} ${chalk.redBright.bold(failedSteps + ' failed')}, ${chalk.yellowBright.bold(skippedSteps + ' skipped')}, ${chalk.greenBright.bold(passedSteps + ' passed')}, ${steps.length} total`)
function colorIfNonZero(n: number, color: Chalk, text: string): string {
return n > 0 ? color.bold(text) : chalk.bold(text)
}

console.log(`\n${chalk.bold('Tests:')} ${colorIfNonZero(failedTests, chalk.redBright, failedTests + ' failed')}, ${colorIfNonZero(passedTests, chalk.greenBright, passedTests + ' passed')}, ${result.tests.length} total`)
console.log(`${chalk.bold('Steps:')} ${colorIfNonZero(failedSteps, chalk.redBright, failedSteps + ' failed')}, ${colorIfNonZero(skippedSteps, chalk.yellowBright, skippedSteps + ' skipped')}, ${colorIfNonZero(passedSteps, chalk.greenBright, passedSteps + ' passed')}, ${steps.length} total`)
console.log(`${chalk.bold('Time:')} ${result.duration / 1000}s, estimated ${(result.duration / 1000).toFixed(0)}s`)
console.log(`${chalk.bold('CO2:')} ${chalk.greenBright(result.co2.toFixed(5) + 'g')}`)
console.log(result.passed
Expand Down

0 comments on commit 7f1f808

Please sign in to comment.