Created
August 1, 2022 12:18
-
-
Save richarcher/1eaeaeae592aed195548f5f3c282a0ab to your computer and use it in GitHub Desktop.
Proptype warnings etc are getting in the way - this just strips the output to a rspec-style `.`, `F`, `*`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pluralize = (word, count) => `${count} ${word}${count === 1 ? '' : 's'}` | |
// filtering out the consoles - '.' for a pass, 'F' for a fail, and '*' for a skipped test | |
// wholesale stolen/adapted from https://github.com/jodonnell/jest-simple-dot-reporter | |
// usage npm test -- --reporters="<rootDir>/dev_scripts/oz-simple-jest-reporter.js" | |
class OzSimpleJestReporter { | |
constructor(globalConfig, options) { | |
this.globalConfig = globalConfig | |
this.options = options | |
} | |
onRunStart(test) { | |
this.numTestSuitesLeft = test.numTotalTestSuites | |
console.log(`\nFound ${test.numTotalTestSuites} test suites`) | |
} | |
onRunComplete(test, results) { | |
const { | |
numFailedTests, | |
numPassedTests, | |
numTodoTests, | |
numPendingTests, | |
testResults, | |
numTotalTests, | |
startTime | |
} = results | |
console.log() | |
testResults.map(({ failureMessage }) => { | |
if (failureMessage) { | |
console.error(failureMessage) | |
} | |
}) | |
if (!results.snapshot.didUpdate && results.snapshot.unchecked) { | |
const obsoleteError = `${pluralize('obsolete snapshot', results.snapshot.unchecked)} found.` | |
if (this.options.color) { console.error(`\x1b[31m${obsoleteError}\x1b[0m`) } else { console.error(obsoleteError) } | |
} | |
console.log(`Ran ${numTotalTests} tests in ${testDuration()}`) | |
process.stdout.write(` ${numPassedTests || 0} passing`) | |
process.stdout.write(` ${numFailedTests || 0} failing`) | |
process.stdout.write(` ${(numTodoTests || 0) + (numPendingTests || 0)} skipped`) | |
console.log() | |
function testDuration() { | |
const end = new Date() | |
const start = new Date(startTime) | |
const seconds = (end - start) / 1000 | |
return `${seconds} s` | |
} | |
} | |
onTestResult(test, testResult) { | |
for (let i = 0; i < testResult.testResults.length; i++) { | |
switch (testResult.testResults[i].status) { | |
case 'passed': | |
process.stdout.write('.') | |
break | |
case 'skipped': | |
case 'pending': | |
case 'todo': | |
case 'disabled': | |
process.stdout.write('*') | |
break | |
case 'failed': | |
process.stdout.write('F') | |
break | |
default: | |
process.stdout.write(`(${testResult.testResults[i].status})`) | |
} | |
} | |
if (!--this.numTestSuitesLeft && this.globalConfig.collectCoverage) { | |
console.log() | |
} | |
} | |
} | |
module.exports = OzSimpleJestReporter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment