allure 3.0.0-beta.16 → 3.0.0-beta.17

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 (46) 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 +44 -36
  13. package/dist/commands/history.d.ts +9 -7
  14. package/dist/commands/history.js +31 -28
  15. package/dist/commands/knownIssue.d.ts +8 -6
  16. package/dist/commands/knownIssue.js +30 -23
  17. package/dist/commands/log.d.ts +12 -9
  18. package/dist/commands/log.js +54 -58
  19. package/dist/commands/login.d.ts +8 -7
  20. package/dist/commands/login.js +39 -36
  21. package/dist/commands/logout.d.ts +8 -7
  22. package/dist/commands/logout.js +39 -36
  23. package/dist/commands/open.d.ts +11 -9
  24. package/dist/commands/open.js +34 -40
  25. package/dist/commands/projects/create.d.ts +9 -7
  26. package/dist/commands/projects/create.js +70 -66
  27. package/dist/commands/projects/delete.d.ts +10 -7
  28. package/dist/commands/projects/delete.js +55 -61
  29. package/dist/commands/projects/list.d.ts +8 -7
  30. package/dist/commands/projects/list.js +62 -62
  31. package/dist/commands/qualityGate.d.ts +9 -7
  32. package/dist/commands/qualityGate.js +46 -42
  33. package/dist/commands/run.d.ts +13 -10
  34. package/dist/commands/run.js +102 -111
  35. package/dist/commands/slack.d.ts +9 -7
  36. package/dist/commands/slack.js +51 -48
  37. package/dist/commands/testplan.d.ts +8 -6
  38. package/dist/commands/testplan.js +36 -29
  39. package/dist/commands/watch.d.ts +12 -10
  40. package/dist/commands/watch.js +103 -99
  41. package/dist/commands/whoami.d.ts +8 -7
  42. package/dist/commands/whoami.js +44 -38
  43. package/dist/index.js +31 -35
  44. package/package.json +19 -19
  45. package/dist/utils/commands.d.ts +0 -16
  46. package/dist/utils/commands.js +0 -16
