@allurereport/core 3.8.2 → 3.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ import { blue, bold, cyan } from "yoctocolors";
2
+ const noopUploadProgressBar = {
3
+ tick: () => { },
4
+ terminate: () => { },
5
+ };
6
+ const isSilentLogLevel = () => {
7
+ const level = process.env.LOG_LEVEL ?? process.env.ALLURE_LOG_LEVEL;
8
+ return level === "silent";
9
+ };
10
+ export const createUploadProgressBarCounter = (message, total) => {
11
+ if (isSilentLogLevel() || total === 0 || !process.stderr.isTTY) {
12
+ return noopUploadProgressBar;
13
+ }
14
+ const width = 20;
15
+ const prefix = cyan(bold("[AllureReport]:"));
16
+ let current = 0;
17
+ let terminated = false;
18
+ const render = () => {
19
+ const ratio = total === 0 ? 1 : current / total;
20
+ const complete = Math.min(width, Math.round(ratio * width));
21
+ const bar = `${"=".repeat(complete)}${"-".repeat(width - complete)}`;
22
+ process.stderr.write(`\r${prefix} ${blue(message)} [${bar}] ${current}/${total}`);
23
+ };
24
+ render();
25
+ return {
26
+ tick: () => {
27
+ if (terminated) {
28
+ return;
29
+ }
30
+ current = Math.min(current + 1, total);
31
+ render();
32
+ },
33
+ terminate: () => {
34
+ if (terminated) {
35
+ return;
36
+ }
37
+ terminated = true;
38
+ process.stderr.write("\n");
39
+ },
40
+ };
41
+ };
@@ -1 +1,2 @@
1
1
  export declare const shortHash: () => string;
2
+ export declare const md5: (data: string) => string;
@@ -1,2 +1,3 @@
1
- import { randomBytes } from "node:crypto";
1
+ import { randomBytes, createHash } from "node:crypto";
2
2
  export const shortHash = () => randomBytes(8).toString("hex");
