Skip to content

Commit

Permalink
fix: pretty print errors and duration
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Sep 20, 2023
1 parent ac86684 commit a83d616
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions test/runTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const files = readdirSync(__dirname)
.filter((f) => f.endsWith('.ts') && f !== basename(__filename))
.map((f) => `${__dirname}/${f}`)

const start = Date.now()

const testStream = run({
files,
timeout: 60 * 1000,
Expand All @@ -26,10 +28,11 @@ const summary: string[] = []
testStream.on('test:fail', (data) => {
exitCode = 1
const error = data.details.error

summary.push(
`${data.file} - Test "${data.name}" failed in ${Math.round(
`${data.file} - "${data.name}" (${Math.round(
data.details.duration_ms,
)}ms: ${error.message}\n${error.stack} `,
)}ms)\n${error.toString()} `,
)
})

Expand All @@ -38,10 +41,17 @@ testStream.on('test:stderr', (data) => {
})

testStream.once('end', () => {
const duration = Date.now() - start
// print duration in blue
console.log(
'\x1b[34m%s\x1b[0m',
`ℹ Duration: ${duration / 1000}s`,
'\x1b[0m',
)
if (summary.length > 0) {
console.error('--- ERRORS SUMMARY ---\n')
console.error('\x1b[31m%s\x1b[0m', summary.join('\n'), '\x1b[0m\n')
console.error('--- END OF SUMMARY ---')
console.error('\x1b[31m%s\x1b', '\n✖ failing tests:\n')
console.error(summary.join('\n'))
console.error('\n------', '\x1b[0m\n')
}
process.exit(exitCode)
})

0 comments on commit a83d616

Please sign in to comment.