| 3 | import { FormatterCallback } from '../formatter' |
| 4 | |
| 5 | const junitFormatter: FormatterCallback = function (formatter, HTMLHint) { |
| 6 | formatter.on('end', (event) => { |
| 7 | const arrTestcase: XmlObject[] = [] |
| 8 | const arrAllMessages = event.arrAllMessages |
| 9 | |
| 10 | arrAllMessages.forEach((fileInfo) => { |
| 11 | const arrMessages = fileInfo.messages |
| 12 | const arrLogs = HTMLHint.format(arrMessages) |
| 13 | |
| 14 | arrTestcase.push({ |
| 15 | testcase: [ |
| 16 | { |
| 17 | _attr: { |
| 18 | name: fileInfo.file, |
| 19 | time: (fileInfo.time / 1000).toFixed(3), |
| 20 | }, |
| 21 | }, |
| 22 | { |
| 23 | failure: { |
| 24 | _attr: { |
| 25 | message: `Found ${arrMessages.length} errors`, |
| 26 | }, |
| 27 | _cdata: arrLogs.join('\r\n'), |
| 28 | }, |
| 29 | }, |
| 30 | ], |
| 31 | }) |
| 32 | }) |
| 33 | |
| 34 | const objXml: XmlObject = { |
| 35 | testsuites: [ |
| 36 | { |
| 37 | testsuite: [ |
| 38 | { |
| 39 | _attr: { |
| 40 | name: 'HTMLHint Tests', |
| 41 | time: (event.time / 1000).toFixed(3), |
| 42 | tests: event.allFileCount, |
| 43 | failures: arrAllMessages.length, |
| 44 | }, |
| 45 | }, |
| 46 | ...arrTestcase, |
| 47 | ], |
| 48 | }, |
| 49 | ], |
| 50 | } |
| 51 | |
| 52 | console.log( |
| 53 | xml(objXml, { |
| 54 | declaration: true, |
| 55 | indent: ' ', |
| 56 | }) |
| 57 | ) |
| 58 | }) |
| 59 | } |
| 60 | |
| 61 | module.exports = junitFormatter |