Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #171 from Lootjs/feat/junit-report
Browse files Browse the repository at this point in the history
added junit report
  • Loading branch information
hcodes authored Oct 3, 2021
2 parents 81f61c1 + 5472121 commit f1aeb27
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Examples:<br/>


#### `--report <type>`
Set type of report: `console`, `html`, `markdown` or `json`.<br/>
Set type of report: `console`, `html`, `markdown`, `junit` or `json`.<br/>
Default: `console`<br/>
Example: `console,html,custom_report.js`

Expand Down
2 changes: 1 addition & 1 deletion README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ JSON-файл собственного словаря.
`yaspeller --dictionary my_dict.json:my_dict2.json .`

#### `--report <type>`
Задать вид отчёта: `console`, `html`, `markdown` или `json`.<br/>
Задать вид отчёта: `console`, `html`, `markdown`, `junit` или `json`.<br/>
По умолчанию: `console`<br/>
Пример: `console,html,custom_report.js`

Expand Down
2 changes: 2 additions & 0 deletions lib/reports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const consoleReport = require('./console');
const errorDictionaryReport = require('./error_dictionary');
const htmlReport = require('./html');
const jsonReport = require('./json');
const junitReport = require('./junit');
const markdownReport = require('./markdown');

class Reports {
Expand All @@ -23,6 +24,7 @@ class Reports {
errorDictionaryReport,
htmlReport,
jsonReport,
junitReport,
markdownReport,
];

Expand Down
32 changes: 32 additions & 0 deletions lib/reports/junit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';

const fs = require('fs');
const { consoleError, consoleInfo } = require('../helpers/console');
const filename = 'yaspeller_report.junit.xml';
/**
* @param {number} ms
* @returns {number}
*/
const msToSec = (ms) => ms / 1000;

module.exports = {
name: 'junit',
onComplete(data) {
try {
const header = '<?xml version="1.0" encoding="UTF-8"?>\n<testsuites><testsuite name="speller" time="">\n';
const footer = '\n</testsuite></testsuites>';
const items = data.map(([, item]) => {
const errors = item.data.map(error =>
`<error message="${error.word} ${error.suggest ? '-> ' + error.suggest.join(', ') : ''}"/>`
).join('');
return `<testcase classname="${item.resource}" name="${item.resource}" file="${item.resource}" time="${msToSec(item.time)}">
${errors}
</testcase>`;
}).join('\n');
fs.writeFileSync(filename, header + items + footer);
consoleInfo(`Junit report: ./${filename}`);
} catch (e) {
consoleError(e);
}
}
};

0 comments on commit f1aeb27

Please sign in to comment.