1
0
mirror of synced 2025-12-22 11:26:57 -05:00
Files
docs/tests/helpers/lint-translation-reporter.js
Vanessa Yuen a8d54c9af7 Improvements in tools to help merge crowdin PRs (#18409)
- add `script/test-render-translation.js` to render all translated content to catch malformed liquid that would cause render errors
- improve test output for `script/fix-translation-errors.js` and `tests/content/lint-files.js`
- make it so `script/reset-translated-file.js` can handle files that have been renamed
2021-03-26 19:21:45 +00:00

44 lines
1.4 KiB
JavaScript

const chalk = require('chalk')
const stripAnsi = require('strip-ansi')
const { groupBy } = require('lodash')
// we don't want to print all the stack traces
const stackTraceRegExp = /^\s+at\s.+/img
class TranslationReporter {
constructor (globalConfig, options) {
this._globalConfig = globalConfig
this._options = options
}
onRunComplete (contexts, results) {
const failures = results.testResults.reduce((fails, { testResults: assertionResults }) => {
const formattedFails = assertionResults
.filter(result => result.status === 'failed')
.map(({ ancestorTitles, failureMessages, title }) => {
return {
fileName: ancestorTitles[1],
failedTests: title,
failureMessage: failureMessages.map((message) => {
return message.split('\n').filter(line => !stackTraceRegExp.test(stripAnsi(line))).join('\n')
})
}
})
return [...fails, ...formattedFails]
}, [])
const failuresByFile = groupBy(failures, 'fileName')
for (const fileName in failuresByFile) {
console.group(chalk.red.bold(`\n${fileName}`))
failuresByFile[fileName].forEach(({ failureMessage }, index) => {
console.log(chalk.bold(`\n(${index + 1})`))
failureMessage.forEach(msg => console.log(msg))
})
console.groupEnd()
}
}
}
module.exports = TranslationReporter