3
+ export const md5 = (data) => createHash("md5").update(data).digest("hex");
@@ -0,0 +1,42 @@
1
+ export declare const PERF_METRICS_FILE = "allure-perf-metrics.json";
2
+ export type PerfMetricSpan = {
3
+ name: string;
4
+ startTimeMs: number;
5
+ durationMs: number;
6
+ };
7
+ export type PerfMetricSummary = {
8
+ name: string;
9
+ count: number;
10
+ totalMs: number;
11
+ minMs: number;
12
+ maxMs: number;
13
+ avgMs: number;
14
+ };
15
+ export type PerfMetricsPayload = {
16
+ version: 1;
17
+ generatedAt: string;
18
+ timeOriginMs: number;
19
+ spans: PerfMetricSpan[];
20
+ summary: PerfMetricSummary[];
21
+ };
22
+ export declare const PERF_METRIC_NAMES: {
23
+ readonly restoreStateTotal: "restoreState.total";
24
+ readonly restoreStateDump: "restoreState.dump";
25
+ readonly restoreStateAttachments: "restoreState.attachments";
26
+ readonly restoreStateStoreRestore: "restoreState.storeRestore";
27
+ readonly generateTotal: "generate.total";
28
+ readonly generateReadResults: "generate.readResults";
29
+ readonly generatePluginsDone: "generate.plugins.done";
30
+ readonly publishUploadTotal: "publish.upload.total";
31
+ readonly summaryGenerate: "summary.generate";
32
+ };
33
+ export declare const PERF_METRIC_PREFIXES: {
34
+ readonly generatePluginDone: "generate.plugin.done.";
35
+ readonly publishUploadPlugin: "publish.upload.plugin.";
36
+ };
37
+ export declare const isPerfMetricsEnabled: () => boolean;
38
+ export declare const startPerfSpan: (name: string) => (() => void);
39
+ export declare const measurePerf: <T>(name: string, fn: () => Promise<T>) => Promise<T>;
40
+ export declare const getPerfMetricsPayload: () => PerfMetricsPayload;
41
+ export declare const writePerfMetrics: (output: string) => Promise<boolean>;
42
+ export declare const resetPerfMetrics: () => void;
@@ -0,0 +1,122 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { performance } from "node:perf_hooks";
4
+ export const PERF_METRICS_FILE = "allure-perf-metrics.json";
5
+ const MARK_PREFIX = "allure:perf:";
6
+ const ENABLED_VALUES = new Set(["1", "true", "yes", "on"]);
7
+ const SPANS = [];
8
+ const MARKS = new Set();
9
+ const MEASURES = new Set();
10
+ let sequence = 0;
11
+ const round = (value) => Number(value.toFixed(3));
12
+ export const PERF_METRIC_NAMES = {
13
+ restoreStateTotal: "restoreState.total",
14
+ restoreStateDump: "restoreState.dump",
15
+ restoreStateAttachments: "restoreState.attachments",
16
+ restoreStateStoreRestore: "restoreState.storeRestore",
17
+ generateTotal: "generate.total",
18
+ generateReadResults: "generate.readResults",
19
+ generatePluginsDone: "generate.plugins.done",
20
+ publishUploadTotal: "publish.upload.total",
21
+ summaryGenerate: "summary.generate",
22
+ };
23
+ export const PERF_METRIC_PREFIXES = {
24
+ generatePluginDone: "generate.plugin.done.",
25
+ publishUploadPlugin: "publish.upload.plugin.",
26
+ };
27
+ export const isPerfMetricsEnabled = () => ENABLED_VALUES.has((process.env.ALLURE_PERF_METRICS ?? "").toLowerCase());
28
+ export const startPerfSpan = (name) => {
29
+ if (!isPerfMetricsEnabled()) {
30
+ return () => { };
31
+ }
32
+ const id = `${MARK_PREFIX}${sequence++}:${name}`;
33
+ const startMark = `${id}:start`;
34
+ const endMark = `${id}:end`;
35
+ let ended = false;
36
+ MARKS.add(startMark);
37
+ MARKS.add(endMark);
38
+ MEASURES.add(id);
39
+ performance.mark(startMark);
40
+ return () => {
41
+ if (ended) {
42
+ return;
43
+ }
44
+ ended = true;
45
+ performance.mark(endMark);
46
+ performance.measure(id, startMark, endMark);
47
+ const entry = performance.getEntriesByName(id, "measure").at(-1);
48
+ if (entry) {
49
+ SPANS.push({
50
+ name,
51
+ startTimeMs: round(entry.startTime),
52
+ durationMs: round(entry.duration),
53
+ });
54
+ }
55
+ performance.clearMarks(startMark);
56
+ performance.clearMarks(endMark);
57
+ performance.clearMeasures(id);
58
+ MARKS.delete(startMark);
59
+ MARKS.delete(endMark);
60
+ MEASURES.delete(id);
61
+ };
62
+ };
63
+ export const measurePerf = async (name, fn) => {
64
+ if (!isPerfMetricsEnabled()) {
65
+ return fn();
66
+ }
67
+ const end = startPerfSpan(name);
68
+ try {
69
+ return await fn();
70
+ }
71
+ finally {
72
+ end();
73
+ }
74
+ };
75
+ export const getPerfMetricsPayload = () => {
76
+ const byName = new Map();
77
+ for (const span of SPANS) {
78
+ const current = byName.get(span.name) ?? [];
79
+ current.push(span);
80
+ byName.set(span.name, current);
81
+ }
82
+ return {
83
+ version: 1,
84
+ generatedAt: new Date().toISOString(),
85
+ timeOriginMs: round(performance.timeOrigin),
86
+ spans: [...SPANS],
87
+ summary: [...byName.entries()].map(([name, group]) => {
88
+ const durations = group.map(({ durationMs }) => durationMs);
89
+ const totalMs = durations.reduce((acc, duration) => acc + duration, 0);
90
+ return {
91
+ name,
92
+ count: group.length,
93
+ totalMs: round(totalMs),
94
+ minMs: round(Math.min(...durations)),
95
+ maxMs: round(Math.max(...durations)),
96
+ avgMs: round(totalMs / group.length),
97
+ };
98
+ }),
99
+ };
100
+ };
101
+ export const writePerfMetrics = async (output) => {
102
+ if (!isPerfMetricsEnabled()) {
103
+ return false;
104
+ }
105
+ const payload = getPerfMetricsPayload();
106
+ await mkdir(output, { recursive: true });
107
+ await writeFile(join(output, PERF_METRICS_FILE), `${JSON.stringify(payload, null, 2)}\n`, "utf8");
108
+ resetPerfMetrics();
109
+ return true;
110
+ };
111
+ export const resetPerfMetrics = () => {
112
+ SPANS.length = 0;
113
+ sequence = 0;
114
+ for (const mark of MARKS) {
115
+ performance.clearMarks(mark);
116
+ }
117
+ for (const measure of MEASURES) {
118
+ performance.clearMeasures(measure);
119
+ }
120
+ MARKS.clear();
121
+ MEASURES.clear();
122
+ };
@@ -28,7 +28,12 @@ export class RealtimeUpdateScheduler {
28
28
  await setTimeout(__classPrivateFieldGet(this, _RealtimeUpdateScheduler_cooldownMs, "f"));
29
29
  __classPrivateFieldSet(this, _RealtimeUpdateScheduler_phase, "running", "f");
30
30
  __classPrivateFieldSet(this, _RealtimeUpdateScheduler_dirty, false, "f");
31
+ const start = Date.now();
31
32
  await __classPrivateFieldGet(this, _RealtimeUpdateScheduler_worker, "f").call(this);
33
+ const elapsed = Date.now() - start;
34
+ if (__classPrivateFieldGet(this, _RealtimeUpdateScheduler_dirty, "f") && elapsed > __classPrivateFieldGet(this, _RealtimeUpdateScheduler_cooldownMs, "f")) {
35
+ await setTimeout(elapsed - __classPrivateFieldGet(this, _RealtimeUpdateScheduler_cooldownMs, "f"));
36
+ }
32
37
  } while (__classPrivateFieldGet(this, _RealtimeUpdateScheduler_dirty, "f"));
