Skip to content

Commit

Permalink
refactor: use array destructuring for easy output align, var jsdoc syncs
Browse files Browse the repository at this point in the history
  • Loading branch information
andreidmt committed Feb 10, 2023
1 parent 768cfab commit b683b78
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions lib/run-one.tap-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const highlightFileName = filePath => {
* name: "src/__tests__/index.test.js",
* errors: [],
* })
* // => "ok 1 - 0.8s | src/__tests__/index.test.js"
* // => "ok 1 - src/__tests__/index.test.js 0.8s"
*
* @example
* formatTestResult({
Expand All @@ -77,12 +77,12 @@ const highlightFileName = filePath => {
* { row: 1, column: 1, message: "Unexpected token" },
* ],
* })
* // => "not ok 1 - 1.2s | src/__tests__/index.test.js"
* // => "not ok 1 - src/__tests__/index.test.js 1.2s"
* // => " ---"
* // => " message: 'Unexpected token'
* // => " severity: fail"
* // => " data:"
* // => " row: 1"
* // => " line: 1"
* // => " column: 1"
* // => " ..."
*/
Expand Down Expand Up @@ -141,28 +141,29 @@ const formatTest = ({
* failCount: 1,
* duration: [5, 420000000]
* })
* // => "# tests 2"
* // => "# pass 1"
* // => "# fail 1"
* // => "# time 5.42s"
* // => "# tests 2"
* // => "# pass 1"
* // => "# fail 1"
* // => "# duration 5.42s"
*/
const formatSuite = ({ passCount, failCount, duration, hasColor }) => {
const hasFailures = failCount > 0
const totalCount = passCount + failCount
let testsLine = `# tests ${totalCount}`
let passLine = `# pass ${passCount}`
let failLine = `# fail ${failCount}`
let durationLine = `# duration ${formatHrTime(duration)}`
let [testsLine, passLine, failLine, durationLine] = [
`# tests ${totalCount}`,
`# pass ${passCount}`,
`# fail ${failCount}`,
`# duration ${formatHrTime(duration)}`,
]

if (hasColor) {
testsLine =
failCount === 0
? ttext.green.fgSecondary(testsLine)
: ttext.red.fgSecondary(testsLine)
testsLine = hasFailures
? ttext.red.fgSecondary(testsLine)
: ttext.green.fgSecondary(testsLine)
passLine = ttext.green.fgSecondary(passLine)
failLine =
failCount === 0
? ttext.gray.fgSecondary(failLine)
: ttext.red.fgSecondary(failLine)
failLine = hasFailures
? ttext.red.fgSecondary(failLine)
: ttext.gray.fgSecondary(failLine)
durationLine = ttext.gray.fgSecondary(durationLine)
}

Expand Down

0 comments on commit b683b78

Please sign in to comment.