allure 3.0.0-beta.16 → 3.0.0-beta.18

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.
Files changed (56) hide show
  1. package/dist/commands/allure2.d.ts +15 -13
  2. package/dist/commands/allure2.js +67 -79
  3. package/dist/commands/awesome.d.ts +18 -15
  4. package/dist/commands/awesome.js +79 -99
  5. package/dist/commands/classic.d.ts +15 -13
  6. package/dist/commands/classic.js +67 -79
  7. package/dist/commands/csv.d.ts +13 -11
  8. package/dist/commands/csv.js +59 -65
  9. package/dist/commands/dashboard.d.ts +15 -13
  10. package/dist/commands/dashboard.js +67 -78
  11. package/dist/commands/generate.d.ts +11 -9
  12. package/dist/commands/generate.js +70 -36
  13. package/dist/commands/history.d.ts +9 -7
  14. package/dist/commands/history.js +31 -28
  15. package/dist/commands/index.d.ts +1 -0
  16. package/dist/commands/index.js +1 -0
  17. package/dist/commands/knownIssue.d.ts +8 -6
  18. package/dist/commands/knownIssue.js +30 -23
  19. package/dist/commands/log.d.ts +12 -9
  20. package/dist/commands/log.js +54 -58
  21. package/dist/commands/login.d.ts +8 -7
  22. package/dist/commands/login.js +39 -36
  23. package/dist/commands/logout.d.ts +8 -7
  24. package/dist/commands/logout.js +39 -36
  25. package/dist/commands/open.d.ts +11 -9
  26. package/dist/commands/open.js +34 -40
  27. package/dist/commands/projects/create.d.ts +9 -7
  28. package/dist/commands/projects/create.js +70 -66
  29. package/dist/commands/projects/delete.d.ts +10 -7
  30. package/dist/commands/projects/delete.js +55 -61
  31. package/dist/commands/projects/list.d.ts +8 -7
  32. package/dist/commands/projects/list.js +62 -62
  33. package/dist/commands/qualityGate.d.ts +14 -7
  34. package/dist/commands/qualityGate.js +131 -45
  35. package/dist/commands/results/index.d.ts +2 -0
  36. package/dist/commands/results/index.js +2 -0
  37. package/dist/commands/results/pack.d.ts +10 -0
  38. package/dist/commands/results/pack.js +111 -0
  39. package/dist/commands/results/unpack.d.ts +9 -0
  40. package/dist/commands/results/unpack.js +79 -0
  41. package/dist/commands/run.d.ts +22 -10
  42. package/dist/commands/run.js +244 -101
  43. package/dist/commands/slack.d.ts +9 -7
  44. package/dist/commands/slack.js +51 -48
  45. package/dist/commands/testplan.d.ts +8 -6
  46. package/dist/commands/testplan.js +36 -29
  47. package/dist/commands/watch.d.ts +12 -10
  48. package/dist/commands/watch.js +103 -99
  49. package/dist/commands/whoami.d.ts +8 -7
  50. package/dist/commands/whoami.js +44 -38
  51. package/dist/index.js +33 -35
  52. package/dist/utils/process.d.ts +7 -1
  53. package/dist/utils/process.js +17 -6
  54. package/package.json +27 -20
  55. package/dist/utils/commands.d.ts +0 -16
  56. package/dist/utils/commands.js +0 -16
@@ -1,74 +1,68 @@
1
1
  import { readConfig } from "@allurereport/core";
2
2
  import { AllureServiceClient, KnownError } from "@allurereport/service";
3
+ import { Command, Option } from "clipanion";
4
+ import * as console from "node:console";
5
+ import { exit } from "node:process";
3
6
  import prompts from "prompts";
4
7
  import { green, red } from "yoctocolors";
5
- import { createCommand } from "../../utils/commands.js";
6
8
  import { logError } from "../../utils/logs.js";
