-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathplugin.ts
More file actions
176 lines (149 loc) · 6.22 KB
/
plugin.ts
File metadata and controls
176 lines (149 loc) · 6.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { type EnvironmentItem, type Statistic, getWorstStatus } from "@allurereport/core-api";
import {
type AllureStore,
type Plugin,
type PluginContext,
type PluginSummary,
convertToSummaryTestResult,
} from "@allurereport/plugin-api";
import { preciseTreeLabels } from "@allurereport/plugin-api";
import { join } from "node:path";
import { filterEnv } from "./environments.js";
import { generateTimeline } from "./generateTimeline.js";
import {
generateAllCharts,
generateAttachmentsFiles,
generateEnvironmentJson,
generateEnvirontmentsList,
generateGlobals,
generateHistoryDataPoints,
generateNav,
generateQualityGateResults,
generateStaticFiles,
generateStatistic,
generateTestEnvGroups,
generateTestResults,
generateTree,
generateVariables,
} from "./generators.js";
import type { AwesomePluginOptions } from "./model.js";
import { type AwesomeDataWriter, InMemoryReportDataWriter, ReportFileDataWriter } from "./writer.js";
export class AwesomePlugin implements Plugin {
#writer: AwesomeDataWriter | undefined;
constructor(readonly options: AwesomePluginOptions = {}) {}
#generate = async (context: PluginContext, store: AllureStore) => {
const { singleFile, groupBy = [], filter, appendTitlePath } = this.options ?? {};
const environmentItems = await store.metadataByKey<EnvironmentItem[]>("allure_environment");
const reportEnvironments = await store.allEnvironments();
const attachments = await store.allAttachments();
const allTrs = await store.allTestResults({ includeHidden: true });
const statistics = await store.testsStatistic(filter);
const environments = await store.allEnvironments();
const envStatistics = new Map<string, Statistic>();
const allTestEnvGroups = await store.allTestEnvGroups();
const globalAttachments = await store.allGlobalAttachments();
const globalExitCode = await store.globalExitCode();
const globalErrors = await store.allGlobalErrors();
const qualityGateResults = await store.qualityGateResults();
for (const env of environments) {
envStatistics.set(env, await store.testsStatistic(filterEnv(env, filter)));
}
await generateStatistic(this.#writer!, {
stats: statistics,
statsByEnv: envStatistics,
envs: environments,
});
await generateAllCharts(this.#writer!, store, this.options, context);
await generateTimeline(this.#writer!, store, this.options);
const convertedTrs = await generateTestResults(this.#writer!, store, allTrs, this.options.filter);
const hasGroupBy = groupBy.length > 0;
const treeLabels = hasGroupBy
? preciseTreeLabels(groupBy, convertedTrs, ({ labels }) => labels.map(({ name }) => name))
: [];
await generateHistoryDataPoints(this.#writer!, store);
await generateTree(this.#writer!, "tree.json", treeLabels, convertedTrs, { appendTitlePath });
await generateNav(this.#writer!, convertedTrs, "nav.json");
await generateTestEnvGroups(this.#writer!, allTestEnvGroups);
for (const reportEnvironment of reportEnvironments) {
const envConvertedTrs = convertedTrs.filter(({ environment }) => environment === reportEnvironment);
await generateTree(this.#writer!, join(reportEnvironment, "tree.json"), treeLabels, envConvertedTrs, {
appendTitlePath,
});
await generateNav(this.#writer!, envConvertedTrs, join(reportEnvironment, "nav.json"));
}
await generateEnvirontmentsList(this.#writer!, store);
await generateVariables(this.#writer!, store);
if (environmentItems?.length) {
await generateEnvironmentJson(this.#writer!, environmentItems);
}
if (attachments?.length) {
await generateAttachmentsFiles(this.#writer!, attachments, (id) => store.attachmentContentById(id));
}
await generateQualityGateResults(this.#writer!, qualityGateResults);
await generateGlobals(this.#writer!, {
globalAttachments,
globalErrors,
globalExitCode,
contentFunction: (id) => store.attachmentContentById(id),
});
const reportDataFiles = singleFile ? (this.#writer! as InMemoryReportDataWriter).reportFiles() : [];
await generateStaticFiles({
...this.options,
id: context.id,
allureVersion: context.allureVersion,
reportFiles: context.reportFiles,
reportUuid: context.reportUuid,
reportName: context.reportName,
ci: context.ci,
reportDataFiles,
});
};
start = async (context: PluginContext) => {
const { singleFile } = this.options;
if (singleFile) {
this.#writer = new InMemoryReportDataWriter();
return;
}
this.#writer = new ReportFileDataWriter(context.reportFiles, context.reportStoreFiles);
await Promise.resolve();
};
update = async (context: PluginContext, store: AllureStore) => {
if (!this.#writer) {
throw new Error("call start first");
}
await this.#generate(context, store);
};
done = async (context: PluginContext, store: AllureStore) => {
if (!this.#writer) {
throw new Error("call start first");
}
await this.#generate(context, store);
};
async info(context: PluginContext, store: AllureStore): Promise<PluginSummary> {
const allTrs = (await store.allTestResults()).filter((tr) =>
this.options.filter ? this.options.filter(tr) : true,
);
const newTrs = await store.allNewTestResults();
const retryTrs = allTrs.filter((tr) => !!tr?.retries?.length);
const flakyTrs = allTrs.filter((tr) => !!tr?.flaky);
const duration = allTrs.reduce((acc, { duration: trDuration = 0 }) => acc + trDuration, 0);
const worstStatus = getWorstStatus(allTrs.map(({ status }) => status));
const createdAt = allTrs.reduce((acc, { stop }) => Math.max(acc, stop || 0), 0);
return {
name: this.options.reportName || context.reportName,
stats: await store.testsStatistic(this.options.filter),
status: worstStatus ?? "passed",
duration,
createdAt,
plugin: "Awesome",
newTests: newTrs.map(convertToSummaryTestResult),
flakyTests: flakyTrs.map(convertToSummaryTestResult),
retryTests: retryTrs.map(convertToSummaryTestResult),
meta: {
reportId: context.reportUuid,
singleFile: this.options.singleFile ?? false,
withTestResultsLinks: true,
},
};
}
}