allure 3.0.0-beta.2 → 3.0.0-beta.20

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 (66) hide show
  1. package/README.md +148 -16
  2. package/dist/commands/allure2.d.ts +15 -0
  3. package/dist/commands/allure2.js +77 -0
  4. package/dist/commands/awesome.d.ts +18 -12
  5. package/dist/commands/awesome.js +83 -75
  6. package/dist/commands/classic.d.ts +15 -11
  7. package/dist/commands/classic.js +71 -63
  8. package/dist/commands/csv.d.ts +13 -9
  9. package/dist/commands/csv.js +63 -45
  10. package/dist/commands/dashboard.d.ts +15 -0
  11. package/dist/commands/dashboard.js +77 -0
  12. package/dist/commands/generate.d.ts +12 -9
  13. package/dist/commands/generate.js +99 -26
  14. package/dist/commands/history.d.ts +9 -7
  15. package/dist/commands/history.js +32 -29
  16. package/dist/commands/index.d.ts +7 -0
  17. package/dist/commands/index.js +7 -0
  18. package/dist/commands/knownIssue.d.ts +8 -6
  19. package/dist/commands/knownIssue.js +31 -20
  20. package/dist/commands/log.d.ts +12 -7
  21. package/dist/commands/log.js +58 -40
  22. package/dist/commands/login.d.ts +8 -0
  23. package/dist/commands/login.js +50 -0
  24. package/dist/commands/logout.d.ts +8 -0
  25. package/dist/commands/logout.js +50 -0
  26. package/dist/commands/open.d.ts +11 -8
  27. package/dist/commands/open.js +36 -36
  28. package/dist/commands/projects/create.d.ts +9 -0
  29. package/dist/commands/projects/create.js +83 -0
  30. package/dist/commands/projects/delete.d.ts +10 -0
  31. package/dist/commands/projects/delete.js +68 -0
  32. package/dist/commands/projects/index.d.ts +3 -0
  33. package/dist/commands/projects/index.js +3 -0
  34. package/dist/commands/projects/list.d.ts +8 -0
  35. package/dist/commands/projects/list.js +75 -0
  36. package/dist/commands/qualityGate.d.ts +14 -6
  37. package/dist/commands/qualityGate.js +126 -39
  38. package/dist/commands/results/index.d.ts +2 -0
  39. package/dist/commands/results/index.js +2 -0
  40. package/dist/commands/results/pack.d.ts +10 -0
  41. package/dist/commands/results/pack.js +106 -0
  42. package/dist/commands/results/unpack.d.ts +9 -0
  43. package/dist/commands/results/unpack.js +79 -0
  44. package/dist/commands/run.d.ts +24 -10
  45. package/dist/commands/run.js +279 -109
  46. package/dist/commands/slack.d.ts +9 -5
  47. package/dist/commands/slack.js +55 -31
  48. package/dist/commands/testplan.d.ts +8 -6
  49. package/dist/commands/testplan.js +38 -30
  50. package/dist/commands/watch.d.ts +12 -10
  51. package/dist/commands/watch.js +110 -106
  52. package/dist/commands/whoami.d.ts +8 -0
  53. package/dist/commands/whoami.js +57 -0
  54. package/dist/index.d.ts +1 -2
  55. package/dist/index.js +34 -28
  56. package/dist/utils/index.d.ts +1 -0
  57. package/dist/utils/index.js +1 -0
  58. package/dist/utils/logs.d.ts +3 -0
  59. package/dist/utils/logs.js +32 -0
  60. package/dist/utils/process.d.ts +8 -2
  61. package/dist/utils/process.js +17 -6
  62. package/dist/utils/terminal.d.ts +1 -1
  63. package/dist/utils/terminal.js +1 -1
  64. package/package.json +33 -15
  65. package/dist/utils/commands.d.ts +0 -16
  66. package/dist/utils/commands.js +0 -14
