reporting-labs 0.6.16 → 0.6.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.
@@ -46,10 +46,7 @@ exports.reportingLabsComplete = reportingLabsComplete;
46
46
  */
47
47
  const fs = __importStar(require("fs"));
48
48
  const path = __importStar(require("path"));
49
- const template_1 = require("../template");
50
- const mask_1 = require("../mask");
51
- const pdf_1 = require("../pdf");
52
- const env_1 = require("./env");
49
+ const write_report_1 = require("../write-report");
53
50
  async function reportingLabsComplete(options = {}) {
54
51
  const outputFolder = options.outputFolder || 'reporting-labs';
55
52
  const partsDir = path.join(outputFolder, '.rl-wdio');
@@ -58,7 +55,6 @@ async function reportingLabsComplete(options = {}) {
58
55
  const files = fs.readdirSync(partsDir).filter(f => f.endsWith('.json'));
59
56
  if (!files.length)
60
57
  return undefined;
61
- const masker = (0, mask_1.makeMasker)(options.maskKeys || [], { knownValues: options.maskValues || [], fromEnv: options.maskFromEnv !== false });
62
58
  const tests = [];
63
59
  let startTime = Number.MAX_SAFE_INTEGER;
64
60
  let endTime = 0;
@@ -85,106 +81,11 @@ async function reportingLabsComplete(options = {}) {
85
81
  startTime = Date.now();
86
82
  if (!endTime)
87
83
  endTime = Date.now();
88
- const stats = { passed: 0, failed: 0, skipped: 0, flaky: 0, timedOut: 0, interrupted: 0, total: tests.length };
89
- for (const t of tests)
90
- stats[t.outcome]++;
91
- const projects = [...new Set(tests.map(t => t.project).filter(Boolean))];
92
- const base = process.cwd();
93
- const dims = (options.dimensions ?? ['priority', 'severity', 'feature', 'owner']).map(d => d.toLowerCase());
94
- const histOn = options.history?.enabled ?? true;
95
- const histFile = path.resolve(base, options.history?.file ?? 'reporting-labs.history.json');
96
- let entries = [];
97
- if (histOn) {
98
- try {
99
- entries = JSON.parse(fs.readFileSync(histFile, 'utf8'));
100
- }
101
- catch { /* first run */ }
102
- }
103
- const failedCount = stats.failed + stats.timedOut + stats.interrupted;
104
- const code = (o) => o === 'passed' ? 'p' : o === 'flaky' ? 'k' : o === 'skipped' ? 's' : 'f';
105
- const perTest = {};
106
- for (const t of tests) {
107
- const last = t.results[t.results.length - 1];
108
- perTest[t.key] = [code(t.outcome), Math.round(last?.duration ?? t.duration)];
109
- }
110
- const current = {
111
- time: startTime, duration: endTime - startTime,
112
- passed: stats.passed, failed: failedCount, flaky: stats.flaky, skipped: stats.skipped, total: stats.total,
113
- label: options.metadata?.build ?? (0, env_1.ciRunLabel)(process.env) ?? options.metadata?.branch, tests: perTest,
114
- };
115
- const history = [...entries, current].slice(-(options.history?.keep ?? 30));
116
- if (histOn) {
117
- try {
118
- fs.writeFileSync(histFile, JSON.stringify(history, null, 1));
119
- }
120
- catch { /* read-only fs */ }
121
- }
122
- const metadata = Object.fromEntries(Object.entries(options.metadata ?? {}).map(([k, v]) => [k, masker.maskStr(String(v))]));
123
- const bdd = options.bdd ?? tests.some(t => t.results.some(r => r.steps.some(st => /^(Given|When|Then|And|But)\b/.test(st.title))));
124
- const data = {
125
- title: masker.maskStr(options.title ?? 'Test report'),
126
- generatedAt: Date.now(),
127
- startTime,
128
- duration: endTime - startTime,
129
- metadata,
130
- projects,
131
- workers,
132
- stats,
133
- tests,
134
- history,
135
- bdd,
136
- rootDir: base,
137
- env: (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) })),
138
- runStatus,
139
- globalErrors: [],
140
- globalOutput: [],
141
- options: {
142
- logo: options.logo,
143
- accent: options.accent,
144
- theme: options.theme ?? 'auto',
145
- palette: options.palette ?? 'lab',
146
- embedFonts: options.embedFonts ?? true,
147
- sections: options.sections ?? [],
148
- 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 },
149
- dimensions: dims,
150
- dimensionOrder: {
151
- priority: ['P0', 'P1', 'P2', 'P3', 'P4'],
152
- severity: ['blocker', 'critical', 'major', 'high', 'medium', 'normal', 'minor', 'low', 'trivial'],
153
- ...(options.dimensionOrder ?? {}),
154
- },
155
- project: options.project,
156
- links: Object.fromEntries(Object.entries(options.links ?? {}).map(([k, v]) => [k.toLowerCase(), typeof v === 'string' ? v : v.url])),
157
- customCss: options.customCss ?? '',
158
- editorLinks: options.editorLinks ?? !process.env.CI,
159
- expandFailedSteps: options.expandFailedSteps ?? true,
160
- },
161
- };
162
- fs.mkdirSync(outputFolder, { recursive: true });
163
- const htmlFile = path.join(outputFolder, options.outputFile ?? 'index.html');
164
- fs.writeFileSync(htmlFile, (0, template_1.renderHtml)(data), 'utf8');
165
- if (options.emitJson !== false)
166
- fs.writeFileSync(path.join(outputFolder, options.jsonFile ?? 'report.json'), JSON.stringify(data), 'utf8');
167
- // tidy the partials
84
+ // the partials are only needed for this report
85
+ const htmlFile = await (0, write_report_1.writeReport)(tests, { startTime, endTime, runStatus, workers }, options);
168
86
  try {
169
87
  fs.rmSync(partsDir, { recursive: true, force: true });
170
88
  }
