@flakiness/junit-xml 1.0.0 → 1.2.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/README.md +2 -0
- package/lib/cli.js +2 -1
- package/lib/parser.js +13 -5
- package/package.json +3 -3
- package/types/src/parser.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
[](https://flakiness.io/flakiness/junit-xml)
|
|
2
|
+
|
|
1
3
|
# @flakiness/junit-xml
|
|
2
4
|
|
|
3
5
|
Convert JUnit XML test reports into a Flakiness report and upload it to [flakiness.io](https://flakiness.io).
|
package/lib/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import { CIUtils, GitWorktree, ReportUtils, uploadReport, writeReport } from "@f
|
|
|
3
3
|
import { Command, Option } from "commander";
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
import path from "node:path";
|
|
6
|
+
import pkg from "../package.json" with { type: "json" };
|
|
6
7
|
import { parseJUnit } from "./parser.js";
|
|
7
8
|
const STDERR_LOGGER = {
|
|
8
9
|
log: (...args) => console.error(...args),
|
|
@@ -12,7 +13,7 @@ const STDERR_LOGGER = {
|
|
|
12
13
|
function envBool(name) {
|
|
13
14
|
return ["1", "true"].includes(process.env[name]?.toLowerCase() ?? "");
|
|
14
15
|
}
|
|
15
|
-
const program = new Command("flakiness-junit-xml").description("Convert JUnit XML report(s) to a Flakiness report and upload it to flakiness.io").argument("<junit-path>", "Path to a JUnit XML file or a directory containing XML files").option("-c, --category <category>", "Report category identifier (e.g. `bun`, `rust`). Defaults to `junit`.").option("--env-name <name>", "Environment name for the report (defaults to --category, or `junit` if neither is set)").option("--commit-id <id>", "Git commit ID (auto-detected from the current working directory if not provided)").addOption(new Option("--title <title>", "Human-readable report title").env("FLAKINESS_TITLE")).option("--output-dir <dir>", "Output directory for the report", "flakiness-report").addOption(new Option("--flakiness-project <project>", "Flakiness project identifier in `org/project` format").env("FLAKINESS_PROJECT")).addOption(new Option("-p, --project <org/project>").hideHelp()).addOption(new Option("--token <token>", "Flakiness.io access token for upload").env("FLAKINESS_ACCESS_TOKEN")).option("--endpoint <url>", "Flakiness.io API endpoint override").addOption(new Option("--disable-upload", "Convert only; do not upload to flakiness.io").env("FLAKINESS_DISABLE_UPLOAD")).action(async (junitPath, options) => {
|
|
16
|
+
const program = new Command("flakiness-junit-xml").description("Convert JUnit XML report(s) to a Flakiness report and upload it to flakiness.io").version(pkg.version, "-v, --version", "Output the version number").argument("<junit-path>", "Path to a JUnit XML file or a directory containing XML files").option("-c, --category <category>", "Report category identifier (e.g. `bun`, `rust`). Defaults to `junit`.").option("--env-name <name>", "Environment name for the report (defaults to --category, or `junit` if neither is set)").option("--commit-id <id>", "Git commit ID (auto-detected from the current working directory if not provided)").addOption(new Option("--title <title>", "Human-readable report title").env("FLAKINESS_TITLE")).option("--output-dir <dir>", "Output directory for the report", "flakiness-report").addOption(new Option("--flakiness-project <project>", "Flakiness project identifier in `org/project` format").env("FLAKINESS_PROJECT")).addOption(new Option("-p, --project <org/project>").hideHelp()).addOption(new Option("--token <token>", "Flakiness.io access token for upload").env("FLAKINESS_ACCESS_TOKEN")).option("--endpoint <url>", "Flakiness.io API endpoint override").addOption(new Option("--disable-upload", "Convert only; do not upload to flakiness.io").env("FLAKINESS_DISABLE_UPLOAD")).action(async (junitPath, options) => {
|
|
16
17
|
await runConvert(junitPath, {
|
|
17
18
|
envName: options.envName ?? options.category ?? "junit",
|
|
18
19
|
outputDir: options.outputDir,
|
package/lib/parser.js
CHANGED
|
@@ -6,6 +6,10 @@ import fs from "fs";
|
|
|
6
6
|
import mime from "mime";
|
|
7
7
|
import path from "path";
|
|
8
8
|
import { Temporal } from "temporal-polyfill";
|
|
9
|
+
import pkg from "../package.json" with { type: "json" };
|
|
10
|
+
function toGitFilePath(file) {
|
|
11
|
+
return file.split("\\").join("/");
|
|
12
|
+
}
|
|
9
13
|
let gTZAbbreviationToIANATimezone;
|
|
10
14
|
function tzAbbreviationToIANA(tz) {
|
|
11
15
|
if (!gTZAbbreviationToIANATimezone) {
|
|
@@ -103,14 +107,17 @@ async function traverseJUnitReport(context, node) {
|
|
|
103
107
|
const file = element.attributes["file"];
|
|
104
108
|
const line = parseInt(element.attributes["line"], 10);
|
|
105
109
|
const name = element.attributes["name"];
|
|
110
|
+
const isTopSuiteAFileSuite = !currentSuite && !!name && name === file;
|
|
111
|
+
const isFileSuite = isTopSuiteAFileSuite || !name && file;
|
|
112
|
+
const filePath = file ? toGitFilePath(file) : void 0;
|
|
106
113
|
const newSuite = {
|
|
107
|
-
title:
|
|
108
|
-
location:
|
|
109
|
-
file,
|
|
114
|
+
title: isFileSuite && filePath ? filePath : name,
|
|
115
|
+
location: filePath && !isNaN(line) ? {
|
|
116
|
+
file: filePath,
|
|
110
117
|
line,
|
|
111
118
|
column: 1
|
|
112
119
|
} : void 0,
|
|
113
|
-
type:
|
|
120
|
+
type: isFileSuite ? "file" : name ? "suite" : "anonymous suite",
|
|
114
121
|
suites: [],
|
|
115
122
|
tests: []
|
|
116
123
|
};
|
|
@@ -158,7 +165,7 @@ async function traverseJUnitReport(context, node) {
|
|
|
158
165
|
const test = {
|
|
159
166
|
title: name,
|
|
160
167
|
location: file && !isNaN(line) ? {
|
|
161
|
-
file,
|
|
168
|
+
file: toGitFilePath(file),
|
|
162
169
|
line,
|
|
163
170
|
column: 1
|
|
164
171
|
} : void 0,
|
|
@@ -206,6 +213,7 @@ async function parseJUnit(xmls, options) {
|
|
|
206
213
|
const report = {
|
|
207
214
|
category: options.category ?? "junit",
|
|
208
215
|
commitId: options.commitId,
|
|
216
|
+
generatedBy: { name: pkg.name, version: pkg.version },
|
|
209
217
|
duration: options.runDuration,
|
|
210
218
|
startTimestamp: options.runStartTimestamp,
|
|
211
219
|
url: options.runUrl,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flakiness/junit-xml",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"temporal-polyfill": "^0.3.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@
|
|
37
|
+
"@types/bun": "^1.3.14",
|
|
38
38
|
"@types/node": "^25.0.3",
|
|
39
39
|
"esbuild": "^0.27.2",
|
|
40
40
|
"kubik": "^0.24.0",
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
"scripts": {
|
|
45
45
|
"build": "kubik build.mts",
|
|
46
46
|
"watch": "kubik build.mts -w",
|
|
47
|
-
"test": "
|
|
47
|
+
"test": "bun test tests/ --reporter=junit --reporter-outfile=junit.xml"
|
|
48
48
|
}
|
|
49
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,eAAe,IAAI,EAAE,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/parser.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,eAAe,IAAI,EAAE,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AA6Q7C,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE;IACxD,UAAU,EAAE,EAAE,CAAC,WAAW,CAAC;IAC3B,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC;IACtB,WAAW,EAAE,EAAE,CAAC,UAAU,CAAC;IAC3B,iBAAiB,EAAE,EAAE,CAAC,eAAe,CAAC;IACtC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC;IAAC,WAAW,EAAE,WAAW,CAAC,UAAU,EAAE,CAAA;CAAE,CAAC,CAgCxE"}
|