Skip to content

Commit 846994c

Browse files
committed
upd Readme and some fixes
1 parent d6338bc commit 846994c

File tree

4 files changed

+121
-62
lines changed

4 files changed

+121
-62
lines changed

packages/e2e/test/allure-awesome/test/tree.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ test.describe("commons", () => {
3131
history: undefined,
3232
historyPath: undefined,
3333
knownIssuesPath: undefined,
34+
groupBy: ["parentSuite", "suite", "subSuite"],
3435
},
3536
testResults: [
3637
{
@@ -169,6 +170,7 @@ test.describe("SearchBox component with debounce", () => {
169170
history: [],
170171
historyPath: "",
171172
knownIssuesPath: "",
173+
groupBy: ["parentSuite", "suite", "subSuite"],
172174
},
173175
testResults: [
174176
{
@@ -218,6 +220,7 @@ test.describe("suites", () => {
218220
history: undefined,
219221
historyPath: undefined,
220222
knownIssuesPath: undefined,
223+
groupBy: ["parentSuite", "suite", "subSuite"],
221224
},
222225
testResults: [
223226
{
@@ -285,6 +288,7 @@ test.describe("suites", () => {
285288
history: undefined,
286289
historyPath: undefined,
287290
knownIssuesPath: undefined,
291+
groupBy: ["parentSuite", "suite", "subSuite"],
288292
},
289293
testResults: [
290294
{
@@ -348,6 +352,7 @@ test.describe("suites", () => {
348352
defaultLabels: {
349353
parentSuite: "Assign me please!",
350354
},
355+
groupBy: ["parentSuite", "suite", "subSuite"],
351356
},
352357
testResults: [
353358
{
@@ -415,6 +420,7 @@ test.describe("features", () => {
415420
history: undefined,
416421
historyPath: undefined,
417422
knownIssuesPath: undefined,
423+
groupBy: ["parentSuite", "suite", "subSuite"],
418424
},
419425
testResults: [
420426
{
@@ -466,6 +472,7 @@ test.describe("stories", () => {
466472
history: undefined,
467473
historyPath: undefined,
468474
knownIssuesPath: undefined,
475+
groupBy: ["parentSuite", "suite", "subSuite"],
469476
},
470477
testResults: [
471478
{

packages/plugin-awesome/README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ export default defineConfig({
4747

4848
The plugin accepts the following options:
4949

50-
| Option | Description | Type | Default |
51-
|------------------|-------------------------------------------------|--------------------------------------------------------------|-----------------|
52-
| `reportName` | Name of the report | `string` | `Allure Report` |
53-
| `singleFile` | Writes the report as a single `index.html` file | `boolean` | `false` |
54-
| `logo` | Path to the logo image | `string` | `null` |
55-
| `theme` | Default color theme of the report | `light \| dark` | OS theme |
56-
| `reportLanguage` | Default language of the report | `string` | OS language |
57-
| `ci` | CI data which will be rendered in the report | `{ type: "github" \| "jenkins", url: string, name: string }` | `undefined` |
50+
| Option | Description | Type | Default |
51+
|------------------|-------------------------------------------------|---------|-------------------------|
52+
| `reportName` | Name of the report | `string` | `Allure Report` |
53+
| `singleFile` | Writes the report as a single `index.html` file | `boolean` | `false` |
54+
| `logo` | Path to the logo image | `string` | `null` |
55+
| `theme` | Default color theme of the report | `light \| dark` | OS theme |
56+
| `reportLanguage` | Default language of the report | `string` | OS language |
57+
| `ci` | CI data which will be rendered in the report | `{ type: "github" \| "jenkins", url: string, name: string }` | `undefined` |
58+
| `groupBy` | By default, tests are grouped using the `titlePath` provided by the test framework. | `string`| Grouping by `titlepath` |

packages/plugin-awesome/src/generators.ts

Lines changed: 95 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
type AttachmentLink,
33
type EnvironmentItem,
4+
type TreeData,
45
compareBy,
56
incrementStatistic,
67
nullsLast,
@@ -11,10 +12,13 @@ import {
1112
type ReportFiles,
1213
type ResultFile,
1314
type TestResultFilter,
15+
createTreeByLabels,
1416
createTreeByTitlePath,
1517
filterTree,
18+
preciseTreeLabels,
19+
sortTree,
20+
transformTree,
1621
} from "@allurereport/plugin-api";
17-
import { createTreeByLabels, sortTree, transformTree } from "@allurereport/plugin-api";
1822
import type {
1923
AwesomeFixtureResult,
2024
AwesomeReportOptions,
@@ -184,69 +188,111 @@ export const generateTree = async (
184188
tests: AwesomeTestResult[],
185189
) => {
186190
const visibleTests = tests.filter((test) => !test.hidden);
187-
const testsWithoutTitlePath = visibleTests.filter((test) => !test.titlePath?.length);
188-
const testsWithTitlePath = visibleTests.filter((test) => test.titlePath?.length);
189-
const treeByLabels = createTreeByLabels<AwesomeTestResult, AwesomeTreeLeaf, AwesomeTreeGroup>(
190-
testsWithoutTitlePath,
191+
192+
const tree: TreeData<AwesomeTreeLeaf, AwesomeTreeGroup> = labels.length
193+
? buildTreeByLabels(visibleTests, labels)
194+
: buildTreeByTitlePath(visibleTests);
195+
196+
// @ts-ignore
197+
filterTree(tree, (leaf) => !leaf.hidden);
198+
sortTree(tree, nullsLast(compareBy("start", ordinal())));
199+
transformTree(tree, (leaf, idx) => ({ ...leaf, groupOrder: idx + 1 }));
200+
201+
await writer.writeWidget(treeFilename, tree);
202+
};
203+
204+
const buildTreeByLabels = (
205+
tests: AwesomeTestResult[],
206+
labels: string[],
207+
): TreeData<AwesomeTreeLeaf, AwesomeTreeGroup> => {
208+
console.log("buildTreeByLabels");
209+
return createTreeByLabels<AwesomeTestResult, AwesomeTreeLeaf, AwesomeTreeGroup>(
210+
tests,
191211
labels,
192-
({ id, name, status, duration, flaky, transition, start, retry, retriesCount }) => ({
193-
nodeId: id,
194-
retry,
195-
retriesCount,
196-
name,
197-
status,
198-
start,
199-
duration,
200-
flaky,
201-
transition,
202-
}),
212+
leafFactory,
203213
undefined,
204-
(group, leaf) => {
205-
incrementStatistic(group.statistic, leaf.status);
206-
},
214+
(group, leaf) => incrementStatistic(group.statistic, leaf.status),
207215
);
216+
};
217+
218+
const buildTreeByTitlePath = (tests: AwesomeTestResult[]): TreeData<AwesomeTreeLeaf, AwesomeTreeGroup> => {
219+
console.log("buildTreeByTitlePath");
220+
const testsWithTitlePath: AwesomeTestResult[] = [];
221+
const testsWithoutTitlePath: AwesomeTestResult[] = [];
208222

209-
const tree = createTreeByTitlePath<AwesomeTestResult>(
223+
for (const test of tests) {
224+
if (Array.isArray(test.titlePath) && test.titlePath.length > 0) {
225+
testsWithTitlePath.push(test);
226+
} else {
227+
testsWithoutTitlePath.push(test);
228+
}
229+
}
230+
231+
const treeByTitlePath = createTreeByTitlePath<AwesomeTestResult>(
210232
testsWithTitlePath,
211-
({ id, name, status, duration, flaky, start, retries, transition }) => ({
212-
nodeId: id,
213-
name,
214-
status,
215-
duration,
216-
flaky,
217-
start,
218-
retry: !!retries?.length,
219-
retriesCount: retries?.length || 0,
220-
transition,
221-
}),
233+
leafFactory,
222234
undefined,
223-
(group, leaf) => {
224-
incrementStatistic(group.statistic, leaf.status);
225-
},
235+
(group, leaf) => incrementStatistic(group.statistic, leaf.status),
226236
);
227237

228-
const mergedLeavesById = { ...tree.leavesById, ...treeByLabels.leavesById };
229-
const mergedGroupsById = { ...tree.groupsById, ...treeByLabels.groupsById };
230-
const uniqueLeafIds = Array.from(new Set([...(tree.root.leaves ?? []), ...(treeByLabels.root.leaves ?? [])]));
231-
const uniqueGroupIds = Array.from(new Set([...(tree.root.groups ?? []), ...(treeByLabels.root.groups ?? [])]));
238+
const defaultLabels = preciseTreeLabels(["parentSuite", "suite", "subSuite"], testsWithoutTitlePath, ({ labels }) =>
239+
labels.map(({ name }) => name),
240+
);
241+
// fallback if integrations return empty titlePath
242+
const treeByDefaultLabels = createTreeByLabels<AwesomeTestResult, AwesomeTreeLeaf, AwesomeTreeGroup>(
243+
testsWithoutTitlePath,
244+
defaultLabels,
245+
leafFactory,
246+
undefined,
247+
(group, leaf) => incrementStatistic(group.statistic, leaf.status),
248+
);
232249

233-
const mergedTree = {
250+
const mergedLeavesById = { ...treeByTitlePath.leavesById, ...treeByDefaultLabels.leavesById } as Record<
251+
string,
252+
AwesomeTreeLeaf
253+
>;
254+
const mergedGroupsById = { ...treeByTitlePath.groupsById, ...treeByDefaultLabels.groupsById };
255+
256+
const mergedRootLeaves = Array.from(
257+
new Set([...(treeByTitlePath.root.leaves ?? []), ...(treeByDefaultLabels.root.leaves ?? [])]),
258+
);
259+
260+
const mergedRootGroups = Array.from(
261+
new Set([...(treeByTitlePath.root.groups ?? []), ...(treeByDefaultLabels.root.groups ?? [])]),
262+
);
263+
264+
return {
234265
root: {
235-
groups: uniqueGroupIds,
236-
leaves: uniqueLeafIds,
266+
leaves: mergedRootLeaves,
267+
groups: mergedRootGroups,
237268
},
238-
groupsById: mergedGroupsById,
239269
leavesById: mergedLeavesById,
270+
groupsById: mergedGroupsById,
240271
};
241-
242-
// @ts-ignore
243-
filterTree(mergedTree, (leaf) => !leaf.hidden);
244-
sortTree(mergedTree, nullsLast(compareBy("start", ordinal())));
245-
transformTree(mergedTree, (leaf, idx) => ({ ...leaf, groupOrder: idx + 1 }));
246-
247-
await writer.writeWidget(treeFilename, mergedTree);
248272
};
249273

274+
const leafFactory = ({
275+
id,
276+
name,
277+
status,
278+
duration,
279+
flaky,
280+
start,
281+
transition,
282+
retry,
283+
retriesCount,
284+
}: AwesomeTestResult): AwesomeTreeLeaf => ({
285+
nodeId: id,
286+
name,
287+
status,
288+
duration,
289+
flaky,
290+
start,
291+
retry,
292+
retriesCount,
293+
transition,
294+
});
295+
250296
export const generateEnvironmentJson = async (writer: AwesomeDataWriter, env: EnvironmentItem[]) => {
251297
await writer.writeWidget("allure_environment.json", env);
252298
};

packages/plugin-awesome/src/plugin.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,16 @@ export class AwesomePlugin implements Plugin {
3737
await generateAllCharts(this.#writer!, store, this.options, context);
3838

3939
const convertedTrs = await generateTestResults(this.#writer!, store, this.options.filter);
40-
const treeLabels = preciseTreeLabels(
41-
!groupBy.length ? ["parentSuite", "suite", "subSuite"] : groupBy,
42-
convertedTrs,
43-
({ labels }) => labels.map(({ name }) => name),
44-
);
40+
const hasGroupBy = groupBy.length > 0;
41+
42+
const treeLabels = hasGroupBy
43+
? preciseTreeLabels(groupBy, convertedTrs, ({ labels }) => labels.map(({ name }) => name))
44+
: [];
45+
// const treeLabels = preciseTreeLabels(
46+
// !groupBy.length ? ["parentSuite", "suite", "subSuite"] : groupBy,
47+
// convertedTrs,
48+
// ({ labels }) => labels.map(({ name }) => name),
49+
// );
4550

4651
await generateHistoryDataPoints(this.#writer!, store);
4752
await generateTestCases(this.#writer!, convertedTrs);

0 commit comments

Comments
 (0)