forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint-translation-reporter.js
43 lines (37 loc) · 1.38 KB
/
lint-translation-reporter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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