- 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
44 lines
1.4 KiB
JavaScript
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
|