@retemper/lodestar-reporter-junit 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +97 -0
- package/dist/index.js.map +1 -0
- package/package.json +42 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Minhyeok Kang and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Violation, RunSummary, WorkspaceReporter } from '@retemper/lodestar-types';
|
|
2
|
+
|
|
3
|
+
/** Options for the JUnit reporter */
|
|
4
|
+
interface JunitReporterOptions {
|
|
5
|
+
/** Output file path — writes to stdout if omitted */
|
|
6
|
+
readonly output?: string;
|
|
7
|
+
}
|
|
8
|
+
/** Collected result per rule */
|
|
9
|
+
interface RuleEntry {
|
|
10
|
+
readonly ruleId: string;
|
|
11
|
+
readonly violations: Violation[];
|
|
12
|
+
readonly durationMs: number;
|
|
13
|
+
readonly error?: Error;
|
|
14
|
+
}
|
|
15
|
+
/** Create a JUnit XML reporter that outputs test-suite style results */
|
|
16
|
+
declare function createJunitReporter(options?: JunitReporterOptions): WorkspaceReporter;
|
|
17
|
+
/** Build JUnit XML string from rule entries */
|
|
18
|
+
declare function buildJunitXml(entries: readonly RuleEntry[], summary: RunSummary): string;
|
|
19
|
+
/** Escape special XML characters */
|
|
20
|
+
declare function escapeXml(str: string): string;
|
|
21
|
+
/** Create a JUnit ReporterFactory for use in lodestar config */
|
|
22
|
+
declare function junitReporter(options?: JunitReporterOptions): {
|
|
23
|
+
name: string;
|
|
24
|
+
create: () => WorkspaceReporter;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export { type JunitReporterOptions, buildJunitXml, createJunitReporter, escapeXml, junitReporter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// src/reporter/junit-reporter.ts
|
|
2
|
+
import { writeFile } from "fs/promises";
|
|
3
|
+
function createJunitReporter(options) {
|
|
4
|
+
const ruleEntries = [];
|
|
5
|
+
return {
|
|
6
|
+
name: "junit",
|
|
7
|
+
onStart() {
|
|
8
|
+
},
|
|
9
|
+
onRuleComplete(result) {
|
|
10
|
+
ruleEntries.push({
|
|
11
|
+
ruleId: result.ruleId,
|
|
12
|
+
violations: [...result.violations],
|
|
13
|
+
durationMs: result.durationMs,
|
|
14
|
+
error: result.error
|
|
15
|
+
});
|
|
16
|
+
},
|
|
17
|
+
onViolation() {
|
|
18
|
+
},
|
|
19
|
+
async onComplete(summary) {
|
|
20
|
+
const xml = buildJunitXml(ruleEntries, summary);
|
|
21
|
+
if (options?.output) {
|
|
22
|
+
await writeFile(options.output, xml, "utf-8");
|
|
23
|
+
} else {
|
|
24
|
+
process.stdout.write(xml);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
onPackageStart(_pkg) {
|
|
28
|
+
},
|
|
29
|
+
onPackageComplete(_pkg, _summary) {
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function buildJunitXml(entries, summary) {
|
|
34
|
+
const lines = [];
|
|
35
|
+
lines.push('<?xml version="1.0" encoding="UTF-8"?>');
|
|
36
|
+
const totalTests = entries.length;
|
|
37
|
+
const totalFailures = entries.filter(
|
|
38
|
+
(e) => e.violations.some((v) => v.severity === "error")
|
|
39
|
+
).length;
|
|
40
|
+
const totalErrors = entries.filter((e) => e.error).length;
|
|
41
|
+
const totalTime = (summary.durationMs / 1e3).toFixed(3);
|
|
42
|
+
lines.push(
|
|
43
|
+
`<testsuites tests="${totalTests}" failures="${totalFailures}" errors="${totalErrors}" time="${totalTime}">`
|
|
44
|
+
);
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
const errors = entry.violations.filter((v) => v.severity === "error");
|
|
47
|
+
const warnings = entry.violations.filter((v) => v.severity === "warn");
|
|
48
|
+
const time = (entry.durationMs / 1e3).toFixed(3);
|
|
49
|
+
lines.push(
|
|
50
|
+
` <testsuite name="${escapeXml(entry.ruleId)}" tests="1" failures="${errors.length > 0 ? 1 : 0}" errors="${entry.error ? 1 : 0}" time="${time}">`
|
|
51
|
+
);
|
|
52
|
+
if (entry.error) {
|
|
53
|
+
lines.push(` <testcase name="${escapeXml(entry.ruleId)}" time="${time}">`);
|
|
54
|
+
lines.push(
|
|
55
|
+
` <error message="${escapeXml(entry.error.message)}">${escapeXml(entry.error.message)}</error>`
|
|
56
|
+
);
|
|
57
|
+
lines.push(" </testcase>");
|
|
58
|
+
} else if (errors.length > 0) {
|
|
59
|
+
lines.push(` <testcase name="${escapeXml(entry.ruleId)}" time="${time}">`);
|
|
60
|
+
const failureText = errors.map((v) => formatViolation(v)).join("\n");
|
|
61
|
+
lines.push(
|
|
62
|
+
` <failure message="${escapeXml(`${errors.length} violation(s)`)}">${escapeXml(failureText)}</failure>`
|
|
63
|
+
);
|
|
64
|
+
lines.push(" </testcase>");
|
|
65
|
+
} else if (warnings.length > 0) {
|
|
66
|
+
lines.push(` <testcase name="${escapeXml(entry.ruleId)}" time="${time}">`);
|
|
67
|
+
const warnText = warnings.map((v) => formatViolation(v)).join("\n");
|
|
68
|
+
lines.push(` <system-out>${escapeXml(warnText)}</system-out>`);
|
|
69
|
+
lines.push(" </testcase>");
|
|
70
|
+
} else {
|
|
71
|
+
lines.push(` <testcase name="${escapeXml(entry.ruleId)}" time="${time}"/>`);
|
|
72
|
+
}
|
|
73
|
+
lines.push(" </testsuite>");
|
|
74
|
+
}
|
|
75
|
+
lines.push("</testsuites>");
|
|
76
|
+
return lines.join("\n");
|
|
77
|
+
}
|
|
78
|
+
function formatViolation(v) {
|
|
79
|
+
const location = v.location ? ` at ${v.location.file}${v.location.line ? `:${v.location.line}` : ""}` : "";
|
|
80
|
+
return `${v.message}${location}`;
|
|
81
|
+
}
|
|
82
|
+
function escapeXml(str) {
|
|
83
|
+
return str.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
84
|
+
}
|
|
85
|
+
function junitReporter(options) {
|
|
86
|
+
return {
|
|
87
|
+
name: "junit",
|
|
88
|
+
create: () => createJunitReporter(options)
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export {
|
|
92
|
+
buildJunitXml,
|
|
93
|
+
createJunitReporter,
|
|
94
|
+
escapeXml,
|
|
95
|
+
junitReporter
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/reporter/junit-reporter.ts"],"sourcesContent":["import { writeFile } from 'node:fs/promises';\nimport type {\n WorkspaceReporter,\n WorkspacePackageInfo,\n Violation,\n RunSummary,\n RuleResultSummary,\n} from '@retemper/lodestar-types';\n\n/** Options for the JUnit reporter */\ninterface JunitReporterOptions {\n /** Output file path — writes to stdout if omitted */\n readonly output?: string;\n}\n\n/** Collected result per rule */\ninterface RuleEntry {\n readonly ruleId: string;\n readonly violations: Violation[];\n readonly durationMs: number;\n readonly error?: Error;\n}\n\n/** Create a JUnit XML reporter that outputs test-suite style results */\nfunction createJunitReporter(options?: JunitReporterOptions): WorkspaceReporter {\n const ruleEntries: RuleEntry[] = [];\n\n return {\n name: 'junit',\n\n onStart() {},\n\n onRuleComplete(result: RuleResultSummary) {\n ruleEntries.push({\n ruleId: result.ruleId,\n violations: [...result.violations],\n durationMs: result.durationMs,\n error: result.error,\n });\n },\n\n onViolation() {},\n\n async onComplete(summary: RunSummary) {\n const xml = buildJunitXml(ruleEntries, summary);\n\n if (options?.output) {\n await writeFile(options.output, xml, 'utf-8');\n } else {\n process.stdout.write(xml);\n }\n },\n\n onPackageStart(_pkg: WorkspacePackageInfo) {},\n onPackageComplete(_pkg: WorkspacePackageInfo, _summary: RunSummary) {},\n };\n}\n\n/** Build JUnit XML string from rule entries */\nfunction buildJunitXml(entries: readonly RuleEntry[], summary: RunSummary): string {\n const lines: string[] = [];\n lines.push('<?xml version=\"1.0\" encoding=\"UTF-8\"?>');\n\n const totalTests = entries.length;\n const totalFailures = entries.filter((e) =>\n e.violations.some((v) => v.severity === 'error'),\n ).length;\n const totalErrors = entries.filter((e) => e.error).length;\n const totalTime = (summary.durationMs / 1000).toFixed(3);\n\n lines.push(\n `<testsuites tests=\"${totalTests}\" failures=\"${totalFailures}\" errors=\"${totalErrors}\" time=\"${totalTime}\">`,\n );\n\n for (const entry of entries) {\n const errors = entry.violations.filter((v) => v.severity === 'error');\n const warnings = entry.violations.filter((v) => v.severity === 'warn');\n const time = (entry.durationMs / 1000).toFixed(3);\n\n lines.push(\n ` <testsuite name=\"${escapeXml(entry.ruleId)}\" tests=\"1\" failures=\"${errors.length > 0 ? 1 : 0}\" errors=\"${entry.error ? 1 : 0}\" time=\"${time}\">`,\n );\n\n if (entry.error) {\n lines.push(` <testcase name=\"${escapeXml(entry.ruleId)}\" time=\"${time}\">`);\n lines.push(\n ` <error message=\"${escapeXml(entry.error.message)}\">${escapeXml(entry.error.message)}</error>`,\n );\n lines.push(' </testcase>');\n } else if (errors.length > 0) {\n lines.push(` <testcase name=\"${escapeXml(entry.ruleId)}\" time=\"${time}\">`);\n const failureText = errors.map((v) => formatViolation(v)).join('\\n');\n lines.push(\n ` <failure message=\"${escapeXml(`${errors.length} violation(s)`)}\">${escapeXml(failureText)}</failure>`,\n );\n lines.push(' </testcase>');\n } else if (warnings.length > 0) {\n lines.push(` <testcase name=\"${escapeXml(entry.ruleId)}\" time=\"${time}\">`);\n const warnText = warnings.map((v) => formatViolation(v)).join('\\n');\n lines.push(` <system-out>${escapeXml(warnText)}</system-out>`);\n lines.push(' </testcase>');\n } else {\n lines.push(` <testcase name=\"${escapeXml(entry.ruleId)}\" time=\"${time}\"/>`);\n }\n\n lines.push(' </testsuite>');\n }\n\n lines.push('</testsuites>');\n return lines.join('\\n');\n}\n\n/** Format a violation as a human-readable string */\nfunction formatViolation(v: Violation): string {\n const location = v.location\n ? ` at ${v.location.file}${v.location.line ? `:${v.location.line}` : ''}`\n : '';\n return `${v.message}${location}`;\n}\n\n/** Escape special XML characters */\nfunction escapeXml(str: string): string {\n return str\n .replaceAll('&', '&')\n .replaceAll('<', '<')\n .replaceAll('>', '>')\n .replaceAll('\"', '"')\n .replaceAll(\"'\", ''');\n}\n\n/** Create a JUnit ReporterFactory for use in lodestar config */\nfunction junitReporter(options?: JunitReporterOptions) {\n return {\n name: 'junit',\n create: () => createJunitReporter(options),\n };\n}\n\nexport { createJunitReporter, junitReporter, buildJunitXml, escapeXml };\nexport type { JunitReporterOptions };\n"],"mappings":";AAAA,SAAS,iBAAi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AAS,gBAAgB,GAAsB;AAC7C,QAAM,WAAW,EAAE,WACf,OAAO,EAAE,SAAS,IAAI,GAAG,EAAE,SAAS,OAAO,IAAI,EAAE,SAAS,IAAI,KAAK,EAAE,KACrE;AACJ,SAAO,GAAG,EAAE,OAAO,GAAG,QAAQ;AAChC;AAGA,SAAS,UAAU,KAAqB;AACtC,SAAO,IACJ,WAAW,KAAK,OAAO,EACvB,WAAW,KAAK,MAAM,EACtB,WAAW,KAAK,MAAM,EACtB,WAAW,KAAK,QAAQ,EACxB,WAAW,KAAK,QAAQ;AAC7B;AAGA,SAAS,cAAc,SAAgC;AACrD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,MAAM,oBAAoB,OAAO;AAAA,EAC3C;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@retemper/lodestar-reporter-junit",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "JUnit XML reporter for Lodestar — output violations as JUnit test results for CI integration",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"import": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@retemper/lodestar-types": "0.0.0"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"tsup": "^8.3.0",
|
|
21
|
+
"typescript": "^5.6.0",
|
|
22
|
+
"vitest": "^4.1.0"
|
|
23
|
+
},
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public",
|
|
27
|
+
"provenance": true
|
|
28
|
+
},
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/retemper/lodestar",
|
|
32
|
+
"directory": "packages/reporter-junit"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"dev": "tsup --watch",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"test:watch": "vitest",
|
|
39
|
+
"type-check": "tsc --noEmit",
|
|
40
|
+
"lint": "eslint src/"
|
|
41
|
+
}
|
|
42
|
+
}
|