forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_runner: display failed test stack trace with dot reporter
PR-URL: nodejs#52655 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Chemi Atlow <[email protected]>
- Loading branch information
Showing
7 changed files
with
376 additions
and
84 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
'use strict'; | ||
const { | ||
ArrayPrototypeJoin, | ||
RegExpPrototypeSymbolSplit, | ||
SafeMap, | ||
StringPrototypeRepeat, | ||
hardenRegExp, | ||
} = primordials; | ||
const colors = require('internal/util/colors'); | ||
const { inspectWithNoCustomRetry } = require('internal/errors'); | ||
const indentMemo = new SafeMap(); | ||
|
||
const inspectOptions = { | ||
__proto__: null, | ||
colors: colors.shouldColorize(process.stdout), | ||
breakLength: Infinity, | ||
}; | ||
|
||
const reporterUnicodeSymbolMap = { | ||
'__proto__': null, | ||
'test:fail': '\u2716 ', | ||
'test:pass': '\u2714 ', | ||
'test:diagnostic': '\u2139 ', | ||
'test:coverage': '\u2139 ', | ||
'arrow:right': '\u25B6 ', | ||
'hyphen:minus': '\uFE63 ', | ||
}; | ||
|
||
const reporterColorMap = { | ||
'__proto__': null, | ||
get 'test:fail'() { | ||
return colors.red; | ||
}, | ||
get 'test:pass'() { | ||
return colors.green; | ||
}, | ||
get 'test:diagnostic'() { | ||
return colors.blue; | ||
}, | ||
}; | ||
|
||
function indent(nesting) { | ||
let value = indentMemo.get(nesting); | ||
if (value === undefined) { | ||
value = StringPrototypeRepeat(' ', nesting); | ||
indentMemo.set(nesting, value); | ||
} | ||
return value; | ||
} | ||
|
||
function formatError(error, indent) { | ||
if (!error) return ''; | ||
const err = error.code === 'ERR_TEST_FAILURE' ? error.cause : error; | ||
const message = ArrayPrototypeJoin( | ||
RegExpPrototypeSymbolSplit( | ||
hardenRegExp(/\r?\n/), | ||
inspectWithNoCustomRetry(err, inspectOptions), | ||
), `\n${indent} `); | ||
return `\n${indent} ${message}\n`; | ||
} | ||
|
||
function formatTestReport(type, data, prefix = '', indent = '', hasChildren = false) { | ||
let color = reporterColorMap[type] ?? colors.white; | ||
let symbol = reporterUnicodeSymbolMap[type] ?? ' '; | ||
const { skip, todo } = data; | ||
const duration_ms = data.details?.duration_ms ? ` ${colors.gray}(${data.details.duration_ms}ms)${colors.white}` : ''; | ||
let title = `${data.name}${duration_ms}`; | ||
|
||
if (skip !== undefined) { | ||
title += ` # ${typeof skip === 'string' && skip.length ? skip : 'SKIP'}`; | ||
} else if (todo !== undefined) { | ||
title += ` # ${typeof todo === 'string' && todo.length ? todo : 'TODO'}`; | ||
} | ||
const error = formatError(data.details?.error, indent); | ||
if (hasChildren) { | ||
// If this test has had children - it was already reported, so slightly modify the output | ||
const err = !error || data.details?.error?.failureType === 'subtestsFailed' ? '' : `\n${error}`; | ||
return `${prefix}${indent}${color}${reporterUnicodeSymbolMap['arrow:right']}${colors.white}${title}${err}`; | ||
} | ||
if (skip !== undefined) { | ||
color = colors.gray; | ||
symbol = reporterUnicodeSymbolMap['hyphen:minus']; | ||
} | ||
return `${prefix}${indent}${color}${symbol}${title}${colors.white}${error}`; | ||
} | ||
|
||
module.exports = { | ||
__proto__: null, | ||
reporterUnicodeSymbolMap, | ||
reporterColorMap, | ||
formatTestReport, | ||
indent, | ||
}; |
Oops, something went wrong.