remove the dependency patch when the JUnit root-layout fix is released:

Open Beginner friendly
#694 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
73/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
github-actions, javascript, node.js
Domain
ci-cd, testing

Research direction

Start with actions/quality/prepare-ci-reports/src/TestReports.js and inspect the junit-to-ctrf dependency and the linked root-layout fix, pull request 93. Check whether that fix has been released and how the dependency patch is applied; remove the patch once the release is available. Confirm the converter still handles JUnit reports and produces a valid, nonempty CTRF report.

Written by the indexing model from the issue text.

Description

bug need-fix

https://github\.com/ctrf\-io/junit\-to\-ctrf/pull/93

https://github.com/hoverkraft-tech/ci-github-common/blob/3d85e6252a0c3c45c34d6f5d50db140944f61b85/actions/quality/prepare-ci-reports/src/TestReports.js#L4-L5


import fs from "node:fs";
import { validate } from "ctrf";
import { XMLValidator } from "fast-xml-parser";
// FIXME: remove the dependency patch when the JUnit root-layout fix is released:
// https://github.com/ctrf-io/junit-to-ctrf/pull/93
import { convertJUnitToCTRFReport } from "junit-to-ctrf";
import { JestReport } from "./JestReport.js";
import { SourcePaths } from "./SourcePaths.js";

/** Adapt native runner output to the maintained CTRF converters and schema. */
export class TestReports {
	constructor(options) {
		this.options = options;
	}

	async convert(file, target) {
		const options = { ...this.options, output: `${target}.json` };
		const content = fs.readFileSync(file, "utf8");
		let report;
		if (content.trimStart().startsWith("<")) {
			if (
				/<!ENTITY|<!DOCTYPE/i.test(content) ||
				XMLValidator.validate(content) !== true
			)
				throw new Error("Invalid or unsafe JUnit XML.");
			report = await convertJUnitToCTRFReport(file, {
				toolName: options.name,
				log: false,
			});
		} else {
			const value = JSON.parse(content);
			report = value.results
				? value
				: await new JestReport(options).convert(value);
		}
		const result = validate(report);
		if (!result.valid || !report?.results?.tests?.length)
			throw new Error(
				`Expected a nonempty valid test report: ${JSON.stringify(result.errors)}`,
			);
		for (const test of report.results.tests) {
			const source = new SourcePaths(options).resolve(test.filePath);
			if (source) test.filePath = source;
			else delete test.filePath;
		}
		report.results.environment = {
			...report.results.environment,
			appName: options.project,
			buildName: options.name,
		};
		report.results.extra = {
			...report.results.extra,
			variant: options.variant,
		};
		fs.writeFileSync(options.output, JSON.stringify(report));
		return { file: options.output, summary: report.results.summary };
	}
}

Dominant language
JavaScript
Stars
5
Forks
1
Avg merge
5h 25m
Merged PRs (30d)
60

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from hoverkraft-tech/ci-github-common

All issues in hoverkraft-tech/ci-github-common

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.