33
38
  });
34
39
  __classPrivateFieldSet(this, _RealtimeUpdateScheduler_worker, worker, "f");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allurereport/core",
3
- "version": "3.8.2",
3
+ "version": "3.10.0",
4
4
  "description": "Collection of generic Allure utilities used across the entire project",
5
5
  "keywords": [
6
6
  "allure"
@@ -25,45 +25,43 @@
25
25
  "lint:fix": "oxlint --import-plugin --fix src test features stories"
26
26
  },
27
27
  "dependencies": {
28
- "@allurereport/ci": "3.8.2",
29
- "@allurereport/core-api": "3.8.2",
30
- "@allurereport/plugin-agent": "3.8.2",
31
- "@allurereport/plugin-allure2": "3.8.2",
32
- "@allurereport/plugin-api": "3.8.2",
33
- "@allurereport/plugin-awesome": "3.8.2",
34
- "@allurereport/plugin-classic": "3.8.2",
35
- "@allurereport/plugin-csv": "3.8.2",
36
- "@allurereport/plugin-dashboard": "3.8.2",
37
- "@allurereport/plugin-jira": "3.8.2",
38
- "@allurereport/plugin-log": "3.8.2",
39
- "@allurereport/plugin-progress": "3.8.2",
40
- "@allurereport/plugin-slack": "3.8.2",
41
- "@allurereport/plugin-testops": "3.8.2",
42
- "@allurereport/plugin-testplan": "3.8.2",
43
- "@allurereport/reader": "3.8.2",
44
- "@allurereport/reader-api": "3.8.2",
45
- "@allurereport/service": "3.8.2",
46
- "@allurereport/summary": "3.8.2",
28
+ "@allurereport/ci": "3.10.0",
29
+ "@allurereport/core-api": "3.10.0",
30
+ "@allurereport/plugin-agent": "3.10.0",
31
+ "@allurereport/plugin-allure2": "3.10.0",
32
+ "@allurereport/plugin-api": "3.10.0",
33
+ "@allurereport/plugin-awesome": "3.10.0",
34
+ "@allurereport/plugin-classic": "3.10.0",
35
+ "@allurereport/plugin-csv": "3.10.0",
36
+ "@allurereport/plugin-dashboard": "3.10.0",
37
+ "@allurereport/plugin-jira": "3.10.0",
38
+ "@allurereport/plugin-log": "3.10.0",
39
+ "@allurereport/plugin-progress": "3.10.0",
40
+ "@allurereport/plugin-slack": "3.10.0",
41
+ "@allurereport/plugin-testops": "3.10.0",
42
+ "@allurereport/plugin-testplan": "3.10.0",
43
+ "@allurereport/reader": "3.10.0",
44
+ "@allurereport/reader-api": "3.10.0",
45
+ "@allurereport/service": "3.10.0",
46
+ "@allurereport/summary": "3.10.0",
47
47
  "glob": "^13.0.6",
48
48
  "handlebars": "^4.7.9",
49
49
  "node-stream-zip": "^1.15.0",
50
- "p-limit": "^7.2.0",
51
- "progress": "^2.0.3",
50
+ "p-limit": "^7.3.0",
52
51
  "yaml": "^2.8.3",
53
52
  "yoctocolors": "^2.1.1",
54
53
  "zip-stream": "^7.0.2"
55
54
  },
56
55
  "devDependencies": {
57
- "@types/node": "^20.17.9",
58
- "@types/progress": "^2",
56
+ "@types/node": "^20",
59
57
  "@types/zip-stream": "^7.0.0",
60
- "@vitest/runner": "^2.1.9",
58
+ "@vitest/runner": "^2",
61
59
  "@vitest/snapshot": "^2.1.9",
62
- "allure-js-commons": "^3.3.3",
63
- "allure-vitest": "^3.3.3",
64
- "rimraf": "^6.0.1",
60
+ "allure-js-commons": "^3",
61
+ "allure-vitest": "^3",
62
+ "rimraf": "^6",
65
63
  "tslib": "^2.7.0",
66
- "typescript": "^5.6.3",
67
- "vitest": "^2.1.9"
64
+ "typescript": "^5",
65
+ "vitest": "^4.1.0"
68
66
  }
69
67
  }