@allurereport/plugin-log 3.0.0-beta.10

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.
package/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # Log Plugin
2
+
3
+ [<img src="https://allurereport.org/public/img/allure-report.svg" height="85px" alt="Allure Report logo" align="right" />](https://allurereport.org "Allure Report")
4
+
5
+ - Learn more about Allure Report at https://allurereport.org
6
+ - 📚 [Documentation](https://allurereport.org/docs/) – discover official documentation for Allure Report
7
+ - ❓ [Questions and Support](https://github.com/orgs/allure-framework/discussions/categories/questions-support) – get help from the team and community
8
+ - 📢 [Official announcements](https://github.com/orgs/allure-framework/discussions/categories/announcements) – be in touch with the latest updates
9
+ - 💬 [General Discussion ](https://github.com/orgs/allure-framework/discussions/categories/general-discussion) – engage in casual conversations, share insights and ideas with the community
10
+
11
+ ---
12
+
13
+ ## Overview
14
+
15
+ This plugin prints report in the terminal.
16
+
17
+ ## Install
18
+
19
+ Use your favorite package manager to install the package:
20
+
21
+ ```shell
22
+ npm add @allurereport/plugin-log
23
+ yarn add @allurereport/plugin-log
24
+ pnpm add @allurereport/plugin-log
25
+ ```
26
+
27
+ Then, add the plugin to the Allure configuration file:
28
+
29
+ ```diff
30
+ import { defineConfig } from "allure";
31
+
32
+ export default defineConfig({
33
+ name: "Allure Report",
34
+ output: "./allure-report",
35
+ historyPath: "./history.jsonl",
36
+ plugins: {
37
+ + log: {
38
+ + options: {
39
+ + },
40
+ + },
41
+ },
42
+ });
43
+ ```
44
+
45
+ ## Options
46
+
47
+ The plugin accepts the following options:
48
+
49
+ | Option | Description | Type | Default |
50
+ |-------------|----------------------------------|------------------------------------------|---------|
51
+ | `allSteps` | Include all steps in the report | `boolean` | `false` |
52
+ | `withTrace` | Include step trace in the report | `boolean` | `false` |
53
+ | `groupBy` | Group tests by given label | `suites \| features \| packages \| none` | `none` |
54
+
@@ -0,0 +1,2 @@
1
+ import { LogPlugin } from "./plugin.js";
2
+ export default LogPlugin;
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ import { LogPlugin } from "./plugin.js";
2
+ export default LogPlugin;
@@ -0,0 +1,5 @@
1
+ export type LogPluginOptions = {
2
+ allSteps?: boolean;
3
+ withTrace?: boolean;
4
+ groupBy?: "suites" | "features" | "packages" | "none";
5
+ };
package/dist/model.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import type { AllureStore, Plugin, PluginContext } from "@allurereport/plugin-api";
2
+ import type { LogPluginOptions } from "./model.js";
3
+ export declare class LogPlugin implements Plugin {
4
+ readonly options: LogPluginOptions;
5
+ constructor(options?: LogPluginOptions);
6
+ done: (context: PluginContext, store: AllureStore) => Promise<void>;
7
+ }
package/dist/plugin.js ADDED
@@ -0,0 +1,38 @@
1
+ import * as console from "node:console";
2
+ import { gray } from "yoctocolors";
3
+ import { printSummary, printTest } from "./utils.js";
4
+ export class LogPlugin {
5
+ constructor(options = {}) {
6
+ this.options = options;
7
+ this.done = async (context, store) => {
8
+ const { groupBy = "suite" } = this.options ?? {};
9
+ const allTestResults = await store.allTestResults();
10
+ if (groupBy === "none") {
11
+ allTestResults.forEach((test) => {
12
+ printTest(test, this.options);
13
+ });
14
+ console.log("");
15
+ printSummary(Array.from(allTestResults));
16
+ return;
17
+ }
18
+ const groupedTests = await store.testResultsByLabel(groupBy);
19
+ Object.keys(groupedTests).forEach((key) => {
20
+ const tests = groupedTests[key];
21
+ if (tests.length === 0) {
22
+ return;
23
+ }
24
+ if (key === "_") {
25
+ console.info(gray("uncategorized"));
26
+ }
27
+ else {
28
+ console.info(key);
29
+ }
30
+ tests.forEach((test) => {
31
+ printTest(test, this.options, 1);
32
+ });
33
+ console.log("");
34
+ });
35
+ printSummary(Array.from(allTestResults));
36
+ };
37
+ }
38
+ }
@@ -0,0 +1,11 @@
1
+ import type { DefaultTestStepResult, TestResult, TestStatus, TestStepResult } from "@allurereport/core-api";
2
+ import type { LogPluginOptions } from "./model.js";
3
+ export type PrintFunctionOptions = Pick<LogPluginOptions, "allSteps" | "groupBy" | "withTrace">;
4
+ export declare const isFailedResult: (result: TestResult | TestStepResult) => boolean;
5
+ export declare const hasResultFailedSteps: (result: TestResult | TestStepResult) => boolean;
6
+ export declare const stringifyStatusBadge: (status: TestStatus) => string;
7
+ export declare const stringifyTestResultTitle: (result: TestResult) => string;
8
+ export declare const stringifyStepResultTitle: (result: DefaultTestStepResult) => string;
9
+ export declare const printTest: (test: TestResult, options?: PrintFunctionOptions, indent?: number) => void;
10
+ export declare const printStep: (step: DefaultTestStepResult, options?: PrintFunctionOptions, indent?: number) => void;
11
+ export declare const printSummary: (results: TestResult[]) => void;
package/dist/utils.js ADDED
@@ -0,0 +1,136 @@
1
+ import { isStep } from "@allurereport/core-api";
2
+ import console from "node:console";
3
+ import { gray, green, red, yellow } from "yoctocolors";
4
+ export const isFailedResult = (result) => {
5
+ if ("status" in result) {
6
+ return result.status === "failed" || result.status === "broken";
7
+ }
8
+ return false;
9
+ };
10
+ export const hasResultFailedSteps = (result) => {
11
+ if (!("steps" in result)) {
12
+ return false;
13
+ }
14
+ return result.steps?.some((step) => {
15
+ if (isFailedResult(step)) {
16
+ return true;
17
+ }
18
+ if (step.type === "step" && step?.steps) {
19
+ return hasResultFailedSteps(step);
20
+ }
21
+ return false;
22
+ });
23
+ };
24
+ export const stringifyStatusBadge = (status) => {
25
+ switch (status) {
26
+ case "passed":
27
+ return green("✓");
28
+ case "failed":
29
+ return red("⨯");
30
+ case "broken":
31
+ return red("⨯");
32
+ case "skipped":
33
+ return gray("-");
34
+ case "unknown":
35
+ return gray("?");
36
+ }
37
+ };
38
+ export const stringifyTestResultTitle = (result) => {
39
+ const status = stringifyStatusBadge(result.status);
40
+ const name = result.name;
41
+ const duration = result.duration ? `${yellow(`${result.duration}ms`)}` : "";
42
+ return [status, name, duration].filter(Boolean).join(" ");
43
+ };
44
+ export const stringifyStepResultTitle = (result) => {
45
+ const status = stringifyStatusBadge(result.status);
46
+ const duration = result.duration ? `${yellow(`${result.duration}ms`)}` : "";
47
+ return [status, result.name, duration].filter(Boolean).join(" ");
48
+ };
49
+ export const printTest = (test, options, indent = 0) => {
50
+ const title = stringifyTestResultTitle(test);
51
+ const stepsToPrint = options?.allSteps ? test.steps.filter(isStep) : test.steps.filter(isFailedResult).filter(isStep);
52
+ const failedResult = isFailedResult(test);
53
+ const indentSpaces = " ".repeat(indent);
54
+ console.info(`${indentSpaces}${title}`);
55
+ if (failedResult && test.error?.message) {
56
+ console.info(`${indentSpaces} ${red(test.error.message)}`);
57
+ }
58
+ if (options?.withTrace && failedResult && test.error?.trace) {
59
+ test.error.trace.split("\n").forEach((line) => {
60
+ console.info(`${indentSpaces} ${gray(line)}`);
61
+ });
62
+ }
63
+ if (!stepsToPrint?.length) {
64
+ return;
65
+ }
66
+ stepsToPrint.forEach((step) => {
67
+ printStep(step, options, indent + 1);
68
+ });
69
+ };
70
+ export const printStep = (step, options, indent = 0) => {
71
+ const title = stringifyStepResultTitle(step);
72
+ const stepsToPrint = (options?.allSteps ? step.steps.filter(isStep) : step.steps?.filter(isStep).filter(isFailedResult)) || [];
73
+ const indentSpaces = " ".repeat(indent);
74
+ const failedResult = isFailedResult(step);
75
+ console.info(`${indentSpaces}${title}`);
76
+ if (failedResult && step.error?.message) {
77
+ console.info(` ${indentSpaces}${red(step.error?.message)}`);
78
+ }
79
+ if (options?.withTrace && failedResult && step.error?.trace) {
80
+ step.error.trace.split("\n").forEach((line) => {
81
+ console.info(` ${indentSpaces}${gray(line)}`);
82
+ });
83
+ }
84
+ if (!stepsToPrint?.length) {
85
+ return;
86
+ }
87
+ stepsToPrint.forEach((child) => {
88
+ printStep(child, options, indent + 1);
89
+ });
90
+ };
91
+ export const printSummary = (results) => {
92
+ const statsCounters = {
93
+ passed: 0,
94
+ failed: 0,
95
+ broken: 0,
96
+ skipped: 0,
97
+ };
98
+ let totalDuration = 0;
99
+ results.forEach((test) => {
100
+ totalDuration += test.duration || 0;
101
+ switch (test.status) {
102
+ case "passed":
103
+ statsCounters.passed++;
104
+ break;
105
+ case "failed":
106
+ statsCounters.failed++;
107
+ break;
108
+ case "broken":
109
+ statsCounters.broken++;
110
+ break;
111
+ case "skipped":
112
+ statsCounters.skipped++;
113
+ break;
114
+ }
115
+ });
116
+ const stringifiedCounters = [];
117
+ if (statsCounters.passed > 0) {
118
+ stringifiedCounters.push(green(`${statsCounters.passed} passed`));
119
+ }
120
+ if (statsCounters.failed > 0) {
121
+ stringifiedCounters.push(red(`${statsCounters.failed} failed`));
122
+ }
123
+ if (statsCounters.broken > 0) {
124
+ stringifiedCounters.push(red(`${statsCounters.broken} broken`));
125
+ }
126
+ if (statsCounters.skipped > 0) {
127
+ stringifiedCounters.push(yellow(`${statsCounters.skipped} skipped`));
128
+ }
129
+ if (results.length === 0) {
130
+ console.info("No test results found to show");
131
+ return;
132
+ }
133
+ console.info(`Total tests: ${results.length}`);
134
+ console.info(`Tests: ${stringifiedCounters.join(" | ")}`);
135
+ console.info(`Duration: ${yellow((totalDuration / 1000).toString())}s`);
136
+ };
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@allurereport/plugin-log",
3
+ "version": "3.0.0-beta.10",
4
+ "description": "Allure Plugin to write report in stdout",
5
+ "keywords": [
6
+ "allure",
7
+ "testing",
8
+ "report",
9
+ "plugin",
10
+ "cli",
11
+ "stdout"
12
+ ],
13
+ "repository": "https://github.com/allure-framework/allure3",
14
+ "license": "Apache-2.0",
15
+ "author": "Qameta Software",
16
+ "type": "module",
17
+ "exports": {
18
+ ".": "./dist/index.js"
19
+ },
20
+ "main": "./dist/index.js",
21
+ "module": "./dist/index.js",
22
+ "types": "./dist/index.d.ts",
23
+ "files": [
24
+ "./dist"
25
+ ],
26
+ "scripts": {
27
+ "build": "run clean && tsc --project ./tsconfig.json",
28
+ "clean": "rimraf ./dist",
29
+ "eslint": "eslint ./src/**/*.{js,jsx,ts,tsx}",
30
+ "eslint:format": "eslint --fix ./src/**/*.{js,jsx,ts,tsx}",
31
+ "test": "rimraf ./out && vitest run"
32
+ },
33
+ "dependencies": {
34
+ "@allurereport/core-api": "3.0.0-beta.10",
35
+ "@allurereport/plugin-api": "3.0.0-beta.10",
36
+ "yoctocolors": "^2.1.1"
37
+ },
38
+ "devDependencies": {
39
+ "@stylistic/eslint-plugin": "^2.6.1",
40
+ "@types/eslint": "^8.56.11",
41
+ "@types/node": "^20.17.9",
42
+ "@typescript-eslint/eslint-plugin": "^8.0.0",
43
+ "@typescript-eslint/parser": "^8.0.0",
44
+ "@vitest/runner": "^2.1.8",
45
+ "@vitest/snapshot": "^2.1.8",
46
+ "allure-vitest": "^3.0.9",
47
+ "eslint": "^8.57.0",
48
+ "eslint-config-prettier": "^9.1.0",
49
+ "eslint-plugin-import": "^2.29.1",
50
+ "eslint-plugin-jsdoc": "^50.0.0",
51
+ "eslint-plugin-n": "^17.10.1",
52
+ "eslint-plugin-no-null": "^1.0.2",
53
+ "eslint-plugin-prefer-arrow": "^1.2.3",
54
+ "rimraf": "^6.0.1",
55
+ "typescript": "^5.6.3",
56
+ "vitest": "^2.1.8"
57
+ }
58
+ }