@@ -4,13 +4,13 @@ import { allureResultsDirectoriesWatcher, delayedFileProcessingWatcher, newFiles
4
4
  import Awesome from "@allurereport/plugin-awesome";
5
5
  import { PathResultFile } from "@allurereport/reader-api";
6
6
  import { KnownError } from "@allurereport/service";
7
+ import { Command, Option } from "clipanion";
7
8
  import * as console from "node:console";
8
9
  import { mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
9
10
  import { tmpdir } from "node:os";
10
11
  import { join, resolve } from "node:path";
11
12
  import process from "node:process";
12
13
  import { red } from "yoctocolors";
13
- import { createCommand } from "../utils/commands.js";
14
14
  import { logTests, runProcess, terminationOf } from "../utils/index.js";
15
15
  import { logError } from "../utils/logs.js";
16
16
  const runTests = async (allureReport, cwd, command, commandArgs, environment, silent) => {
@@ -59,124 +59,115 @@ const runTests = async (allureReport, cwd, command, commandArgs, environment, si
59
59
  await processWatcher.abort();
60
60
  return code;
61
61
  };
62
- export const RunCommandAction = async (options) => {
63
- const args = options["--"];
64
- if (!args || !args.length) {
65
- throw new Error("expecting command to be specified after --, e.g. allure run -- npm run test");
66
- }
67
- const before = new Date().getTime();
68
- process.on("exit", (exitCode) => {
69
- const after = new Date().getTime();
70
- console.log(`exit code ${exitCode} (${after - before}ms)`);
71
- });
72
- const command = args[0];
73
- const commandArgs = args.slice(1);
74
- const cwd = await realpath(options.cwd ?? process.cwd());
75
- console.log(`${command} ${commandArgs.join(" ")}`);
76
- const { config: configPath, output, reportName, rerun: maxRerun = 0, silent = false } = options;
77
- const config = await readConfig(cwd, configPath, { output, name: reportName });
78
- try {
79
- await rm(config.output, { recursive: true });
62
+ export class RunCommand extends Command {
63
+ constructor() {
64
+ super(...arguments);
65
+ this.config = Option.String("--config,-c", {
66
+ description: "The path Allure config file",
67
+ });
68
+ this.cwd = Option.String("--cwd", {
69
+ description: "The working directory for the command to run (default: current working directory)",
70
+ });
71
+ this.output = Option.String("--output,-o", {
72
+ description: "The output file name, allure.csv by default. Accepts absolute paths (default: ./allure-report)",
73
+ });
74
+ this.reportName = Option.String("--report-name,--name", {
75
+ description: "The report name (default: Allure Report)",
76
+ });
77
+ this.rerun = Option.String("--rerun", {
78
+ description: "The number of reruns for failed tests (default: 0)",
79
+ });
80
+ this.silent = Option.Boolean("--silent", {
81
+ description: "Don't pipe the process output logs to console (default: 0)",
82
+ });
83
+ this.commandToRun = Option.Proxy();
80
84
  }
81
- catch (e) {
82
- if (!isFileNotFoundError(e)) {
83
- console.error("could not clean output directory", e);
85
+ async execute() {
86
+ const args = this.commandToRun.filter((arg) => arg !== "--");
87
+ if (!args || !args.length) {
88
+ throw new Error("expecting command to be specified after --, e.g. allure run -- npm run test");
84
89
  }
85
- }
86
- try {
87
- const allureReport = new AllureReport({
88
- ...config,
89
- realTime: false,
90
- plugins: [
91
- ...(config.plugins?.length
92
- ? config.plugins
93
- : [
94
- {
95
- id: "awesome",
96
- enabled: true,
97
- options: {},
98
- plugin: new Awesome({
99
- reportName: config.name,
100
- }),
101
- },
102
- ]),
103
- ],
90
+ const before = new Date().getTime();
91
+ process.on("exit", (exitCode) => {
92
+ const after = new Date().getTime();
93
+ console.log(`exit code ${exitCode} (${after - before}ms)`);
104
94
  });
105
- await allureReport.start();
106
- let code = await runTests(allureReport, cwd, command, commandArgs, {}, silent);
107
- for (let rerun = 0; rerun < maxRerun; rerun++) {
108
- const failed = await allureReport.store.failedTestResults();
109
- if (failed.length === 0) {
110
- console.log("no failed tests is detected.");
111
- break;
95
+ const command = args[0];
96
+ const commandArgs = args.slice(1);
97
+ const cwd = await realpath(this.cwd ?? process.cwd());
98
+ console.log(`${command} ${commandArgs.join(" ")}`);
99
+ const maxRerun = this.rerun ? parseInt(this.rerun, 10) : 0;
100
+ const silent = this.silent ?? false;
101
+ const config = await readConfig(cwd, this.config, { output: this.output, name: this.reportName });
102
+ try {
103
+ await rm(config.output, { recursive: true });
104
+ }
105
+ catch (e) {
106
+ if (!isFileNotFoundError(e)) {
107
+ console.error("could not clean output directory", e);
112
108
  }
113
- const testPlan = createTestPlan(failed);
114
- console.log(`rerun number ${rerun} of ${testPlan.tests.length} tests:`);
115
- logTests(failed);
116
- const tmpDir = await mkdtemp(join(tmpdir(), "allure-run-"));
117
- const testPlanPath = resolve(tmpDir, `${rerun}-testplan.json`);
118
- await writeFile(testPlanPath, JSON.stringify(testPlan));
119
- code = await runTests(allureReport, cwd, command, commandArgs, {
120
- ALLURE_TESTPLAN_PATH: testPlanPath,
121
- ALLURE_RERUN: `${rerun}`,
122
- }, silent);
123
- await rm(tmpDir, { recursive: true });
124
- logTests(await allureReport.store.allTestResults());
125
109
  }
126
- await allureReport.done();
127
- await allureReport.validate();
128
- process.exit(code ?? allureReport.exitCode);
129
- }
130
- catch (error) {
131
- if (error instanceof KnownError) {
132
- console.error(red(error.message));
110
+ try {
111
+ const allureReport = new AllureReport({
112
+ ...config,
113
+ realTime: false,
114
+ plugins: [
115
+ ...(config.plugins?.length
116
+ ? config.plugins
117
+ : [
118
+ {
119
+ id: "awesome",
120
+ enabled: true,
121
+ options: {},
122
+ plugin: new Awesome({
123
+ reportName: config.name,
124
+ }),
125
+ },
126
+ ]),
127
+ ],
128
+ });
129
+ await allureReport.start();
130
+ let code = await runTests(allureReport, cwd, command, commandArgs, {}, silent);
131
+ for (let rerun = 0; rerun < maxRerun; rerun++) {
132
+ const failed = await allureReport.store.failedTestResults();
133
+ if (failed.length === 0) {
134
+ console.log("no failed tests is detected.");
135
+ break;
136
+ }
137
+ const testPlan = createTestPlan(failed);
138
+ console.log(`rerun number ${rerun} of ${testPlan.tests.length} tests:`);
139
+ logTests(failed);
140
+ const tmpDir = await mkdtemp(join(tmpdir(), "allure-run-"));
141
+ const testPlanPath = resolve(tmpDir, `${rerun}-testplan.json`);
142
+ await writeFile(testPlanPath, JSON.stringify(testPlan));
143
+ code = await runTests(allureReport, cwd, command, commandArgs, {
144
+ ALLURE_TESTPLAN_PATH: testPlanPath,
145
+ ALLURE_RERUN: `${rerun}`,
146
+ }, silent);
147
+ await rm(tmpDir, { recursive: true });
148
+ logTests(await allureReport.store.allTestResults());
149
+ }
150
+ await allureReport.done();
151
+ await allureReport.validate();
152
+ process.exit(code ?? allureReport.exitCode);
153
+ }
154
+ catch (error) {
155
+ if (error instanceof KnownError) {
156
+ console.error(red(error.message));
157
+ process.exit(1);
158
+ return;
159
+ }
160
+ await logError("Failed to run tests using Allure due to unexpected error", error);
133
161
  process.exit(1);
134
- return;
135
162
  }
136
- await logError("Failed to run tests using Allure due to unexpected error", error);
137
- process.exit(1);
138
163
  }
139
- };
140
- export const RunCommand = createCommand({
141
- name: "run",
164
+ }
165
+ RunCommand.paths = [["run"]];
166
+ RunCommand.usage = Command.Usage({
142
167
  description: "Run specified command",
143
- options: [
144
- [
145
- "--config, -c <file>",
146
- {
147
- description: "The path Allure config file",
148
- },
149
- ],
150
- [
151
- "--cwd <cwd>",
152
- {
153
- description: "The working directory for the command to run (Default: current working directory)",
154
- },
155
- ],
156
- [
157
- "--output, -o <file>",
158
- {
159
- description: "The output file name, allure.csv by default. Accepts absolute paths (Default: ./allure-report)",
160
- },
161
- ],
162
- [
163
- "--report-name, --name <string>",
164
- {
165
- description: "The report name (Default: Allure Report)",
166
- },
167
- ],
168
- [
169
- "--rerun <number>",
170
- {
171
- description: "The number of reruns for failed tests (Default: 0)",
172
- },
173
- ],
174
- [
175
- "--silent",
176
- {
177
- description: "Don't pipe the process output logs to console (Default: 0)",
178
- },
179
- ],
168
+ details: "This command runs the specified command and collects Allure results.",
169
+ examples: [
170
+ ["run -- npm run test", "Run npm run test and collect Allure results"],
171
+ ["run --rerun 3 -- npm run test", "Run npm run test and rerun failed tests up to 3 times"],
180
172
  ],
181
- action: RunCommandAction,
182
173
  });
@@ -1,9 +1,11 @@
1
- type CommandOptions = {
2
- cwd?: string;
3
- config?: string;
1
+ import { Command } from "clipanion";
2
+ export declare class SlackCommand extends Command {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ resultsDir: string;
6
+ config: string | undefined;
7
+ cwd: string | undefined;
4
8
  token: string;
5
9
  channel: string;
6
- };
7
- export declare const SlackCommandAction: (resultsDir: string, options: CommandOptions) => Promise<void>;
8
- export declare const SlackCommand: (cli: import("cac").CAC) => void;
9
- export {};
10
+ execute(): Promise<void>;
11
+ }
@@ -1,58 +1,61 @@
1
- import { AllureReport, enforcePlugin, readConfig } from "@allurereport/core";
1
+ import { AllureReport, readConfig } from "@allurereport/core";
2
2
  import SlackPlugin from "@allurereport/plugin-slack";
3
+ import { Command, Option } from "clipanion";
3
4
  import * as console from "node:console";
4
5
  import { realpath } from "node:fs/promises";
5
6
  import process from "node:process";
6
- import { createCommand } from "../utils/commands.js";
7
- export const SlackCommandAction = async (resultsDir, options) => {
8
- const cwd = await realpath(options.cwd ?? process.cwd());
9
- const before = new Date().getTime();
10
- const { config: configPath, token, channel } = options;
11
- const defaultSlackOptions = {
12
- token,
13
- channel,
14
- };
15
- const config = enforcePlugin(await readConfig(cwd, configPath), {
16
- id: "slack",
17
- enabled: true,
18
- options: defaultSlackOptions,
19
- plugin: new SlackPlugin(defaultSlackOptions),
20
- });
21
- const allureReport = new AllureReport(config);
22
- await allureReport.start();
23
- await allureReport.readDirectory(resultsDir);
24
- await allureReport.done();
25
- const after = new Date().getTime();
26
- console.log(`the report successfully generated (${after - before}ms)`);
27
- };
28
- export const SlackCommand = createCommand({
29
- name: "slack <resultsDir>",
30
- description: "Posts test results into Slack Channel",
31
- options: [
32
- [
33
- "--config, -c <file>",
34
- {
35
- description: "The path Allure config file",
36
- },
37
- ],
38
- [
39
- "--cwd <cwd>",
40
- {
41
- description: "The working directory for the command to run (Default: current working directory)",
42
- },
43
- ],
44
- [
45
- "--token, -t <token>",
7
+ export class SlackCommand extends Command {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.resultsDir = Option.String({ required: true, name: "The directory with Allure results" });
11
+ this.config = Option.String("--config,-c", {
12
+ description: "The path Allure config file",
13
+ });
14
+ this.cwd = Option.String("--cwd", {
15
+ description: "The working directory for the command to run (default: current working directory)",
16
+ });
17
+ this.token = Option.String("--token,-t", {
18
+ description: "Slack Bot User OAuth Token",
19
+ required: true,
20
+ });
21
+ this.channel = Option.String("--channel", {
22
+ description: "Slack channelId",
23
+ required: true,
24
+ });
25
+ }
26
+ async execute() {
27
+ const cwd = await realpath(this.cwd ?? process.cwd());
28
+ const before = new Date().getTime();
29
+ const defaultSlackOptions = {
30
+ token: this.token,
31
+ channel: this.channel,
32
+ };
33
+ const config = await readConfig(cwd, this.config);
34
+ config.plugins = [
46
35
  {
47
- description: "Slack Bot User OAuth Token",
36
+ id: "slack",
37
+ enabled: true,
38
+ options: defaultSlackOptions,
39
+ plugin: new SlackPlugin(defaultSlackOptions),
48
40
  },
49
- ],
41
+ ];
42
+ const allureReport = new AllureReport(config);
43
+ await allureReport.start();
44
+ await allureReport.readDirectory(this.resultsDir);
45
+ await allureReport.done();
46
+ const after = new Date().getTime();
47
+ console.log(`the report successfully generated (${after - before}ms)`);
48
+ }
49
+ }
50
+ SlackCommand.paths = [["slack"]];
51
+ SlackCommand.usage = Command.Usage({
52
+ category: "Reports",
53
+ description: "Posts test results into Slack Channel",
54
+ details: "This command posts test results from the provided Allure Results directory to a Slack channel.",
55
+ examples: [
50
56
  [
51
- "--channel, -c <channel>",
52
- {
53
- description: "Slack channelId",
54
- },
57
+ "slack ./allure-results --token xoxb-token --channel C12345",
58
+ "Post test results from the ./allure-results directory to the specified Slack channel",
55
59
  ],
56
60
  ],
57
- action: SlackCommandAction,
58
61
  });
@@ -1,6 +1,8 @@
1
- type CommandOptions = {
2
- output?: string;
3
- };
4
- export declare const TestPlanCommandAction: (resultsDir: string, options: CommandOptions) => Promise<void>;
5
- export declare const TestPlanCommand: (cli: import("cac").CAC) => void;
6
- export {};
1
+ import { Command } from "clipanion";
2
+ export declare class TestPlanCommand extends Command {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ resultsDir: string;
6
+ output: string | undefined;
7
+ execute(): Promise<void>;
8
+ }
@@ -1,38 +1,45 @@
1
1
  import { AllureReport, resolveConfig } from "@allurereport/core";
2
+ import { Command, Option } from "clipanion";
2
3
  import * as console from "node:console";
3
4
  import { basename, dirname, resolve } from "node:path";
4
- import { createCommand } from "../utils/commands.js";
5
- export const TestPlanCommandAction = async (resultsDir, options) => {
6
- const before = new Date().getTime();
7
- const resolved = resolve(options.output ?? "./testplan.json");
8
- const output = dirname(resolved);
9
- const fileName = basename(resolved);
10
- const config = await resolveConfig({
11
- output: output,
12
- plugins: {
13
- "@allurereport/plugin-testplan": {
14
- options: { fileName },
5
+ export class TestPlanCommand extends Command {
6
+ constructor() {
7
+ super(...arguments);
8
+ this.resultsDir = Option.String({ required: true, name: "The directory with Allure results" });
9
+ this.output = Option.String("--output,-o", {
10
+ description: "The output file name. Absolute paths are accepted as well",
11
+ });
12
+ }
13
+ async execute() {
14
+ const before = new Date().getTime();
15
+ const resolved = resolve(this.output ?? "./testplan.json");
16
+ const output = dirname(resolved);
17
+ const fileName = basename(resolved);
18
+ const config = await resolveConfig({
19
+ output: output,
20
+ plugins: {
21
+ "@allurereport/plugin-testplan": {
22
+ options: { fileName },
23
+ },
15
24
  },
16
- },
17
- });
18
- const allureReport = new AllureReport(config);
19
- await allureReport.start();
20
- await allureReport.readDirectory(resultsDir);
21
- await allureReport.done();
22
- const after = new Date().getTime();
23
- console.log(`the report successfully generated (${after - before}ms)`);
24
- };
25
- export const TestPlanCommand = createCommand({
26
- name: "testplan <resultsDir>",
25
+ });
26
+ const allureReport = new AllureReport(config);
27
+ await allureReport.start();
28
+ await allureReport.readDirectory(this.resultsDir);
29
+ await allureReport.done();
30
+ const after = new Date().getTime();
31
+ console.log(`the report successfully generated (${after - before}ms)`);
32
+ }
33
+ }
34
+ TestPlanCommand.paths = [["testplan"]];
35
+ TestPlanCommand.usage = Command.Usage({
27
36
  description: "Generates testplan.json based on provided Allure Results",
28
- options: [
37
+ details: "This command generates a testplan.json file from the provided Allure Results directory.",
38
+ examples: [
39
+ ["testplan ./allure-results", "Generate a testplan.json file from the ./allure-results directory"],
29
40
  [
30
- "--output, -o <file>",
31
- {
32
- description: "The output file name. Absolute paths are accepted as well",
33
- default: "testplan.json",
34
- },
41
+ "testplan ./allure-results --output custom-testplan.json",
42
+ "Generate a custom-testplan.json file from the ./allure-results directory",
35
43
  ],
36
44
  ],
37
- action: TestPlanCommandAction,
38
45
  });
@@ -1,10 +1,12 @@
1
- type WatchCommandOptions = {
2
- config?: string;
3
- output?: string;
4
- cwd?: string;
5
- reportName?: string;
6
- port?: string;
7
- };
8
- export declare const WatchCommandAction: (resultsDir: string, options: WatchCommandOptions) => Promise<void>;
9
- export declare const WatchCommand: (cli: import("cac").CAC) => void;
10
- export {};
1
+ import { Command } from "clipanion";
2
+ export declare class WatchCommand extends Command {
3
+ static paths: string[][];
4
+ static usage: import("clipanion").Usage;
5
+ resultsDir: string;
6
+ config: string | undefined;
7
+ cwd: string | undefined;
8
+ output: string | undefined;
9
+ reportName: string | undefined;
10
+ port: string | undefined;
11
+ execute(): Promise<void>;
12
+ }