Skip to content

Commit

Permalink
feat: use core summary builder for printing summary
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Jun 27, 2023
1 parent 2680d61 commit 2a197d1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
35 changes: 15 additions & 20 deletions modules/core/reporters/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,11 @@ export abstract class BaseReporter {
this.#options = Object.assign({ stackLinesCount: 2 }, options)
}

/**
* Prints a key value pair with justified spacing
*/
#printKeyValuePair(key: string, value: string, whitespaceLength: number) {
console.log(`${ansi.dim(`${key.padEnd(whitespaceLength + 2)} : `)}${value}`)
}

/**
* Pretty prints the aggregates
*/
#printAggregates(summary: RunnerSummary) {
const [tests, time]: string[][] = [[], []]

/**
* Set value for time row
*/
time.push(ansi.dim(ms(summary.duration)))
const tests: string[] = []

/**
* Set value for tests row
Expand All @@ -90,13 +78,20 @@ export abstract class BaseReporter {
tests.push(ansi.magenta(`${summary.aggregates.regression} regression`))
}

const keysPadding = 5
this.#printKeyValuePair(
'Tests',
`${tests.join(', ')} ${ansi.dim(`(${summary.aggregates.total})`)}`,
keysPadding
)
this.#printKeyValuePair('Time', time.join(''), keysPadding)
this.runner!.summaryBuilder.use(() => {
return [
{
key: ansi.dim('Tests'),
value: `${tests.join(', ')} ${ansi.dim(`(${summary.aggregates.total})`)}`,
},
{
key: ansi.dim('Time'),
value: ansi.dim(ms(summary.duration)),
},
]
})

console.log(this.runner!.summaryBuilder.build().join('\n'))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"typescript": "^5.1.3"
},
"dependencies": {
"@japa/core": "^8.0.0-5",
"@japa/core": "^8.0.0-6",
"@japa/errors-printer": "^3.0.0-4",
"@poppinss/cliui": "^6.1.1-2",
"@poppinss/hooks": "^7.1.1-3",
Expand Down
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import type { HookHandler } from '@poppinss/hooks/types'

import type { Emitter, Refiner, Runner, Suite } from '../modules/core/main.js'
import type { FilteringOptions, NamedReporterContract } from '../modules/core/types.js'

export * from '../modules/core/types.js'

/**
Expand Down

0 comments on commit 2a197d1

Please sign in to comment.