Skip to content

Commit

Permalink
fix(commitlint-config): junit formatter updated to include top level …
Browse files Browse the repository at this point in the history
…title
  • Loading branch information
SimeonC committed Feb 2, 2024
1 parent c4d24a4 commit 24ee1c6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 17 additions & 9 deletions packages/commitlint-config/formatters/junit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@

const builder = require('junit-report-builder');

const levelMap = {
[0]: 'Disabled',
[1]: 'Warning',
[2]: 'Error',
};

/**
* Format the commitlint report as a valid JUnit XML report.
*
Expand All @@ -19,27 +25,29 @@ function formatJunit(report = {}) {
const errorCount = result.errors?.length || 0;
const warningCount = result.warnings?.length || 0;
const suite = builder.testSuite().name(result.input);
suite.property('errors', errorCount);
suite.property('failures', errorCount + warningCount);
suite.property('tests', Math.max(errorCount + warningCount, 1));
suite.property('skipped', 0);

result.errors?.forEach((error) => {
const testcase = suite.testCase().className('error').name(error.name);
testcase.failure('error').standardOutput(error.message);
suite
.testCase()
.name(error.name)
.className(levelMap[error.level])
.error(error.message);
});

result.warnings?.forEach((warning) => {
const testcase = suite.testCase().className('warning').name(warning.name);
testcase.failure('warning').standardOutput(warning.message);
suite
.testCase()
.name(warning.name)
.className(levelMap[warning.level])
.failure(warning.message);
});

if (errorCount + warningCount === 0) {
suite.testCase().className('valid').name('valid');
}
});

return builder.build();
return builder.name('Commit Lint').build();
}

module.exports = formatJunit;
2 changes: 1 addition & 1 deletion packages/commitlint-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"files": ["formatters"],
"dependencies": {
"@commitlint/config-conventional": "^17",
"junit-report-builder": "3.0.1"
"junit-report-builder": "3.2.1"
},
"peerDependencies": {
"@commitlint/cli": "^17"
Expand Down

0 comments on commit 24ee1c6

Please sign in to comment.