Skip to content

Commit 20f3434

Browse files
committed
feat(jest): use a new jest custom reporter that provides verbose test output while suppressing console logs for passing tests. Only shows console output (like console.error) for failed tests.
1 parent a0cd3ff commit 20f3434

File tree

3 files changed

+72
-3
lines changed

3 files changed

+72
-3
lines changed

jest-custom-reporter.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* Custom Jest reporter that provides verbose test output with colors
3+
* while suppressing console logs for passing tests. Only shows console
4+
* output (like console.error) for failed tests.
5+
*/
6+
7+
const { DefaultReporter } = require('@jest/reporters')
8+
const chalk = require('chalk')
9+
10+
class Reporter extends DefaultReporter {
11+
constructor(globalConfig, options) {
12+
super(globalConfig, options)
13+
}
14+
15+
printTestFileHeader(testPath, config, result) {
16+
// Don't call super to avoid printing console output
17+
const testFileName = testPath.replace(process.cwd() + '/', '')
18+
const duration = result.perfStats ? ((result.perfStats.end - result.perfStats.start) / 1000).toFixed(3) : '0.000'
19+
const status = result.numFailingTests === 0 ? chalk.green('PASS') : chalk.red('FAIL')
20+
21+
this.log(`${status} ${testFileName} ${chalk.gray(`(${duration} s)`)}`)
22+
23+
// Print test structure
24+
const testsByGroup = {}
25+
result.testResults.forEach(test => {
26+
const groupName = test.ancestorTitles[0] || 'Root'
27+
if (!testsByGroup[groupName]) {
28+
testsByGroup[groupName] = []
29+
}
30+
testsByGroup[groupName].push(test)
31+
})
32+
33+
Object.entries(testsByGroup).forEach(([groupName, tests]) => {
34+
if (groupName !== 'Root') {
35+
this.log(` ${groupName}`)
36+
}
37+
tests.forEach(test => {
38+
const prefix = groupName !== 'Root' ? ' ' : ' '
39+
const status = test.status === 'passed' ? chalk.green('✓') : chalk.red('✗')
40+
const duration = test.duration ? chalk.gray(` (${test.duration} ms)`) : ''
41+
this.log(`${prefix}${status} ${test.title}${duration}`)
42+
})
43+
})
44+
45+
// Show console output only for failed tests
46+
if (result.numFailingTests > 0 && result.console && result.console.length > 0) {
47+
result.console.forEach(entry => {
48+
this.log(` ${entry.type}`)
49+
this.log(` ${entry.message}`)
50+
})
51+
}
52+
}
53+
54+
onRunComplete(contexts, results) {
55+
this.log('')
56+
const passedSuites = chalk.green(`${results.numPassedTestSuites} passed`)
57+
const failedSuites = results.numFailedTestSuites > 0 ? `, ${chalk.red(`${results.numFailedTestSuites} failed`)}` : ''
58+
this.log(`Test Suites: ${passedSuites}${failedSuites}, ${results.numTotalTestSuites} total`)
59+
60+
const passedTests = chalk.green(`${results.numPassedTests} passed`)
61+
const failedTests = results.numFailedTests > 0 ? `, ${chalk.red(`${results.numFailedTests} failed`)}` : ''
62+
this.log(`Tests: ${passedTests}${failedTests}, ${results.numTotalTests} total`)
63+
64+
this.log(`Snapshots: ${results.snapshot.total} total`)
65+
const duration = results.testRuntimeSummary ? (results.testRuntimeSummary.slow / 1000).toFixed(1) : '0.0'
66+
this.log(`Time: ${duration} s`)
67+
}
68+
}
69+
70+
module.exports = Reporter

jest.config.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ module.exports = {
1313
}
1414
]
1515
},
16-
// Other Jest configuration options
1716
reporters: [
18-
'default',
17+
'./jest-custom-reporter.js',
1918
[
2019
'jest-html-reporter',
2120
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlitecloud/drivers",
3-
"version": "1.0.574",
3+
"version": "1.0.611",
44
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",

0 commit comments

Comments
 (0)