Skip to content

Commit

Permalink
add ability to group awesome tree by provided label
Browse files Browse the repository at this point in the history
  • Loading branch information
epszaw committed Dec 20, 2024
1 parent ec05a0f commit a698c4e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 14 deletions.
8 changes: 8 additions & 0 deletions packages/cli/src/commands/awesome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type AwesomeCommandOptions = {
singleFile?: boolean;
historyPath?: string;
knownIssues?: string;
groupBy?: string;
};

export const AwesomeCommandAction = async (resultsDir: string, options: AwesomeCommandOptions) => {
Expand Down Expand Up @@ -90,6 +91,13 @@ export const AwesomeCommand = createCommand({
description: "Path to the known issues file. Updates the file and quarantines failed tests when specified",
},
],
[
"--group-by, -g <string>",
{
description: "Group test results by label, e.g. suite, feature, package, story, epic etc.",
default: "suite",
}
]
],
action: AwesomeCommandAction,
});
2 changes: 2 additions & 0 deletions packages/plugin-awesome/src/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ export const generateStaticFiles = async (
singleFile,
logo = "",
theme = "light",
groupBy = "suite",
reportFiles,
reportDataFiles,
reportUuid,
Expand Down Expand Up @@ -276,6 +277,7 @@ export const generateStaticFiles = async (
reportLanguage,
createdAt: Date.now(),
reportUuid,
groupBy,
};
const html = compile({
headTags: headTags.join("\n"),
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-awesome/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type AllureAwesomeOptions = {
logo?: string;
theme?: "light" | "dark";
reportLanguage?: "en" | "ru";
groupBy?: string;
ci?: {
type: "github" | "jenkins";
url: string;
Expand Down
21 changes: 13 additions & 8 deletions packages/plugin-awesome/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class AllureAwesomePlugin implements Plugin {
constructor(readonly options: AllureAwesomePluginOptions = {}) {}

#generate = async (context: PluginContext, store: AllureStore) => {
const { singleFile } = this.options ?? {};
const { singleFile, groupBy = "suite" } = this.options ?? {};
const environmentItems = await store.metadataByKey<EnvironmentItem[]>("allure_environment");
const statistic = await store.testsStatistic();
const allTr = await store.allTestResults({ includeHidden: true });
Expand All @@ -28,14 +28,19 @@ export class AllureAwesomePlugin implements Plugin {
await generateStatistic(this.#writer!, statistic);
await generatePieChart(this.#writer!, statistic);

const noParentSuite = allTr.find((tr) => findByLabelName(tr.labels, "parentSuite")) === undefined;
if (groupBy === "suite") {
const noParentSuite = allTr.find((tr) => findByLabelName(tr.labels, "parentSuite")) === undefined;

await generateTree(
this.#writer!,
"suite",
noParentSuite ? ["suite", "subSuite"] : ["parentSuite", "suite", "subSuite"],
allTr,
);
} else {
await generateTree(this.#writer!, groupBy, [groupBy], allTr);
}

await generateTree(
this.#writer!,
"suites",
noParentSuite ? ["suite", "subSuite"] : ["parentSuite", "suite", "subSuite"],
allTr,
);
await generateTestResults(this.#writer!, store);
await generateHistoryDataPoints(this.#writer!, store);

Expand Down
9 changes: 6 additions & 3 deletions packages/web-awesome/src/components/app/BaseLayout/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { ensureReportDataReady } from "@allurereport/web-commons";
import { ensureReportDataReady, getReportOptions } from "@allurereport/web-commons";
import { useEffect } from "preact/compat";
import { Footer } from "@/components/app/Footer";
import MainReport from "@/components/app/MainReport";
import Modal from "@/components/app/Modal";
import TestResult from "@/components/app/TestResult";
import { Loadable } from "@/components/commons/Loadable";
import { PageLoader } from "@/components/commons/PageLoader";
import { fetchStats, getTheme, getLocale } from "@/stores";
import { fetchStats, getLocale, getTheme } from "@/stores";
import { fetchPieChartData } from "@/stores/chart";
import { fetchEnvInfo } from "@/stores/envInfo";
import { fetchTestResult, fetchTestResultNav, testResultStore } from "@/stores/testResults";
import { fetchTreeData, treeStore } from "@/stores/tree";
import type { AllureAwesomeReportOptions } from "../../../../types";
import * as styles from "./styles.scss";

export const BaseLayout = ({ testResultId }) => {
Expand All @@ -24,11 +25,13 @@ export const BaseLayout = ({ testResultId }) => {
fetchTestResult(testResultId);
fetchTestResultNav();
} else {
const { groupBy = "suite" } = getReportOptions<AllureAwesomeReportOptions>() ?? {};

Promise.all([
ensureReportDataReady(),
fetchStats(),
fetchPieChartData(),
fetchTreeData("suites"),
fetchTreeData(groupBy),
fetchEnvInfo(),
]);
}
Expand Down
3 changes: 0 additions & 3 deletions packages/web-awesome/src/components/app/Tree/Tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import cx from "clsx";
import type { FunctionComponent } from "preact";
import { useState } from "preact/hooks";
import TreeItem from "@/components/app/Tree/TreeItem";
import { Text } from "@/components/commons/Typography";
import { useI18n } from "@/stores";
import type { AllureAwesomeRecursiveTree, AllureAwesomeStatus } from "../../../../types";
import TreeHeader from "./TreeHeader";
import * as styles from "./styles.scss";
Expand All @@ -18,7 +16,6 @@ interface TreeProps {
}

const Tree: FunctionComponent<TreeProps> = ({ tree, statusFilter, root, name, statistic }) => {
const { t } = useI18n("empty");
const [isOpened, setIsOpen] = useState(statistic === undefined || !!statistic.failed || !!statistic.broken);
const toggleTree = () => {
setIsOpen(!isOpened);
Expand Down
1 change: 1 addition & 0 deletions packages/web-awesome/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
theme: "light",
reportLanguage: "ru",
createdAt: 1731513697651,
groupBy: "suite",
};
</script>
<script async>
Expand Down
1 change: 1 addition & 0 deletions packages/web-awesome/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type AllureAwesomeReportOptions = {
reportName?: string;
logo?: string;
theme?: "light" | "dark";
groupBy?: string;
reportLanguage?: "en" | "ru";
createdAt: number;
reportUuid: string;
Expand Down

0 comments on commit a698c4e

Please sign in to comment.