171
89
  catch { /* leave them */ }
172
- if (options.announce !== false) {
173
- console.log(`\n reporting-labs: report written to ${path.relative(process.cwd(), htmlFile)}`);
174
- }
175
- if (options.pdf !== false)
176
- await writePdf(htmlFile, outputFolder, options);
177
- if (options.announce !== false)
178
- console.log('');
179
90
  return htmlFile;
180
91
  }
181
- /** report.pdf next to the HTML; see writeReportPdf for which browser prints it (an installed Chrome or
182
- * Edge when the project has no Playwright). Never fails the run. */
183
- async function writePdf(htmlFile, outputFolder, options) {
184
- const pdfOpt = typeof options.pdf === 'object' ? options.pdf : {};
185
- const pdfFile = path.join(outputFolder, pdfOpt.file || 'report.pdf');
186
- const r = await (0, pdf_1.writeReportPdf)(htmlFile, pdfFile, pdfOpt.chromePath);
187
- if (options.announce === false)
188
- return;
189
- console.log(r.ok ? ` reporting-labs: PDF written to ${path.relative(process.cwd(), pdfFile)}` : ` reporting-labs: PDF skipped — ${r.reason}`);
190
- }
@@ -0,0 +1,51 @@
1
+ import type { TestData, EnvRow } from './types';
2
+ export interface WriteReportOptions {
3
+ outputFolder?: string;
4
+ outputFile?: string;
5
+ jsonFile?: string;
6
+ emitJson?: boolean;
7
+ pdf?: boolean | {
8
+ file?: string;
9
+ chromePath?: string;
10
+ };
11
+ title?: string;
12
+ logo?: string;
13
+ accent?: string;
14
+ theme?: 'auto' | 'light' | 'dark';
15
+ palette?: 'lab' | 'ocean' | 'ember' | 'mono';
16
+ metadata?: Record<string, string>;
17
+ env?: Record<string, string>;
18
+ sections?: {
19
+ title: string;
20
+ html: string;
21
+ }[];
22
+ customCss?: string;
23
+ dimensions?: string[];
24
+ dimensionOrder?: Record<string, string[]>;
25
+ project?: unknown;
26
+ links?: Record<string, unknown>;
27
+ bdd?: boolean;
28
+ announce?: boolean;
29
+ history?: {
30
+ enabled?: boolean;
31
+ file?: string;
32
+ keep?: number;
33
+ };
34
+ maskKeys?: string[];
35
+ maskValues?: string[];
36
+ maskFromEnv?: boolean;
37
+ embedFonts?: boolean;
38
+ editorLinks?: boolean;
39
+ expandFailedSteps?: boolean;
40
+ }
41
+ /** Run-level facts the runner knows. */
42
+ export interface RunInfo {
43
+ startTime: number;
44
+ endTime: number;
45
+ runStatus: 'passed' | 'failed';
46
+ workers: number;
47
+ /** Rows shown first on the Environment card, e.g. the Cypress version and browser. */
48
+ envRows?: EnvRow[];
49
+ }
50
+ /** Writes the report into options.outputFolder (default reporting-labs) and returns the HTML path. */
51
+ export declare function writeReport(tests: TestData[], run: RunInfo, options?: WriteReportOptions): Promise<string>;
@@ -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.18",
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,10 @@
10
10
  "qa",
11
11
  "test-automation",
12
12
  "playwright",
13
+ "cypress",
14
+ "webdriverio",
15
+ "cucumber",
16
+ "bdd",
13
17
  "dashboard"
14
18
  ],
15
19
  "author": "Naveen Khunteta <naveen@naveenautomationlabs.com>",
@@ -33,6 +37,14 @@
33
37
  "./wdio": {
34
38
  "types": "./dist/wdio/index.d.ts",
35
39
  "default": "./dist/wdio/index.js"
40
+ },
41
+ "./cypress": {
42
+ "types": "./dist/cypress/index.d.ts",
43
+ "default": "./dist/cypress/index.js"
44
+ },
45
+ "./cypress/support": {
46
+ "types": "./dist/cypress/support.d.ts",
47
+ "default": "./dist/cypress/support.js"
36
48
  }
37
49
  },
38
50
  "bin": {