|
| 1 | +import { describe, it } from "node:test"; |
| 2 | +import assert from "node:assert/strict"; |
| 3 | +import { CheckStyleParser } from "./CheckStyleParser.js"; |
| 4 | + |
| 5 | +const EMPTY_CHECKSTYLE_XML = `<?xml version="1.0" encoding="UTF-8"?> |
| 6 | +<checkstyle version="10.0"></checkstyle>`; |
| 7 | + |
| 8 | +const CHECKSTYLE_WITH_ISSUES_XML = `<?xml version="1.0" encoding="UTF-8"?> |
| 9 | +<checkstyle version="10.0"> |
| 10 | + <file name="src/index.js"> |
| 11 | + <error line="5" column="1" severity="warning" message="Unexpected console statement" source="no-console"/> |
| 12 | + </file> |
| 13 | +</checkstyle>`; |
| 14 | + |
| 15 | +describe("CheckStyleParser", () => { |
| 16 | + it("keeps auto-pattern path detection synchronized", () => { |
| 17 | + const parser = new CheckStyleParser(); |
| 18 | + const filePath = "application/humanize-checkstyle-result.xml"; |
| 19 | + |
| 20 | + assert.ok(parser.matchesAutoPatterns(filePath)); |
| 21 | + assert.ok(parser.canParse(filePath, EMPTY_CHECKSTYLE_XML)); |
| 22 | + }); |
| 23 | + |
| 24 | + it("identifies valid checkstyle XML reports without file entries", () => { |
| 25 | + const parser = new CheckStyleParser(); |
| 26 | + |
| 27 | + assert.ok( |
| 28 | + parser.canParse( |
| 29 | + "application/humanize-report-checkstyle.xml", |
| 30 | + EMPTY_CHECKSTYLE_XML, |
| 31 | + ), |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + it("parses empty checkstyle reports as zero lint issues", () => { |
| 36 | + const parser = new CheckStyleParser(); |
| 37 | + |
| 38 | + const reportData = parser.parse( |
| 39 | + EMPTY_CHECKSTYLE_XML, |
| 40 | + "application/humanize-report-checkstyle.xml", |
| 41 | + ); |
| 42 | + assert.strictEqual(reportData.lintIssues.length, 0); |
| 43 | + }); |
| 44 | + |
| 45 | + it("parses checkstyle issues from file entries", () => { |
| 46 | + const parser = new CheckStyleParser(); |
| 47 | + |
| 48 | + const reportData = parser.parse( |
| 49 | + CHECKSTYLE_WITH_ISSUES_XML, |
| 50 | + "checkstyle-result.xml", |
| 51 | + ); |
| 52 | + |
| 53 | + assert.strictEqual(reportData.lintIssues.length, 1); |
| 54 | + assert.strictEqual(reportData.lintIssues[0].file, "src/index.js"); |
| 55 | + assert.strictEqual(reportData.lintIssues[0].line, 5); |
| 56 | + assert.strictEqual(reportData.lintIssues[0].column, 1); |
| 57 | + assert.strictEqual(reportData.lintIssues[0].severity, "warning"); |
| 58 | + assert.strictEqual(reportData.lintIssues[0].rule, "no-console"); |
| 59 | + }); |
| 60 | +}); |
0 commit comments