7
- export const ProjectsDeleteCommandAction = async (projectName, options) => {
8
- const { force = false } = options ?? {};
9
- const { config: configPath, cwd } = options ?? {};
10
- const config = await readConfig(cwd, configPath);
11
- if (!config?.allureService?.url) {
12
- console.error(red("No Allure Service URL is provided. Please provide it in the `allureService.url` field in the `allure.config.js` file"));
13
- process.exit(1);
14
- return;
15
- }
16
- const serviceClient = new AllureServiceClient(config.allureService);
17
- if (!projectName) {
18
- console.error(red("No project name is provided"));
19
- process.exit(1);
20
- return;
21
- }
22
- if (!force) {
23
- const res = await prompts({
24
- type: "confirm",
25
- name: "value",
26
- message: `Are you sure you want to delete project "${projectName}"?`,
9
+ export class ProjectsDeleteCommand extends Command {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.projectName = Option.String({ required: true, name: "Project name" });
13
+ this.force = Option.Boolean("--force", {
14
+ description: "Delete project with no confirmation",
27
15
  });
28
- if (!res.value) {
29
- process.exit(0);
30
- return;
31
- }
32
- }
33
- try {
34
- await serviceClient.deleteProject({
35
- name: projectName,
16
+ this.config = Option.String("--config,-c", {
17
+ description: "The path Allure config file",
18
+ });
19
+ this.cwd = Option.String("--cwd", {
20
+ description: "The working directory for the command to run (default: current working directory)",
36
21
  });
37
- console.info(green("Project has been deleted"));
38
22
  }
39
- catch (error) {
40
- if (error instanceof KnownError) {
41
- console.error(red(error.message));
42
- process.exit(1);
23
+ async execute() {
24
+ const config = await readConfig(this.cwd, this.config);
25
+ if (!config?.allureService?.url) {
26
+ console.error(red("No Allure Service URL is provided. Please provide it in the `allureService.url` field in the `allure.config.js` file"));
27
+ exit(1);
43
28
  return;
44
29
  }
45
- await logError("Failed to delete project due to unexpected error", error);
46
- process.exit(1);
30
+ const serviceClient = new AllureServiceClient(config.allureService);
31
+ if (!this.force) {
32
+ const res = await prompts({
33
+ type: "confirm",
34
+ name: "value",
35
+ message: `Are you sure you want to delete project "${this.projectName}"?`,
36
+ });
37
+ if (!res.value) {
38
+ exit(0);
39
+ return;
40
+ }
41
+ }
42
+ try {
43
+ await serviceClient.deleteProject({
44
+ name: this.projectName,
45
+ });
46
+ console.info(green("Project has been deleted"));
47
+ }
48
+ catch (error) {
49
+ if (error instanceof KnownError) {
50
+ console.error(red(error.message));
51
+ exit(1);
52
+ return;
53
+ }
54
+ await logError("Failed to delete project due to unexpected error", error);
55
+ exit(1);
56
+ }
47
57
  }
48
- };
49
- export const ProjectsDeleteCommand = createCommand({
50
- name: "project-delete <name>",
51
- description: "",
52
- options: [
53
- [
54
- "--force",
55
- {
56
- description: "Delete project with no confirmation",
57
- default: false,
58
- },
59
- ],
60
- [
61
- "--config, -c <file>",
62
- {
63
- description: "The path Allure config file",
64
- },
65
- ],
66
- [
67
- "--cwd <cwd>",
68
- {
69
- description: "The working directory for the command to run (default: current working directory)",
70
- },
71
- ],
58
+ }
59
+ ProjectsDeleteCommand.paths = [["projects", "delete"]];
60
+ ProjectsDeleteCommand.usage = Command.Usage({
61
+ category: "Allure Service Projects",
62
+ description: "Deletes a project",
63
+ details: "This command deletes a project from the Allure Service.",
64
+ examples: [
65
+ ["project delete my-project", "Delete the project named 'my-project' (with confirmation)"],
66
+ ["project delete my-project --force", "Delete the project named 'my-project' without confirmation"],
72
67
  ],
73
- action: ProjectsDeleteCommandAction,
74
68
  });
@@ -1,7 +1,8 @@
1
- type CommandOptions = {
2
- config?: string;
3
- cwd?: string;
4
- };
5
- export declare const ProjectsListCommandAction: (options?: CommandOptions) => Promise<void>;
6
- export declare const ProjectsListCommand: (cli: import("cac").CAC) => void;
7
- export {};
1
+ import { Command } from "clipanion";
2
+ export declare class ProjectsListCommand extends Command {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ config: string | undefined;
6
+ cwd: string | undefined;
7
+ execute(): Promise<void>;
8
+ }
@@ -1,75 +1,75 @@
1
1
  import { readConfig } from "@allurereport/core";
2
2
  import { AllureServiceClient, KnownError } from "@allurereport/service";
3
+ import { Command, Option } from "clipanion";
4
+ import * as console from "node:console";
5
+ import { exit } from "node:process";
3
6
  import prompts from "prompts";
4
7
  import { green, red, yellow } from "yoctocolors";
5
- import { createCommand } from "../../utils/commands.js";
6
8
  import { logError } from "../../utils/logs.js";
7
- export const ProjectsListCommandAction = async (options) => {
8
- const { config: configPath, cwd } = options ?? {};
9
- const config = await readConfig(cwd, configPath);
10
- if (!config?.allureService?.url) {
11
- console.error(red("No Allure Service URL is provided. Please provide it in the `allureService.url` field in the `allure.config.js` file"));
12
- process.exit(1);
13
- return;
9
+ export class ProjectsListCommand extends Command {
10
+ constructor() {
11
+ super(...arguments);
12
+ this.config = Option.String("--config,-c", {
13
+ description: "The path Allure config file",
14
+ });
15
+ this.cwd = Option.String("--cwd", {
16
+ description: "The working directory for the command to run (default: current working directory)",
17
+ });
14
18
  }
15
- const serviceClient = new AllureServiceClient(config.allureService);
16
- try {
17
- const projects = await serviceClient.projects();
18
- if (projects.length === 0) {
19
- console.info(yellow("No projects found. Create a new one with `allure project-create` command"));
19
+ async execute() {
20
+ const config = await readConfig(this.cwd, this.config);
21
+ if (!config?.allureService?.url) {
22
+ console.error(red("No Allure Service URL is provided. Please provide it in the `allureService.url` field in the `allure.config.js` file"));
23
+ exit(1);
20
24
  return;
21
25
  }
22
- const res = await prompts({
23
- type: "select",
24
- name: "project",
25
- message: "Select a project",
26
- choices: projects.map((project) => ({
27
- title: project.name,
28
- value: project.name,
29
- })),
30
- });
31
- if (!res?.project) {
32
- console.error(red("No project selected"));
33
- process.exit(1);
34
- return;
26
+ const serviceClient = new AllureServiceClient(config.allureService);
27
+ try {
28
+ const projects = await serviceClient.projects();
29
+ if (projects.length === 0) {
30
+ console.info(yellow("No projects found. Create a new one with `allure project-create` command"));
31
+ return;
32
+ }
33
+ const res = await prompts({
34
+ type: "select",
35
+ name: "project",
36
+ message: "Select a project",
37
+ choices: projects.map((project) => ({
38
+ title: project.name,
39
+ value: project.name,
40
+ })),
41
+ });
42
+ if (!res?.project) {
43
+ console.error(red("No project selected"));
44
+ exit(1);
45
+ return;
46
+ }
47
+ const lines = [
48
+ "Insert following code into your Allure Config file, to enable Allure Service features for the project:",
49
+ "",
50
+ green("{"),
51
+ green(" allureService: {"),
52
+ green(` project: "${res.project}"`),
53
+ green(" }"),
54
+ green("}"),
55
+ ];
56
+ console.info(lines.join("\n"));
35
57
  }
36
- const lines = [
37
- "Insert following code into your Allure Config file, to enable Allure Service features for the project:",
38
- "",
39
- green("{"),
40
- green(" allureService: {"),
41
- green(` project: "${res.project}"`),
42
- green(" }"),
43
- green("}"),
44
- ];
45
- console.info(lines.join("\n"));
46
- }
47
- catch (error) {
48
- if (error instanceof KnownError) {
49
- console.error(red(error.message));
50
- process.exit(1);
51
- return;
58
+ catch (error) {
59
+ if (error instanceof KnownError) {
60
+ console.error(red(error.message));
61
+ exit(1);
62
+ return;
63
+ }
64
+ await logError("Failed to get projects due to unexpected error", error);
65
+ exit(1);
52
66
  }
53
- await logError("Failed to get projects due to unexpected error", error);
54
- process.exit(1);
55
67
  }
56
- };
57
- export const ProjectsListCommand = createCommand({
58
- name: "projects",
68
+ }
69
+ ProjectsListCommand.paths = [["projects", "list"]];
70
+ ProjectsListCommand.usage = Command.Usage({
71
+ category: "Allure Service Projects",
59
72
  description: "Shows list of all available projects for current user",
60
- options: [
61
- [
62
- "--config, -c <file>",
63
- {
64
- description: "The path Allure config file",
65
- },
66
- ],
67
- [
68
- "--cwd <cwd>",
69
- {
70
- description: "The working directory for the command to run (default: current working directory)",
71
- },
72
- ],
73
- ],
74
- action: ProjectsListCommandAction,
73
+ details: "This command lists all available projects for the current user and allows selecting one to get configuration information.",
74
+ examples: [["projects list", "List all available projects"]],
75
75
  });
@@ -1,7 +1,14 @@
1
- type QualityGateCommandOptions = {
2
- config?: string;
3
- cwd?: string;
4
- };
5
- export declare const QualityGateCommandAction: (resultsDir: string, options: QualityGateCommandOptions) => Promise<void>;
6
- export declare const QualityGateCommand: (cli: import("cac").CAC) => void;
7
- export {};
1
+ import { Command } from "clipanion";
2
+ export declare class QualityGateCommand extends Command {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ resultsDir: string | undefined;
6
+ config: string | undefined;
7
+ fastFail: boolean | undefined;
8
+ maxFailures: number | undefined;
9
+ minTestsCount: number | undefined;
10
+ successRate: number | undefined;
11
+ knownIssues: string | undefined;
12
+ cwd: string | undefined;
13
+ execute(): Promise<void>;
14
+ }
@@ -1,52 +1,138 @@
1
- import { AllureReport, readConfig } from "@allurereport/core";
2
- import console from "node:console";
3
- import process from "node:process";
4
- import { bold, red } from "yoctocolors";
5
- import { createCommand } from "../utils/commands.js";
6
- export const QualityGateCommandAction = async (resultsDir, options) => {
7
- const { cwd, config: configPath } = options;
8
- const fullConfig = await readConfig(cwd, configPath);
9
- const allureReport = new AllureReport(fullConfig);
10
- await allureReport.start();
11
- await allureReport.readDirectory(resultsDir);
12
- await allureReport.done();
13
- await allureReport.validate();
14
- if (allureReport.exitCode === 0) {
15
- return;
1
+ import { AllureReport, QualityGateState, readConfig, stringifyQualityGateResults } from "@allurereport/core";
2
+ import { findMatching } from "@allurereport/directory-watcher";
3
+ import { Command, Option } from "clipanion";
4
+ import * as console from "node:console";
5
+ import { realpath } from "node:fs/promises";
6
+ import { join } from "node:path";
7
+ import { exit, cwd as processCwd } from "node:process";
8
+ import pm from "picomatch";
9
+ import * as typanion from "typanion";
10
+ import { red } from "yoctocolors";
11
+ export class QualityGateCommand extends Command {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.resultsDir = Option.String({
15
+ required: false,
16
+ name: "Pattern to match test results directories in the current working directory (default: ./**/allure-results)",
17
+ });
18
+ this.config = Option.String("--config,-c", {
19
+ description: "The path Allure config file",
20
+ });
21
+ this.fastFail = Option.Boolean("--fast-fail", {
22
+ description: "Force the command to fail if there are any rule failures",
23
+ });
24
+ this.maxFailures = Option.String("--max-failures", {
25
+ description: "The maximum number of rule failures to allow before failing the command",
26
+ validator: typanion.isNumber(),
27
+ });
28
+ this.minTestsCount = Option.String("--min-tests-count", {
29
+ description: "The minimum number of tests to run before validating the quality gate",
30
+ validator: typanion.isNumber(),
31
+ });
32
+ this.successRate = Option.String("--success-rate", {
33
+ description: "The minimum success rate to allow before failing the command",
34
+ validator: typanion.isNumber(),
35
+ });
36
+ this.knownIssues = Option.String("--known-issues", {
37
+ description: "Path to the known issues file. Updates the file and quarantines failed tests when specified",
38
+ });
39
+ this.cwd = Option.String("--cwd", {
40
+ description: "The working directory for the command to run (default: current working directory)",
41
+ });
16
42
  }
17
- const failedResults = allureReport.validationResults.filter((result) => !result.success);
18
- console.error(red(`Quality gate has failed with ${bold(failedResults.length.toString())} errors:\n`));
19
- for (const result of failedResults) {
20
- let scope = "";
21
- switch (result.meta?.type) {
22
- case "label":
23
- scope = `(label[${result.meta.name}="${result.meta.value}"])`;
24
- break;
25
- case "parameter":
26
- scope = `(parameter[${result.meta.name}="${result.meta.value}"])`;
27
- break;
28
- }
29
- console.error(red(`⨯ ${bold(`${result.rule}${scope}`)}: expected ${result.expected}, actual ${result.actual}`));
43
+ async execute() {
44
+ const cwd = await realpath(this.cwd ?? processCwd());
45
+ const resultsDir = (this.resultsDir ?? "./**/allure-results").replace(/[\\/]$/, "");
46
+ const { maxFailures, minTestsCount, successRate, fastFail, knownIssues: knownIssuesPath } = this;
47
+ const config = await readConfig(cwd, this.config, {
48
+ knownIssuesPath,
49
+ });
50
+ const rules = {};
51
+ const resultsDirectories = new Set();
52
+ const matcher = pm(resultsDir, {
53
+ dot: true,
54
+ contains: true,
55
+ });
56
+ if (maxFailures !== undefined) {
57
+ rules.maxFailures = maxFailures;
58
+ }
59
+ if (minTestsCount !== undefined) {
60
+ rules.minTestsCount = minTestsCount;
61
+ }
62
+ if (successRate !== undefined) {
63
+ rules.successRate = successRate;
64
+ }
65
+ if (fastFail) {
66
+ rules.fastFail = fastFail;
67
+ }
68
+ config.plugins = [];
69
+ if (Object.keys(rules).length > 0) {
70
+ config.qualityGate = {
71
+ rules: [rules],
72
+ };
73
+ }
74
+ const allureReport = new AllureReport(config);
75
+ if (!allureReport.hasQualityGate) {
76
+ console.error(red("Quality gate is not configured!"));
77
+ console.error(red("Add qualityGate to the config or consult help to know, how to use the command with command-line arguments"));
78
+ exit(-1);
79
+ return;
80
+ }
81
+ await findMatching(cwd, resultsDirectories, (dirent) => {
82
+ if (dirent.isDirectory()) {
83
+ const fullPath = join(dirent?.parentPath ?? dirent?.path, dirent.name);
84
+ return matcher(fullPath);
85
+ }
86
+ return false;
87
+ });
88
+ if (resultsDirectories.size === 0) {
89
+ console.error("No Allure results directories found");
90
+ exit(0);
91
+ return;
92
+ }
93
+ const knownIssues = await allureReport.store.allKnownIssues();
94
+ const state = new QualityGateState();
95
+ allureReport.realtimeSubscriber.onTestResults(async (trsIds) => {
96
+ const trs = await Promise.all(trsIds.map((id) => allureReport.store.testResultById(id)));
97
+ const notHiddenTrs = trs.filter((tr) => !tr.hidden);
98
+ const { results, fastFailed } = await allureReport.validate({
99
+ trs: notHiddenTrs,
100
+ knownIssues,
101
+ state,
102
+ });
103
+ if (!fastFailed) {
104
+ return;
105
+ }
106
+ console.error(stringifyQualityGateResults(results));
107
+ exit(1);
108
+ });
109
+ await allureReport.start();
110
+ for (const dir of resultsDirectories) {
111
+ await allureReport.readDirectory(dir);
112
+ }
113
+ await allureReport.done();
114
+ const allTrs = await allureReport.store.allTestResults({ includeHidden: false });
115
+ const validationResults = await allureReport.validate({
116
+ trs: allTrs,
117
+ knownIssues,
118
+ });
119
+ if (validationResults.results.length === 0) {
120
+ exit(0);
121
+ return;
122
+ }
123
+ console.error(stringifyQualityGateResults(validationResults.results));
124
+ exit(1);
30
125
  }
31
- console.error(red("\nThe process has been exited with code 1"));
32
- process.exit(allureReport.exitCode);
33
- };
34
- export const QualityGateCommand = createCommand({
35
- name: "quality-gate <resultsDir>",
126
+ }
127
+ QualityGateCommand.paths = [["quality-gate"]];
128
+ QualityGateCommand.usage = Command.Usage({
36
129
  description: "Returns status code 1 if there any test failure above specified success rate",
37
- options: [
38
- [
39
- "--config, -c <file>",
40
- {
41
- description: "The path Allure config file",
42
- },
43
- ],
130
+ details: "This command validates the test results against quality gates defined in the configuration.",
131
+ examples: [
132
+ ["quality-gate ./allure-results", "Validate the test results in the ./allure-results directory"],
44
133
  [
45
- "--cwd <cwd>",
46
- {
47
- description: "The working directory for the command to run (Default: current working directory)",
48
- },
134
+ "quality-gate ./allure-results --config custom-config.js",
135
+ "Validate the test results using a custom configuration file",
49
136
  ],
50
137
  ],
51
- action: QualityGateCommandAction,
52
138
  });
@@ -0,0 +1,2 @@
1
+ export * from "./pack.js";
2
+ export * from "./unpack.js";
@@ -0,0 +1,2 @@
1
+ export * from "./pack.js";
2
+ export * from "./unpack.js";
@@ -0,0 +1,10 @@
1
+ import { Command } from "clipanion";
2
+ export declare class ResultsPackCommand extends Command {
3
+ #private;
4
+ static paths: string[][];
5
+ static usage: import("clipanion").Usage;
6
+ resultsDir: string | undefined;
7
+ name: string | undefined;
8
+ cwd: string | undefined;
9
+ execute(): Promise<void>;
10
+ }
@@ -0,0 +1,111 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _ResultsPackCommand_instances, _ResultsPackCommand_formatSize;
7
+ import { findMatching } from "@allurereport/directory-watcher";
8
+ import AdmZip from "adm-zip";
9
+ import { Command, Option } from "clipanion";
10
+ import * as console from "node:console";
11
+ import * as fs from "node:fs/promises";
12
+ import { realpath } from "node:fs/promises";
13
+ import { basename, join, resolve } from "node:path";
14
+ import pm from "picomatch";
15
+ import { green, red } from "yoctocolors";
16
+ export class ResultsPackCommand extends Command {
17
+ constructor() {
18
+ super(...arguments);
19
+ _ResultsPackCommand_instances.add(this);
20
+ this.resultsDir = Option.String({
21
+ required: false,
22
+ name: "Pattern to match test results directories in the current working directory (default: ./**/allure-results)",
23
+ });
24
+ this.name = Option.String("--name", {
25
+ description: "The archive name (default: allure-results.zip)",
26
+ });
27
+ this.cwd = Option.String("--cwd", {
28
+ description: "The working directory for the command to run (default: current working directory)",
29
+ });
30
+ }
31
+ async execute() {
32
+ const cwd = await realpath(this.cwd ?? process.cwd());
33
+ const resultsDir = (this.resultsDir ?? "./**/allure-results").replace(/[\\/]$/, "");
34
+ const archiveName = this.name ?? "allure-results.zip";
35
+ const resultsDirectories = new Set();
36
+ const resultsFiles = new Set();
37
+ const matcher = pm(resultsDir, {
38
+ dot: true,
39
+ contains: true,
40
+ });
41
+ await findMatching(cwd, resultsDirectories, (dirent) => {
42
+ if (dirent.isDirectory()) {
43
+ const fullPath = join(dirent?.parentPath ?? dirent?.path, dirent.name);
44
+ return matcher(fullPath);
45
+ }
46
+ return false;
47
+ });
48
+ if (resultsDirectories.size === 0) {
49
+ console.log(red(`No test results directories found matching pattern: ${resultsDir}`));
50
+ return;
51
+ }
52
+ for (const dir of resultsDirectories) {
53
+ const files = await fs.readdir(dir);
54
+ if (files.length === 0) {
55
+ continue;
56
+ }
57
+ for (const file of files) {
58
+ resultsFiles.add(resolve(dir, file));
59
+ }
60
+ }
61
+ const outputPath = join(cwd, archiveName);
62
+ const zip = new AdmZip();
63
+ for (const file of resultsFiles) {
64
+ try {
65
+ const stats = await fs.stat(file);
66
+ if (stats.isFile()) {
67
+ zip.addLocalFile(file, "", basename(file));
68
+ }
69
+ }
70
+ catch (error) {
71
+ console.log(red(`Error adding file ${file} to archive: ${error.message}`));
72
+ }
73
+ }
74
+ try {
75
+ zip.writeZip(outputPath);
76
+ const stats = await fs.stat(outputPath);
77
+ console.log(green(`Archive created successfully: ${outputPath}`));
78
+ console.log(green(`Total size: ${__classPrivateFieldGet(this, _ResultsPackCommand_instances, "m", _ResultsPackCommand_formatSize).call(this, stats.size)}. ${resultsFiles.size} results files have been collected`));
79
+ }
80
+ catch (err) {
81
+ console.log(red(`Error creating archive: ${err.message}`));
82
+ throw err;
83
+ }
84
+ }
85
+ }
86
+ _ResultsPackCommand_instances = new WeakSet(), _ResultsPackCommand_formatSize = function _ResultsPackCommand_formatSize(bytes) {
87
+ const units = ["bytes", "KB", "MB", "GB"];
88
+ let size = bytes;
89
+ let unitIndex = 0;
90
+ while (size >= 1024 && unitIndex < units.length - 1) {
91
+ size /= 1024;
92
+ unitIndex++;
93
+ }
94
+ if (bytes === 0) {
95
+ return "0 bytes";
96
+ }
97
+ return unitIndex === 0 ? `${Math.round(size)} ${units[unitIndex]}` : `${size.toFixed(2)} ${units[unitIndex]}`;
98
+ };
99
+ ResultsPackCommand.paths = [["results", "pack"]];
100
+ ResultsPackCommand.usage = Command.Usage({
101
+ description: "Creates .zip archive with test results",
102
+ category: "Allure Test Results",
103
+ details: "This command creates .zip archive with all test results which can be collected in the project",
104
+ examples: [
105
+ ["results pack", "Creates .zip archive with test results in directories matched to ./**/allure-results pattern"],
106
+ [
107
+ "results pack ./**/foo/**/my-results --name results.zip",
108
+ "Creates results.zip archive with test results in directories matched to ./**/foo/**/my-results pattern",
109
+ ],
110
+ ],
111
+ });
@@ -0,0 +1,9 @@
1
+ import { Command } from "clipanion";
2
+ export declare class ResultsUnpackCommand extends Command {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ output: string;
6
+ archives: string[];
7
+ cwd: string | undefined;
8
+ execute(): Promise<void>;
9
+ }