UNPKG

@allurereport/plugin-dashboard

Version:

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

44 lines (43 loc) 2.02 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 _InMemoryDashboardDataWriter_data; import { mkdir, writeFile } from "node:fs/promises"; import { resolve } from "node:path"; import { join as joinPosix } from "node:path/posix"; export class FileSystemReportDataWriter { constructor(output) { this.output = output; } async writeWidget(fileName, data) { const distFolder = resolve(this.output, "widgets"); await mkdir(distFolder, { recursive: true }); await writeFile(resolve(distFolder, fileName), JSON.stringify(data), { encoding: "utf-8" }); } } export class InMemoryDashboardDataWriter { constructor() { _InMemoryDashboardDataWriter_data.set(this, {}); } async writeWidget(fileName, data) { const dist = joinPosix("widgets", fileName); __classPrivateFieldGet(this, _InMemoryDashboardDataWriter_data, "f")[dist] = Buffer.from(JSON.stringify(data), "utf-8"); } reportFiles() { return Object.keys(__classPrivateFieldGet(this, _InMemoryDashboardDataWriter_data, "f")).map((key) => ({ name: key, value: __classPrivateFieldGet(this, _InMemoryDashboardDataWriter_data, "f")[key].toString("base64"), })); } } _InMemoryDashboardDataWriter_data = new WeakMap(); export class ReportFileDashboardDataWriter { constructor(reportFiles) { this.reportFiles = reportFiles; } async writeWidget(fileName, data) { await this.reportFiles.addFile(joinPosix("widgets", fileName), Buffer.from(JSON.stringify(data), "utf-8")); } }