UNPKG

@allurereport/plugin-dashboard

Version:

Allure Dashboard Plugin – plugin for generating dashboard with a mix of charts

77 lines (76 loc) 4.58 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var _DashboardPlugin_writer, _DashboardPlugin_generate; import { getWorstStatus } from "@allurereport/core-api"; import { convertToSummaryTestResult, } from "@allurereport/plugin-api"; import { generateAllCharts, generateEnvirontmentsList, generateStaticFiles } from "./generators.js"; import { InMemoryDashboardDataWriter, ReportFileDashboardDataWriter } from "./writer.js"; export class DashboardPlugin { constructor(options = {}) { this.options = options; _DashboardPlugin_writer.set(this, void 0); _DashboardPlugin_generate.set(this, async (context, store) => { await generateAllCharts(__classPrivateFieldGet(this, _DashboardPlugin_writer, "f"), store, this.options, context); await generateEnvirontmentsList(__classPrivateFieldGet(this, _DashboardPlugin_writer, "f"), store); const reportDataFiles = this.options.singleFile ? __classPrivateFieldGet(this, _DashboardPlugin_writer, "f").reportFiles() : []; await generateStaticFiles({ ...this.options, allureVersion: context.allureVersion, reportFiles: context.reportFiles, reportDataFiles, reportUuid: context.reportUuid, reportName: context.reportName, }); }); this.start = async (context) => { if (this.options.singleFile) { __classPrivateFieldSet(this, _DashboardPlugin_writer, new InMemoryDashboardDataWriter(), "f"); } else { __classPrivateFieldSet(this, _DashboardPlugin_writer, new ReportFileDashboardDataWriter(context.reportFiles), "f"); } }; this.update = async (context, store) => { if (!__classPrivateFieldGet(this, _DashboardPlugin_writer, "f")) { throw new Error("call start first"); } await __classPrivateFieldGet(this, _DashboardPlugin_generate, "f").call(this, context, store); }; this.done = async (context, store) => { if (!__classPrivateFieldGet(this, _DashboardPlugin_writer, "f")) { throw new Error("call start first"); } await __classPrivateFieldGet(this, _DashboardPlugin_generate, "f").call(this, context, store); }; } async info(context, store) { const allTrs = (await store.allTestResults()).filter(this.options.filter ? this.options.filter : () => 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: "Dashboard", newTests: newTrs.map(convertToSummaryTestResult), flakyTests: flakyTrs.map(convertToSummaryTestResult), retryTests: retryTrs.map(convertToSummaryTestResult), }; } } _DashboardPlugin_writer = new WeakMap(), _DashboardPlugin_generate = new WeakMap();