reporting-labs 0.6.16 → 0.6.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.
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.writeReport = writeReport;
37
+ /**
38
+ * Builds the report from finished tests and writes index.html, report.json and (best effort) report.pdf.
39
+ * Shared by the runners that collect tests themselves (WebdriverIO, Cypress); the Playwright reporter has its own.
40
+ */
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ const template_1 = require("./template");
44
+ const mask_1 = require("./mask");
45
+ const pdf_1 = require("./pdf");
46
+ const env_1 = require("./wdio/env");
47
+ /** Writes the report into options.outputFolder (default reporting-labs) and returns the HTML path. */
48
+ async function writeReport(tests, run, options = {}) {
49
+ const outputFolder = options.outputFolder || 'reporting-labs';
50
+ const masker = (0, mask_1.makeMasker)(options.maskKeys || [], { knownValues: options.maskValues || [], fromEnv: options.maskFromEnv !== false });
51
+ const { startTime, endTime, runStatus, workers } = run;
52
+ const stats = { passed: 0, failed: 0, skipped: 0, flaky: 0, timedOut: 0, interrupted: 0, total: tests.length };
53
+ for (const t of tests)
54
+ stats[t.outcome]++;
55
+ const projects = [...new Set(tests.map(t => t.project).filter(Boolean))];
56
+ const base = process.cwd();
57
+ const dims = (options.dimensions ?? ['priority', 'severity', 'feature', 'owner']).map(d => d.toLowerCase());
58
+ const histOn = options.history?.enabled ?? true;
59
+ const histFile = path.resolve(base, options.history?.file ?? 'reporting-labs.history.json');
60
+ let entries = [];
61
+ if (histOn) {
62
+ try {
63
+ entries = JSON.parse(fs.readFileSync(histFile, 'utf8'));
64
+ }
65
+ catch { /* first run */ }
66
+ }
67
+ const failedCount = stats.failed + stats.timedOut + stats.interrupted;
68
+ const code = (o) => o === 'passed' ? 'p' : o === 'flaky' ? 'k' : o === 'skipped' ? 's' : 'f';
69
+ const perTest = {};
70
+ for (const t of tests) {
71
+ const last = t.results[t.results.length - 1];
72
+ perTest[t.key] = [code(t.outcome), Math.round(last?.duration ?? t.duration)];
73
+ }
74
+ const current = {
75
+ time: startTime, duration: endTime - startTime,
76
+ passed: stats.passed, failed: failedCount, flaky: stats.flaky, skipped: stats.skipped, total: stats.total,
77
+ label: options.metadata?.build ?? (0, env_1.ciRunLabel)(process.env) ?? options.metadata?.branch, tests: perTest,
78
+ };
79
+ const history = [...entries, current].slice(-(options.history?.keep ?? 30));
80
+ if (histOn) {
81
+ try {
82
+ fs.writeFileSync(histFile, JSON.stringify(history, null, 1));
83
+ }
84
+ catch { /* read-only fs */ }
85
+ }
86
+ const metadata = Object.fromEntries(Object.entries(options.metadata ?? {}).map(([k, v]) => [k, masker.maskStr(String(v))]));
87
+ const bdd = options.bdd ?? tests.some(t => t.results.some(r => r.steps.some(st => /^(Given|When|Then|And|But)\b/.test(st.title))));
88
+ const data = {
89
+ title: masker.maskStr(options.title ?? 'Test report'),
90
+ generatedAt: Date.now(),
91
+ startTime,
92
+ duration: endTime - startTime,
93
+ metadata,
94
+ projects,
95
+ workers,
96
+ stats,
97
+ tests,
98
+ history,
99
+ bdd,
100
+ rootDir: base,
101
+ env: [...(run.envRows ?? []), ...(0, env_1.collectEnv)(base, Object.fromEntries(Object.entries(options.env ?? {}).map(([k, v]) => [k, masker.maskStr(String(v))])), [...new Set(projects)], workers, options.metadata?.branch)].map(r => ({ ...r, v: masker.maskStr(r.v) })),
102
+ runStatus,
103
+ globalErrors: [],
104
+ globalOutput: [],
105
+ options: {
106
+ logo: options.logo,
107
+ accent: options.accent,
108
+ theme: options.theme ?? 'auto',
109
+ palette: options.palette ?? 'lab',
110
+ embedFonts: options.embedFonts ?? true,
111
+ sections: options.sections ?? [],
112
+ widgets: { runStrip: true, outcome: true, attention: true, dimensions: true, timeline: true, durations: true, tags: true, slowest: true, projects: true, flaky: true, environment: true, skipped: true },
113
+ dimensions: dims,
114
+ dimensionOrder: {
115
+ priority: ['P0', 'P1', 'P2', 'P3', 'P4'],
116
+ severity: ['blocker', 'critical', 'major', 'high', 'medium', 'normal', 'minor', 'low', 'trivial'],
117
+ ...(options.dimensionOrder ?? {}),
118
+ },
119
+ project: options.project,
120
+ links: Object.fromEntries(Object.entries(options.links ?? {}).map(([k, v]) => [k.toLowerCase(), typeof v === 'string' ? v : v.url])),
121
+ customCss: options.customCss ?? '',
122
+ editorLinks: options.editorLinks ?? !process.env.CI,
123
+ expandFailedSteps: options.expandFailedSteps ?? true,
124
+ },
125
+ };
126
+ fs.mkdirSync(outputFolder, { recursive: true });
127
+ const htmlFile = path.join(outputFolder, options.outputFile ?? 'index.html');
128
+ fs.writeFileSync(htmlFile, (0, template_1.renderHtml)(data), 'utf8');
129
+ if (options.emitJson !== false)
130
+ fs.writeFileSync(path.join(outputFolder, options.jsonFile ?? 'report.json'), JSON.stringify(data), 'utf8');
131
+ if (options.announce !== false) {
132
+ console.log(`\n reporting-labs: report written to ${path.relative(process.cwd(), htmlFile)}`);
133
+ }
134
+ if (options.pdf !== false)
135
+ await writePdf(htmlFile, outputFolder, options);
136
+ if (options.announce !== false)
137
+ console.log('');
138
+ return htmlFile;
139
+ }
140
+ /** report.pdf next to the HTML; see writeReportPdf for which browser prints it (an installed Chrome or
141
+ * Edge when the project has no Playwright). Never fails the run. */
142
+ async function writePdf(htmlFile, outputFolder, options) {
143
+ const pdfOpt = typeof options.pdf === 'object' ? options.pdf : {};
144
+ const pdfFile = path.join(outputFolder, pdfOpt.file || 'report.pdf');
145
+ const r = await (0, pdf_1.writeReportPdf)(htmlFile, pdfFile, pdfOpt.chromePath);
146
+ if (options.announce === false)
147
+ return;
148
+ console.log(r.ok ? ` reporting-labs: PDF written to ${path.relative(process.cwd(), pdfFile)}` : ` reporting-labs: PDF skipped — ${r.reason}`);
149
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "reporting-labs",
3
- "version": "0.6.16",
3
+ "version": "0.6.17",
4
4
  "description": "reportingLabs – beautiful, customizable single-file HTML test reports. One line of config. Playwright adapter included, more runners on the way.",
5
5
  "keywords": [
6
6
  "test-report",
@@ -10,6 +10,8 @@
10
10
  "qa",
11
11
  "test-automation",
12
12
  "playwright",
13
+ "cypress",
14
+ "webdriverio",
13
15
  "dashboard"
14
16
  ],
15
17
  "author": "Naveen Khunteta <naveen@naveenautomationlabs.com>",
@@ -33,6 +35,14 @@
33
35
  "./wdio": {
34
36
  "types": "./dist/wdio/index.d.ts",
35
37
  "default": "./dist/wdio/index.js"
38
+ },
39
+ "./cypress": {
40
+ "types": "./dist/cypress/index.d.ts",
41
+ "default": "./dist/cypress/index.js"
42
+ },
43
+ "./cypress/support": {
44
+ "types": "./dist/cypress/support.d.ts",
45
+ "default": "./dist/cypress/support.js"
36
46
  }
37
47
  },
38
48
  "bin": {