@@ -1,16 +1,21 @@
1
- import { AllureReport, isFileNotFoundError, readRuntimeConfig } from "@allure/core";
2
- import { createTestPlan } from "@allure/core-api";
3
- import { allureResultsDirectoriesWatcher, delayedFileProcessingWatcher, newFilesInDirectoryWatcher, } from "@allure/directory-watcher";
4
- import AllureAwesome from "@allure/plugin-awesome";
5
- import { PathResultFile } from "@allure/reader-api";
1
+ import { AllureReport, QualityGateState, isFileNotFoundError, readConfig, stringifyQualityGateResults, } from "@allurereport/core";
2
+ import { createTestPlan } from "@allurereport/core-api";
3
+ import { allureResultsDirectoriesWatcher, delayedFileProcessingWatcher, newFilesInDirectoryWatcher, } from "@allurereport/directory-watcher";
4
+ import Awesome from "@allurereport/plugin-awesome";
5
+ import { BufferResultFile, PathResultFile } from "@allurereport/reader-api";
6
+ import { KnownError } from "@allurereport/service";
7
+ import { Command, Option } from "clipanion";
6
8
  import * as console from "node:console";
7
9
  import { mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
8
10
  import { tmpdir } from "node:os";
9
11
  import { join, resolve } from "node:path";
10
- import process from "node:process";
11
- import { createCommand } from "../utils/commands.js";
12
+ import process, { exit } from "node:process";
13
+ import terminate from "terminate/promise";
14
+ import { red } from "yoctocolors";
12
15
  import { logTests, runProcess, terminationOf } from "../utils/index.js";
13
- const runTests = async (allureReport, cwd, command, commandArgs, environment, silent) => {
16
+ import { logError } from "../utils/logs.js";
17
+ const runTests = async (params) => {
18
+ const { allureReport, knownIssues, cwd, command, commandArgs, logs, environment, withQualityGate, silent } = params;
14
19
  let testProcessStarted = false;
15
20
  const allureResultsWatchers = new Map();
16
21
  const processWatcher = delayedFileProcessingWatcher(async (path) => {
@@ -44,124 +49,289 @@ const runTests = async (allureReport, cwd, command, commandArgs, environment, si
44
49
  await allureResultsWatch.initialScan();
45
50
  testProcessStarted = true;
46
51
  const beforeProcess = Date.now();
47
- const testProcess = runProcess(command, commandArgs, cwd, environment, silent);
52
+ const testProcess = runProcess({
53
+ command,
54
+ commandArgs,
55
+ cwd,
56
+ environment,
57
+ logs,
58
+ });
59
+ const qualityGateState = new QualityGateState();
60
+ let qualityGateUnsub;
61
+ let qualityGateResults = [];
62
+ let testProcessStdout = "";
63
+ let testProcessStderr = "";
64
+ if (withQualityGate) {
65
+ qualityGateUnsub = allureReport.realtimeSubscriber.onTestResults(async (testResults) => {
66
+ const trs = await Promise.all(testResults.map((tr) => allureReport.store.testResultById(tr)));
67
+ const filteredTrs = trs.filter((tr) => tr !== undefined);
68
+ if (!filteredTrs.length) {
69
+ return;
70
+ }
71
+ const { results, fastFailed } = await allureReport.validate({
72
+ trs: filteredTrs,
73
+ state: qualityGateState,
74
+ knownIssues,
75
+ });
76
+ if (!fastFailed) {
77
+ return;
78
+ }
79
+ allureReport.realtimeDispatcher.sendQualityGateResults(results);
80
+ qualityGateResults = results;
81
+ try {
82
+ await terminate(testProcess.pid, "SIGTERM");
83
+ }
84
+ catch (err) {
85
+ if (err.message.includes("kill ESRCH")) {
86
+ return;
87
+ }
88
+ throw err;
89
+ }
90
+ });
91
+ }
92
+ if (logs === "pipe") {
93
+ testProcess.stdout?.setEncoding("utf8").on?.("data", (data) => {
94
+ testProcessStdout += data;
95
+ if (silent) {
96
+ return;
97
+ }
98
+ process.stdout.write(data);
99
+ });
100
+ testProcess.stderr?.setEncoding("utf8").on?.("data", async (data) => {
101
+ testProcessStderr += data;
102
+ if (silent) {
103
+ return;
104
+ }
105
+ process.stderr.write(data);
106
+ });
107
+ }
48
108
  const code = await terminationOf(testProcess);
49
109
  const afterProcess = Date.now();
50
- console.log(`process finished with code ${code ?? 0} (${afterProcess - beforeProcess})ms`);
110
+ if (code !== null) {
111
+ console.log(`process finished with code ${code} (${afterProcess - beforeProcess}ms)`);
112
+ }
113
+ else {
114
+ console.log(`process terminated (${afterProcess - beforeProcess}ms)`);
115
+ }
51
116
  await allureResultsWatch.abort();
52
117
  for (const [ar, watcher] of allureResultsWatchers) {
53
118
  await watcher.abort();
54
119
  allureResultsWatchers.delete(ar);
55
120
  }
56
121
  await processWatcher.abort();
122
+ qualityGateUnsub?.();
123
+ return {
124
+ code,
125
+ stdout: testProcessStdout,
126
+ stderr: testProcessStderr,
127
+ qualityGateResults,
128
+ };
57
129
  };
58
- export const RunCommandAction = async (options) => {
59
- const args = options["--"];
60
- if (!args || !args.length) {
61
- throw new Error("expecting command to be specified after --, e.g. allure run -- npm run test");
62
- }
63
- const before = new Date().getTime();
64
- process.on("exit", (code) => {
65
- const after = new Date().getTime();
66
- console.log(`exit code ${code} (${after - before}ms)`);
67
- });
68
- const command = args[0];
69
- const commandArgs = args.slice(1);
70
- const cwd = await realpath(options.cwd ?? process.cwd());
71
- console.log(`${command} ${commandArgs.join(" ")}`);
72
- const { config: configPath, output, reportName, rerun: maxRerun = 0, silent = false } = options;
73
- const config = await readRuntimeConfig(configPath, cwd, output, reportName);
74
- try {
75
- await rm(config.output, { recursive: true });
130
+ export class RunCommand extends Command {
131
+ constructor() {
132
+ super(...arguments);
133
+ this.config = Option.String("--config,-c", {
134
+ description: "The path Allure config file",
135
+ });
136
+ this.cwd = Option.String("--cwd", {
137
+ description: "The working directory for the command to run (default: current working directory)",
138
+ });
139
+ this.output = Option.String("--output,-o", {
140
+ description: "The output file name, allure.csv by default. Accepts absolute paths (default: ./allure-report)",
141
+ });
142
+ this.reportName = Option.String("--report-name,--name", {
143
+ description: "The report name (default: Allure Report)",
144
+ });
145
+ this.rerun = Option.String("--rerun", {
146
+ description: "The number of reruns for failed tests (default: 0)",
147
+ });
148
+ this.silent = Option.Boolean("--silent", {
149
+ description: "Don't pipe the process output logs to console (default: 0)",
150
+ });
151
+ this.ignoreLogs = Option.Boolean("--ignore-logs", {
152
+ description: "Prevent logs attaching to the report (default: false)",
153
+ });
154
+ this.stage = Option.String("--stage", {
155
+ description: "Runs tests in stage mode to collect results to a stage archive with the provided name (default: empty string)",
156
+ });
157
+ this.environment = Option.String("--environment", {
158
+ description: "Force specific environment to all tests in the run. Given environment has higher priority than the one defined in the config file (default: empty string)",
159
+ });
160
+ this.commandToRun = Option.Rest();
76
161
  }
77
- catch (e) {
78
- if (!isFileNotFoundError(e)) {
79
- console.error("could not clean output directory", e);
162
+ get logs() {
163
+ if (this.silent) {
164
+ return this.ignoreLogs ? "ignore" : "pipe";
80
165
  }
166
+ return this.ignoreLogs ? "inherit" : "pipe";
81
167
  }
82
- const allureReport = new AllureReport({
83
- ...config,
84
- realTime: false,
85
- plugins: [
86
- ...(config.plugins?.length
87
- ? config.plugins
88
- : [
89
- {
90
- id: "awesome",
91
- enabled: true,
92
- options: {},
93
- plugin: new AllureAwesome({
94
- reportName: config.name,
95
- }),
168
+ async execute() {
169
+ const args = this.commandToRun.filter((arg) => arg !== "--");
170
+ if (!args || !args.length) {
171
+ throw new Error("expecting command to be specified after --, e.g. allure run -- npm run test");
172
+ }
173
+ const before = new Date().getTime();
174
+ process.on("exit", (exitCode) => {
175
+ const after = new Date().getTime();
176
+ console.log(`exit code ${exitCode} (${after - before}ms)`);
177
+ });
178
+ const command = args[0];
179
+ const commandArgs = args.slice(1);
180
+ const cwd = await realpath(this.cwd ?? process.cwd());
181
+ console.log(`${command} ${commandArgs.join(" ")}`);
182
+ const maxRerun = this.rerun ? parseInt(this.rerun, 10) : 0;
183
+ const config = await readConfig(cwd, this.config, { output: this.output, name: this.reportName });
184
+ const withQualityGate = !!config.qualityGate;
185
+ const withRerun = !!this.rerun;
186
+ if (withQualityGate && withRerun) {
187
+ console.error(red("At this moment, quality gate and rerun can't be used at the same time!"));
188
+ console.error(red("Consider using --rerun=0 or disable quality gate in the config to run tests"));
189
+ exit(-1);
190
+ }
191
+ try {
192
+ await rm(config.output, { recursive: true });
193
+ }
194
+ catch (e) {
195
+ if (!isFileNotFoundError(e)) {
196
+ console.error("could not clean output directory", e);
197
+ }
198
+ }
199
+ const allureReport = new AllureReport({
200
+ ...config,
201
+ environment: this.environment,
202
+ stage: this.stage,
203
+ realTime: false,
204
+ plugins: [
205
+ ...(config.plugins?.length
206
+ ? config.plugins
207
+ : [
208
+ {
209
+ id: "awesome",
210
+ enabled: true,
211
+ options: {},
212
+ plugin: new Awesome({
213
+ reportName: config.name,
214
+ }),
215
+ },
216
+ ]),
217
+ ],
218
+ });
219
+ const knownIssues = await allureReport.store.allKnownIssues();
220
+ await allureReport.start();
221
+ const globalExitCode = {
222
+ original: 0,
223
+ actual: undefined,
224
+ };
225
+ let qualityGateResults;
226
+ let testProcessResult = null;
227
+ try {
228
+ testProcessResult = await runTests({
229
+ logs: this.logs,
230
+ silent: this.silent,
231
+ allureReport,
232
+ knownIssues,
233
+ cwd,
234
+ command,
235
+ commandArgs,
236
+ environment: {},
237
+ withQualityGate,
238
+ });
239
+ for (let rerun = 0; rerun < maxRerun; rerun++) {
240
+ const failed = await allureReport.store.failedTestResults();
241
+ if (failed.length === 0) {
242
+ console.log("no failed tests is detected.");
243
+ break;
244
+ }
245
+ const testPlan = createTestPlan(failed);
246
+ console.log(`rerun number ${rerun} of ${testPlan.tests.length} tests:`);
247
+ logTests(failed);
248
+ const tmpDir = await mkdtemp(join(tmpdir(), "allure-run-"));
249
+ const testPlanPath = resolve(tmpDir, `${rerun}-testplan.json`);
250
+ await writeFile(testPlanPath, JSON.stringify(testPlan));
251
+ testProcessResult = await runTests({
252
+ silent: this.silent,
253
+ logs: this.logs,
254
+ allureReport,
255
+ knownIssues,
256
+ cwd,
257
+ command,
258
+ commandArgs,
259
+ environment: {
260
+ ALLURE_TESTPLAN_PATH: testPlanPath,
261
+ ALLURE_RERUN: `${rerun}`,
96
262
  },
97
- ]),
98
- ],
99
- });
100
- await allureReport.start();
101
- await runTests(allureReport, cwd, command, commandArgs, {}, silent);
102
- for (let rerun = 0; rerun < maxRerun; rerun++) {
103
- const failed = await allureReport.store.failedTestResults();
104
- if (failed.length === 0) {
105
- console.log("no failed tests is detected.");
106
- break;
263
+ withQualityGate,
264
+ });
265
+ await rm(tmpDir, { recursive: true });
266
+ logTests(await allureReport.store.allTestResults());
267
+ }
268
+ const trs = await allureReport.store.allTestResults({ includeHidden: false });
269
+ qualityGateResults = testProcessResult?.qualityGateResults ?? [];
270
+ if (withQualityGate && !qualityGateResults?.length) {
271
+ const { results } = await allureReport.validate({
272
+ trs,
273
+ knownIssues,
274
+ });
275
+ qualityGateResults = results;
276
+ }
277
+ if (qualityGateResults?.length) {
278
+ const qualityGateMessage = stringifyQualityGateResults(qualityGateResults);
279
+ console.error(qualityGateMessage);
280
+ allureReport.realtimeDispatcher.sendQualityGateResults(qualityGateResults);
281
+ }
282
+ globalExitCode.original = testProcessResult?.code ?? -1;
283
+ if (withQualityGate) {
284
+ globalExitCode.actual = qualityGateResults.length > 0 ? 1 : 0;
285
+ }
107
286
  }
108
- const testPlan = createTestPlan(failed);
109
- console.log(`rerun number ${rerun} of ${testPlan.tests.length} tests:`);
110
- logTests(failed);
111
- const tmpDir = await mkdtemp(join(tmpdir(), "allure-run-"));
112
- const testPlanPath = resolve(tmpDir, `${rerun}-testplan.json`);
113
- await writeFile(testPlanPath, JSON.stringify(testPlan));
114
- await runTests(allureReport, cwd, command, commandArgs, {
115
- ALLURE_TESTPLAN_PATH: testPlanPath,
116
- ALLURE_RERUN: `${rerun}`,
117
- }, silent);
118
- await rm(tmpDir, { recursive: true });
119
- logTests(await allureReport.store.allTestResults());
287
+ catch (error) {
288
+ globalExitCode.actual = 1;
289
+ if (error instanceof KnownError) {
290
+ console.error(red(error.message));
291
+ allureReport.realtimeDispatcher.sendGlobalError({
292
+ message: error.message,
293
+ });
294
+ }
295
+ else {
296
+ await logError("Failed to run tests using Allure due to unexpected error", error);
297
+ allureReport.realtimeDispatcher.sendGlobalError({
298
+ message: error.message,
299
+ trace: error.stack,
300
+ });
301
+ }
302
+ }
303
+ const processFailed = Math.abs(globalExitCode.actual ?? globalExitCode.original) !== 0;
304
+ if (!this.ignoreLogs && testProcessResult?.stdout) {
305
+ const stdoutResultFile = new BufferResultFile(Buffer.from(testProcessResult.stdout, "utf8"), "stdout.txt");
306
+ stdoutResultFile.contentType = "text/plain";
307
+ allureReport.realtimeDispatcher.sendGlobalAttachment(stdoutResultFile);
308
+ }
309
+ if (!this.ignoreLogs && testProcessResult?.stderr) {
310
+ const stderrResultFile = new BufferResultFile(Buffer.from(testProcessResult.stderr, "utf8"), "stderr.txt");
311
+ stderrResultFile.contentType = "text/plain";
312
+ allureReport.realtimeDispatcher.sendGlobalAttachment(stderrResultFile);
313
+ if (processFailed) {
314
+ allureReport.realtimeDispatcher.sendGlobalError({
315
+ message: "Test process has failed",
316
+ trace: testProcessResult.stderr,
317
+ });
318
+ }
319
+ }
320
+ allureReport.realtimeDispatcher.sendGlobalExitCode(globalExitCode);
321
+ await allureReport.done();
322
+ exit(globalExitCode.actual ?? globalExitCode.original);
120
323
  }
121
- await allureReport.done();
122
- await allureReport.validate();
123
- process.exit(allureReport.exitCode);
124
- };
125
- export const RunCommand = createCommand({
126
- name: "run",
324
+ }
325
+ RunCommand.paths = [["run"]];
326
+ RunCommand.usage = Command.Usage({
127
327
  description: "Run specified command",
128
- options: [
129
- [
130
- "--config, -c <file>",
131
- {
132
- description: "The path Allure config file",
133
- },
134
- ],
135
- [
136
- "--cwd <cwd>",
137
- {
138
- description: "The working directory for the command to run (Default: current working directory)",
139
- },
140
- ],
141
- [
142
- "--output, -o <file>",
143
- {
144
- description: "The output file name, allure.csv by default. Accepts absolute paths (Default: ./allure-report)",
145
- },
146
- ],
147
- [
148
- "--report-name, --name <string>",
149
- {
150
- description: "The report name (Default: Allure Report)",
151
- },
152
- ],
153
- [
154
- "--rerun <number>",
155
- {
156
- description: "The number of reruns for failed tests (Default: 0)",
157
- },
158
- ],
328
+ details: "This command runs the specified command and collects Allure results.",
329
+ examples: [
330
+ ["run -- npm run test", "Run npm run test and collect Allure results"],
331
+ ["run --rerun 3 -- npm run test", "Run npm run test and rerun failed tests up to 3 times"],
159
332
  [
160
- "--silent",
161
- {
162
- description: "Don't pipe the process output logs to console (Default: 0)",
163
- },
333
+ "run --stage=my-stage -- npm run test",
334
+ "Run npm run test and pack inner report state into my-stage.zip archive to restore the state in the next run",
164
335
  ],
165
336
  ],
166
- action: RunCommandAction,
167
337
  });
@@ -1,7 +1,11 @@
1
- type CommandOptions = {
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;
2
8
  token: string;
3
9
  channel: string;
4
- };
5
- export declare const SlackCommandAction: (resultsDir: string, options: CommandOptions) => Promise<void>;
6
- export declare const SlackCommand: (cli: import("cac").CAC) => void;
7
- export {};
10
+ execute(): Promise<void>;
11
+ }
@@ -1,37 +1,61 @@
1
- import { AllureReport, resolveConfig } from "@allure/core";
2
- import { createCommand } from "../utils/commands.js";
3
- export const SlackCommandAction = async (resultsDir, options) => {
4
- const before = new Date().getTime();
5
- const config = await resolveConfig({
6
- plugins: {
7
- "@allure/plugin-slack": {
8
- options,
9
- },
10
- },
11
- });
12
- const allureReport = new AllureReport(config);
13
- await allureReport.start();
14
- await allureReport.readDirectory(resultsDir);
15
- await allureReport.done();
16
- const after = new Date().getTime();
17
- console.log(`the report successfully generated (${after - before}ms)`);
18
- };
19
- export const SlackCommand = createCommand({
20
- name: "slack <resultsDir>",
21
- description: "Posts test results into Slack Channel",
22
- options: [
23
- [
24
- "--token, -t <token>",
1
+ import { AllureReport, readConfig } from "@allurereport/core";
2
+ import SlackPlugin from "@allurereport/plugin-slack";
3
+ import { Command, Option } from "clipanion";
4
+ import * as console from "node:console";
5
+ import { realpath } from "node:fs/promises";
6
+ import process from "node:process";
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 = [
25
35
  {
26
- description: "Slack Bot User OAuth Token",
36
+ id: "slack",
37
+ enabled: true,
38
+ options: defaultSlackOptions,
39
+ plugin: new SlackPlugin(defaultSlackOptions),
27
40
  },
28
- ],
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: [
29
56
  [
30
- "--channel, -c <channel>",
31
- {
32
- description: "Slack channelId",
33
- },
57
+ "slack ./allure-results --token xoxb-token --channel C12345",
58
+ "Post test results from the ./allure-results directory to the specified Slack channel",
34
59
  ],
35
60
  ],
36
- action: SlackCommandAction,
37
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,37 +1,45 @@
1
- import { AllureReport, resolveConfig } from "@allure/core";
1
+ import { AllureReport, resolveConfig } from "@allurereport/core";
2
+ import { Command, Option } from "clipanion";
3
+ import * as console from "node:console";
2
4
  import { basename, dirname, resolve } from "node:path";
3
- import { createCommand } from "../utils/commands.js";
4
- export const TestPlanCommandAction = async (resultsDir, options) => {
5
- const before = new Date().getTime();
6
- const resolved = resolve(options.output ?? "./testplan.json");
7
- const output = dirname(resolved);
8
- const fileName = basename(resolved);
9
- const config = await resolveConfig({
10
- output: output,
11
- plugins: {
12
- "@allure/plugin-testplan": {
13
- 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
+ },
14
24
  },
15
- },
16
- });
17
- const allureReport = new AllureReport(config);
18
- await allureReport.start();
19
- await allureReport.readDirectory(resultsDir);
20
- await allureReport.done();
21
- const after = new Date().getTime();
22
- console.log(`the report successfully generated (${after - before}ms)`);
23
- };
24
- export const TestPlanCommand = createCommand({
25
- 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({
26
36
  description: "Generates testplan.json based on provided Allure Results",
27
- 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"],
28
40
  [
29
- "--output, -o <file>",
30
- {
31
- description: "The output file name. Absolute paths are accepted as well",
32
- default: "testplan.json",
33
- },
41
+ "testplan ./allure-results --output custom-testplan.json",
42
+ "Generate a custom-testplan.json file from the ./allure-results directory",
34
43
  ],
35
44
  ],
36
- action: TestPlanCommandAction,
37
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
+ }