reporting-labs 0.6.11 → 0.6.13

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 CHANGED
@@ -1,12 +1,20 @@
1
1
  <p align="center"><img src="https://raw.githubusercontent.com/naveenautomationlabs/reporting-labs/main/assets/logo-wordmark.svg" alt="reportingLabs" width="320"></p>
2
2
 
3
+ <p align="center">
4
+ <a href="https://www.npmjs.com/package/reporting-labs"><img src="https://img.shields.io/npm/v/reporting-labs.svg?label=npm" alt="npm"></a>
5
+ <a href="https://reportinglabs.dev"><img src="https://img.shields.io/badge/docs-reportinglabs.dev-1A56DB.svg" alt="Docs"></a>
6
+ <a href="https://reportinglabs.dev/support"><img src="https://img.shields.io/badge/%E2%99%A5%20Support-reportingLabs-E5405E?style=flat" alt="Support reportingLabs"></a>
7
+ </p>
8
+
3
9
  # reportingLabs
4
10
 
5
11
  **A beautiful test report in one HTML file. It tells you what broke, who owns it, and whether it is new.**
6
12
 
7
13
  reportingLabs turns a test run into a single HTML file. No server. No upload. No login. Open the file in a browser, attach it to a CI job, or send it on Slack or email. It just works.
8
14
 
9
- Today it ships with a **Playwright** reporter. WebdriverIO, Cypress and Jest/Vitest are on the roadmap.
15
+ Today it ships with a **Playwright** reporter and a **WebdriverIO** reporter. Cypress and Jest/Vitest are on the roadmap. The same report is also available for [Java](https://github.com/naveenautomationlabs/reporting-labs-java) and [Python](https://github.com/naveenautomationlabs/reporting-labs-python).
16
+
17
+ > ♥ **Free and open source, no paid tier.** If reportingLabs saves your team time, [support its development](https://reportinglabs.dev/support) (Razorpay for India, Stripe for everywhere else). A ⭐ on GitHub helps too.
10
18
 
11
19
  <p align="center"><img src="https://raw.githubusercontent.com/naveenautomationlabs/reporting-labs/main/docs/quickstart.gif" alt="reportingLabs in three steps: install, tag your tests, open one HTML file" width="900"></p>
12
20
 
@@ -113,6 +121,28 @@ One line per test. With this the report can rank failures by priority, group the
113
121
  - Forgot one? After every run the console lists the tests that have no `meta()`, with file and line. Turn it off with `warnMissingMeta: false`.
114
122
  - `priority`, `severity`, `feature` and `owner` each get a tab in the Breakdown chart and a filter on the Tests page. Want the same for your own key, say `meta({ team: 'web' })`? Add it to `dimensions` in the config: `dimensions: ['priority', 'severity', 'feature', 'owner', 'team']`.
115
123
 
124
+ ### Or write it as a comment (no code change)
125
+
126
+ `meta()` stays the main way. If your team prefers not to add calls to the tests, the same meta can sit in a comment right above the test or `test.describe`:
127
+
128
+ ```ts
129
+ /**
130
+ * Completes a purchase with a saved card.
131
+ * @priority P0 @owner naveen @feature payment @story SHOP-250
132
+ * @smoke
133
+ */
134
+ test('completes purchase', async ({ page }) => {
135
+ // ... your test as usual, no meta() needed
136
+ });
137
+ ```
138
+
139
+ - `@key value` pairs become meta (known keys, plus keys in `dimensions` or `links`). A line of bare `@words` (` * @smoke @regression`) becomes tags, so `@P0` and `@critical` still set priority and severity; a mention inside a sentence ("reported by @naveen") is ignored.
140
+ - A comment above `test.describe` applies to every test inside; the test's own comment wins over it.
141
+ - If a test has both, **`meta()` wins** over the comment.
142
+ - Only a comment touching the test counts: a file header separated by a blank line is ignored, and so are JSDoc tags like `@param`.
143
+ - Works with the WebdriverIO reporter too (above `it()` / `describe()`). Turn it off with `commentMeta: false`.
144
+ - **Snippets:** `npx reporting-labs snippets` adds VS Code snippets, so you type `rlmeta` (or `rltest`, `rlit`, `rldescribe`) and press Tab instead of writing the comment by hand. `init` adds them too.
145
+
116
146
  ### `log()`: a line in the report
117
147
 
118
148
  ```ts
@@ -328,7 +358,7 @@ Every option is optional. `npx reporting-labs init` writes them all, with commen
328
358
  | `embedVideos` | `false` | Videos inside the HTML too (bigger file, no folder issues) |
329
359
  | `emitJson` | `true` | Also write `report.json` alongside `index.html` (used by `merge`) |
330
360
  | `jsonFile` | `'report.json'` | File name of the JSON blob |
331
- | `pdf` | `true` | Also write `report.pdf` (light theme, print-ready) with Playwright's Chromium. `false` turns it off; `{ file: 'run.pdf' }` renames it. The Export PDF button in the report works either way |
361
+ | `pdf` | `true` | Also write `report.pdf` (light theme, print-ready), printed by Playwright's Chromium or an installed Chrome / Edge, whatever browser the tests ran on. `false` turns it off; `{ file: 'run.pdf' }` renames it; `{ chromePath }` (or `CHROME_PATH`) names the browser. The Export PDF button in the report works either way |
332
362
  | `embedFonts` | `true` | Bundle the fonts (~140 KB) so it looks the same offline |
333
363
  | `announce` | `true` | Print the report path after the run |
334
364
  | `open` | `'on-failure'` | Open the report in the browser after the run: `'on-failure'`, `'always'` or `'never'`. Never opens in CI |
package/bin/cli.js CHANGED
@@ -5,10 +5,21 @@ const args = process.argv.slice(2);
5
5
  const cmd = args[0];
6
6
  const has = f => args.includes(f);
7
7
 
8
+ /** Editor snippets (rlmeta, rltest, rlit, rldescribe) in .vscode/, so meta comments are one word + Tab away. */
9
+ function writeSnippets(force) {
10
+ const file = path.resolve('.vscode', 'reporting-labs.code-snippets');
11
+ if (fs.existsSync(file) && !force) return `.vscode/reporting-labs.code-snippets already exists (use --force to replace it).`;
12
+ fs.mkdirSync(path.dirname(file), { recursive: true });
13
+ fs.copyFileSync(path.join(__dirname, 'snippets.code-snippets'), file);
14
+ return 'Created .vscode/reporting-labs.code-snippets: in VS Code type rlmeta, rltest, rlit or rldescribe and press Tab.';
15
+ }
16
+
8
17
  if (cmd === 'merge') {
9
18
  const { merge, parseArgs } = require('./merge');
10
19
  const { dirs, opts } = parseArgs(args.slice(1));
11
20
  merge(dirs, opts);
21
+ } else if (cmd === 'snippets') {
22
+ console.log(writeSnippets(has('--force')));
12
23
  } else if (cmd === 'init') {
13
24
  const js = has('--js');
14
25
  const file = path.resolve(js ? 'reporting-labs.config.js' : 'reporting-labs.config.ts');
@@ -35,12 +46,14 @@ if (cmd === 'merge') {
35
46
  console.log(` import reportingLabs from './${base}';`);
36
47
  }
37
48
  console.log(" reporter: [['list'], ['reporting-labs', reportingLabs]],");
49
+ if (!has('--no-snippets')) { console.log(''); console.log(writeSnippets(false)); }
38
50
  } else {
39
51
  console.log(`reporting-labs
40
52
 
41
53
  npx reporting-labs init write reporting-labs.config.ts with every option, commented
42
54
  npx reporting-labs init --js same, as reporting-labs.config.js
43
55
  npx reporting-labs init --force overwrite an existing config file
56
+ npx reporting-labs snippets add VS Code snippets: rlmeta, rltest, rlit, rldescribe (meta comments)
44
57
  npx reporting-labs merge <dirs> combine several shard runs into one report (see 'merge --help')
45
58
 
46
59
  Then in playwright.config.ts:
@@ -38,6 +38,8 @@ const config: ReportingLabsOptions = {
38
38
  // announce: true, // print the report path after the run
39
39
  // open: 'on-failure', // open the report in the browser: 'on-failure' | 'always' | 'never'; never in CI
40
40
  // warnMissingMeta: true, // after the run, list tests that have no meta() in the console
41
+ // commentMeta: true, // read meta from a comment above a test: /** @owner naveen @priority P0 */ (meta() wins)
42
+ // pdf: true, // also write a print-ready report.pdf (false to skip, { file } to rename, { chromePath } to name the browser)
41
43
 
42
44
  // ── Test details ─────────────────────────────────────────────────────────────
43
45
  // Values come from meta({ priority, severity, owner, feature, epic, story, ... }) in your tests.
@@ -0,0 +1,78 @@
1
+ {
2
+ "reportingLabs: meta comment": {
3
+ "scope": "javascript,typescript,javascriptreact,typescriptreact",
4
+ "prefix": ["rlmeta", "/**rl"],
5
+ "description": "reportingLabs meta as a comment above a test or describe",
6
+ "body": [
7
+ "/**",
8
+ " * @priority ${1|P0,P1,P2,P3,P4|} @owner ${2:name} @feature ${3:area}",
9
+ " * @story ${4:SHOP-123}",
10
+ " */"
11
+ ]
12
+ },
13
+ "reportingLabs: Playwright test with meta": {
14
+ "scope": "javascript,typescript,javascriptreact,typescriptreact",
15
+ "prefix": "rltest",
16
+ "description": "A Playwright test with reportingLabs meta in a comment",
17
+ "body": [
18
+ "/**",
19
+ " * @priority ${1|P0,P1,P2,P3,P4|} @owner ${2:name} @feature ${3:area}",
20
+ " * @story ${4:SHOP-123}",
21
+ " */",
22
+ "test('${5:does something}', async ({ page }) => {",
23
+ "\t$0",
24
+ "});"
25
+ ]
26
+ },
27
+ "reportingLabs: WebdriverIO it() with meta": {
28
+ "scope": "javascript,typescript",
29
+ "prefix": "rlit",
30
+ "description": "A WebdriverIO / Mocha test with reportingLabs meta in a comment",
31
+ "body": [
32
+ "/**",
33
+ " * @priority ${1|P0,P1,P2,P3,P4|} @owner ${2:name} @feature ${3:area}",
34
+ " * @story ${4:SHOP-123}",
35
+ " */",
36
+ "it('${5:does something}', async () => {",
37
+ "\t$0",
38
+ "});"
39
+ ]
40
+ },
41
+ "reportingLabs: describe with meta": {
42
+ "scope": "javascript,typescript,javascriptreact,typescriptreact",
43
+ "prefix": "rldescribe",
44
+ "description": "A describe block whose meta applies to every test inside",
45
+ "body": [
46
+ "/** @owner ${1:name} @feature ${2:area} */",
47
+ "${3|test.describe,describe|}('${4:Feature}', () => {",
48
+ "\t$0",
49
+ "});"
50
+ ]
51
+ },
52
+ "reportingLabs: meta in a docstring": {
53
+ "scope": "python",
54
+ "prefix": "rlmeta",
55
+ "description": "reportingLabs meta in a test docstring",
56
+ "body": [
57
+ "\"\"\"${1:What this test checks}.",
58
+ "",
59
+ "@priority ${2|P0,P1,P2,P3,P4|} @owner ${3:name} @feature ${4:area}",
60
+ "@story ${5:SHOP-123}",
61
+ "\"\"\""
62
+ ]
63
+ },
64
+ "reportingLabs: pytest test with meta": {
65
+ "scope": "python",
66
+ "prefix": "rltest",
67
+ "description": "A pytest test with reportingLabs meta in its docstring",
68
+ "body": [
69
+ "def test_${1:does_something}(${2:page}):",
70
+ "\t\"\"\"${3:What this test checks}.",
71
+ "",
72
+ "\t@priority ${4|P0,P1,P2,P3,P4|} @owner ${5:name} @feature ${6:area}",
73
+ "\t@story ${7:SHOP-123}",
74
+ "\t\"\"\"",
75
+ "\t$0"
76
+ ]
77
+ }
78
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Meta written as a comment right above a test or describe, so a team can tag tests without calling meta():
3
+ *
4
+ * /**
5
+ * * @owner naveen @priority P0 @jira SHOP-12
6
+ * * @smoke
7
+ * *\/
8
+ * test('places an order', async ({ page }) => { ... });
9
+ *
10
+ * `@key value` pairs become meta; a bare `@word` on a line of tags becomes a tag (so `@P0` / `@critical` still set
11
+ * priority and severity), while a mention inside a sentence ("reported by @naveen") is ignored. Only a comment that
12
+ * starts its own line and touches the test line counts: a file header separated by a blank line does not.
13
+ * JSDoc's own tags (@param, @returns, @ts-ignore...) are ignored.
14
+ */
15
+ export interface CommentMeta {
16
+ meta: Record<string, string>;
17
+ tags: string[];
18
+ }
19
+ /** The text of the comment that ends on the line just above `line` (1-based), or ''. */
20
+ export declare function commentAbove(file: string, line: number): string;
21
+ /** `@key value` pairs and bare `@tags` in a comment's text. A value runs to the next ` @key` or the end of the line. */
22
+ export declare function parseCommentMeta(text: string): CommentMeta;
23
+ /** Comment meta for one location, or empty. */
24
+ export declare function commentMetaAt(file: string, line: number): CommentMeta;
25
+ /** Find the line of `it('title'` / `test("title"` / `describe(`title`` in a file (WebdriverIO gives no line). */
26
+ export declare function lineOfTitle(file: string, title: string, kinds?: string, after?: number): number;
@@ -0,0 +1,125 @@
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.commentAbove = commentAbove;
37
+ exports.parseCommentMeta = parseCommentMeta;
38
+ exports.commentMetaAt = commentMetaAt;
39
+ exports.lineOfTitle = lineOfTitle;
40
+ const fs = __importStar(require("fs"));
41
+ const JSDOC = new Set(['param', 'arg', 'argument', 'returns', 'return', 'type', 'typedef', 'template', 'example', 'see', 'link',
42
+ 'throws', 'exception', 'deprecated', 'since', 'callback', 'property', 'prop', 'override', 'private', 'public', 'protected',
43
+ 'readonly', 'async', 'function', 'func', 'method', 'class', 'constructor', 'module', 'namespace', 'memberof', 'inheritdoc',
44
+ 'default', 'description', 'summary', 'version', 'license', 'file', 'fileoverview', 'internal', 'ignore', 'satisfies', 'jsx',
45
+ 'flow', 'format', 'vitest-environment', 'jest-environment']);
46
+ const sources = new Map();
47
+ function linesOf(file) {
48
+ if (!sources.has(file)) {
49
+ try {
50
+ sources.set(file, fs.readFileSync(file, 'utf8').split(/\r?\n/));
51
+ }
52
+ catch {
53
+ sources.set(file, null);
54
+ }
55
+ }
56
+ return sources.get(file) ?? null;
57
+ }
58
+ /** The text of the comment that ends on the line just above `line` (1-based), or ''. */
59
+ function commentAbove(file, line) {
60
+ const lines = linesOf(file);
61
+ if (!lines || line < 2)
62
+ return '';
63
+ let i = line - 2;
64
+ const at = (k) => (lines[k] ?? '').trim();
65
+ if (at(i).endsWith('*/')) {
66
+ const end = i;
67
+ while (i >= 0 && !at(i).includes('/*'))
68
+ i--;
69
+ if (i < 0 || !at(i).startsWith('/*'))
70
+ return ''; // `foo(); /* x */` belongs to the code, not the test
71
+ return lines.slice(i, end + 1).join('\n')
72
+ .replace(/^\s*\/\*+/, '').replace(/\*+\/\s*$/, '')
73
+ .split('\n').map(l => l.replace(/^\s*\*+ ?/, '')).join('\n');
74
+ }
75
+ if (at(i).startsWith('//')) {
76
+ const out = [];
77
+ while (i >= 0 && at(i).startsWith('//')) {
78
+ out.unshift(at(i).replace(/^\/\/+\s?/, ''));
79
+ i--;
80
+ }
81
+ return out.join('\n');
82
+ }
83
+ return '';
84
+ }
85
+ /** `@key value` pairs and bare `@tags` in a comment's text. A value runs to the next ` @key` or the end of the line. */
86
+ function parseCommentMeta(text) {
87
+ const meta = {};
88
+ const tags = [];
89
+ for (const line of text.split('\n')) {
90
+ // a bare @word is a tag only on a line of tags (` * @smoke @regression`), never a mention in a sentence
91
+ const tagLine = line.trim().startsWith('@');
92
+ const re = /(?:^|\s)@([A-Za-z][\w.-]*)(?:[ \t]*[:=][ \t]*|[ \t]+(?!@))?(.*?)(?=\s+@[A-Za-z][\w.-]*|$)/g;
93
+ let m;
94
+ while ((m = re.exec(line))) {
95
+ const key = m[1];
96
+ if (JSDOC.has(key.toLowerCase()) || /^(ts-|eslint|jsx|prettier)/i.test(key))
97
+ continue;
98
+ // `@owner 'naveen'` / `@feature "Cart and checkout"`: the quotes are not part of the value
99
+ const value = m[2].trim().replace(/^(['"`])(.*)\1$/, '$2').trim();
100
+ if (value)
101
+ meta[key.toLowerCase()] = value;
102
+ else if (tagLine && !tags.includes('@' + key))
103
+ tags.push('@' + key);
104
+ }
105
+ }
106
+ return { meta, tags };
107
+ }
108
+ /** Comment meta for one location, or empty. */
109
+ function commentMetaAt(file, line) {
110
+ const text = commentAbove(file, line);
111
+ return text ? parseCommentMeta(text) : { meta: {}, tags: [] };
112
+ }
113
+ /** Find the line of `it('title'` / `test("title"` / `describe(`title`` in a file (WebdriverIO gives no line). */
114
+ function lineOfTitle(file, title, kinds = 'it|test|specify|describe|context|suite', after = 0) {
115
+ const lines = linesOf(file);
116
+ if (!lines || !title)
117
+ return 0;
118
+ const esc = title.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
119
+ const re = new RegExp(`\\b(?:${kinds})(?:\\.\\w+)*\\s*\\(\\s*(['"\`])${esc}\\1`);
120
+ // search after the enclosing describe's line, so two describes with an it('logs in') each find their own
121
+ for (let i = Math.max(0, after); i < lines.length; i++)
122
+ if (re.test(lines[i]))
123
+ return i + 1;
124
+ return 0;
125
+ }
package/dist/explain.d.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  * Turns a raw Playwright error message into a short, plain-language explanation.
3
3
  * Rule based, no network, no AI. The original message is always kept next to it.
4
4
  */
5
- export type ErrorKind = 'not-found' | 'ambiguous' | 'not-visible' | 'blocked' | 'disabled' | 'detached' | 'wrong-element' | 'assertion' | 'visual' | 'navigation' | 'network' | 'api' | 'test-timeout' | 'hook-timeout' | 'closed' | 'script' | 'file' | 'thrown';
5
+ export type ErrorKind = 'not-found' | 'ambiguous' | 'not-visible' | 'blocked' | 'disabled' | 'detached' | 'wrong-element' | 'assertion' | 'visual' | 'navigation' | 'network' | 'api' | 'test-timeout' | 'hook-timeout' | 'closed' | 'crashed' | 'script' | 'file' | 'thrown';
6
6
  export interface ErrorExplain {
7
7
  kind: ErrorKind;
8
8
  /** Short label for a badge, e.g. "Element not found". */
package/dist/explain.js CHANGED
@@ -21,6 +21,7 @@ const LABELS = {
21
21
  'test-timeout': 'Test timed out',
22
22
  'hook-timeout': 'Hook timed out',
23
23
  'closed': 'Browser closed early',
24
+ 'crashed': 'Browser crashed',
24
25
  'script': 'Error in test code',
25
26
  'file': 'File not found',
26
27
  'thrown': 'Test threw an error',
@@ -51,6 +52,9 @@ function explainError(raw) {
51
52
  const where = action ? ` It was stuck in ${action}` + (locator ? ` on ${locator}` : '') + '.' : '';
52
53
  return out('test-timeout', `The whole test took longer than ${secs(ms)}.${where}`, 'Find the slow step in the Steps list below. Raise timeout in playwright.config.ts only if the flow is really that long.', { timeoutMs: ms, action, locator });
53
54
  }
55
+ // ── The browser process died (memory, too many workers): infrastructure, not the app or the test ──
56
+ if (/Target crashed|Page crashed|page has crashed|Renderer process crashed|tab crashed|session deleted because of page crash|chrome not reachable|Browsing context has been discarded/i.test(msg))
57
+ return out('crashed', 'The browser crashed while the test was running.', 'Not a bug in the app or the test: the browser process died, usually from memory pressure or too many parallel workers. Re-run it; if it keeps happening, lower workers or give the machine more memory.', { action });
54
58
  // ── Strict mode ──────────────────────────────────────────────────────────
55
59
  m = msg.match(/strict mode violation: (.+?) resolved to (\d+) elements/s);
56
60
  if (m)
package/dist/pdf.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export interface PdfResult {
2
+ ok: boolean;
3
+ reason?: string;
4
+ }
5
+ /** Render the report's print layout to a PDF. Best-effort, never throws: a failure here must not fail
6
+ * the run — the HTML report and its Export PDF button remain.
7
+ * 1. the Chromium that Playwright ships, when `@playwright/test` and its browser are installed;
8
+ * 2. an installed Chrome, Edge or Chromium, headless with --print-to-pdf (the report builds its print
9
+ * layout itself on `?rl-print`). Edge ships with Windows, so this covers suites that run on Firefox
10
+ * or WebKit, and WebdriverIO projects that have no Playwright at all.
11
+ * `chromePath` (or the CHROME_PATH variable) names the browser explicitly and skips the search. */
12
+ export declare function writeReportPdf(htmlFile: string, pdfFile: string, chromePath?: string): Promise<PdfResult>;
13
+ /** Any Chromium-based browser can print the report: Chrome, Edge or Chromium. */
14
+ export declare function findChrome(): string | undefined;
package/dist/pdf.js ADDED
@@ -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.writeReportPdf = writeReportPdf;
37
+ exports.findChrome = findChrome;
38
+ const fs = __importStar(require("fs"));
39
+ const path = __importStar(require("path"));
40
+ const child_process_1 = require("child_process");
41
+ const url_1 = require("url");
42
+ /** Render the report's print layout to a PDF. Best-effort, never throws: a failure here must not fail
43
+ * the run — the HTML report and its Export PDF button remain.
44
+ * 1. the Chromium that Playwright ships, when `@playwright/test` and its browser are installed;
45
+ * 2. an installed Chrome, Edge or Chromium, headless with --print-to-pdf (the report builds its print
46
+ * layout itself on `?rl-print`). Edge ships with Windows, so this covers suites that run on Firefox
47
+ * or WebKit, and WebdriverIO projects that have no Playwright at all.
48
+ * `chromePath` (or the CHROME_PATH variable) names the browser explicitly and skips the search. */
49
+ async function writeReportPdf(htmlFile, pdfFile, chromePath) {
50
+ try {
51
+ fs.unlinkSync(pdfFile);
52
+ }
53
+ catch { /* none yet */ } // never leave a previous run's PDF next to this report
54
+ const explicit = chromePath || process.env.CHROME_PATH;
55
+ let firstError = '';
56
+ if (!explicit) {
57
+ try {
58
+ const { chromium } = await import('@playwright/test');
59
+ const browser = await chromium.launch();
60
+ try {
61
+ const page = await browser.newPage();
62
+ await page.goto((0, url_1.pathToFileURL)(htmlFile).href, { waitUntil: 'load' });
63
+ await page.evaluate(() => window.reportingLabsPreparePrint?.());
64
+ await page.pdf({ path: pdfFile, printBackground: true, preferCSSPageSize: true });
65
+ }
66
+ finally {
67
+ await browser.close();
68
+ }
69
+ if (written(pdfFile))
70
+ return { ok: true };
71
+ }
72
+ catch (e) {
73
+ firstError = String(e.message).split('\n')[0];
74
+ }
75
+ }
76
+ const chrome = explicit && isFile(explicit) ? explicit : findChrome();
77
+ if (!chrome) {
78
+ return { ok: false, reason: explicit ? `browser not found at ${explicit}` : 'no Chrome, Edge or Chromium found (set pdf: { chromePath }, or pdf: false to silence)' };
79
+ }
80
+ try {
81
+ (0, child_process_1.spawnSync)(chrome, ['--headless', '--no-sandbox', '--disable-gpu', '--no-pdf-header-footer',
82
+ '--virtual-time-budget=8000', '--run-all-compositor-stages-before-draw',
83
+ '--print-to-pdf=' + pdfFile, (0, url_1.pathToFileURL)(htmlFile).href + '?rl-print=1'], { stdio: 'ignore', timeout: 120000 });
84
+ }
85
+ catch (e) {
86
+ return { ok: false, reason: String(e.message).split('\n')[0] };
87
+ }
88
+ return written(pdfFile) ? { ok: true } : { ok: false, reason: firstError || `${path.basename(chrome)} did not write the PDF` };
89
+ }
90
+ function written(f) {
91
+ try {
92
+ return fs.statSync(f).size > 0;
93
+ }
94
+ catch {
95
+ return false;
96
+ }
97
+ }
98
+ function isFile(f) {
99
+ try {
100
+ return fs.statSync(f).isFile();
101
+ }
102
+ catch {
103
+ return false;
104
+ }
105
+ }
106
+ function which(name) {
107
+ const exts = process.platform === 'win32' ? ['.exe', ''] : [''];
108
+ for (const dir of (process.env.PATH || '').split(path.delimiter)) {
109
+ if (!dir)
110
+ continue;
111
+ for (const ext of exts) {
112
+ const p = path.join(dir, name + ext);
113
+ try {
114
+ fs.accessSync(p, fs.constants.X_OK);
115
+ if (isFile(p))
116
+ return p;
117
+ }
118
+ catch { /* next */ }
119
+ }
120
+ }
121
+ return undefined;
122
+ }
123
+ /** Any Chromium-based browser can print the report: Chrome, Edge or Chromium. */
124
+ function findChrome() {
125
+ const candidates = [];
126
+ if (process.platform === 'darwin') {
127
+ candidates.push('/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '/Applications/Chromium.app/Contents/MacOS/Chromium', '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge');
128
+ }
129
+ else if (process.platform === 'win32') {
130
+ for (const base of [process.env.ProgramFiles, process.env['ProgramFiles(x86)'], process.env.LOCALAPPDATA]) {
131
+ if (!base)
132
+ continue;
133
+ candidates.push(path.join(base, 'Google', 'Chrome', 'Application', 'chrome.exe'), path.join(base, 'Microsoft', 'Edge', 'Application', 'msedge.exe'));
134
+ }
135
+ }
136
+ for (const c of candidates)
137
+ if (isFile(c))
138
+ return c;
139
+ for (const name of ['google-chrome', 'google-chrome-stable', 'chromium', 'chromium-browser', 'chrome',
140
+ 'microsoft-edge', 'microsoft-edge-stable', 'msedge']) {
141
+ const p = which(name);
142
+ if (p)
143
+ return p;
144
+ }
145
+ for (const c of ['/usr/bin/google-chrome', '/usr/bin/chromium', '/usr/bin/chromium-browser', '/snap/bin/chromium'])
146
+ if (isFile(c))
147
+ return c;
148
+ return undefined;
149
+ }
@@ -20,8 +20,7 @@ export default class ReportingLabsReporter implements Reporter {
20
20
  private pushOutput;
21
21
  onBegin(config: FullConfig, suite: Suite): void;
22
22
  onEnd(result: FullResult): Promise<void>;
23
- /** Render the report's print layout to a PDF with the Chromium that Playwright already ships. Best-effort:
24
- * a failure here (no browser, sandbox) never fails the run — the report and its Export PDF button remain. */
23
+ /** report.pdf next to the HTML; see writeReportPdf for which browser prints it. Never fails the run. */
25
24
  private writePdf;
26
25
  /** One short list of tests that carry no meta() at all, so the whole team keeps the report useful. */
27
26
  private printMissingMeta;
@@ -46,6 +45,8 @@ export default class ReportingLabsReporter implements Reporter {
46
45
  * An object value (meta({ octaneTestCase: { id, p } })) is folded to its display text and, when the key has a
47
46
  * link template, to a ready-made href in `links`; the other fields never show in the report.
48
47
  */
48
+ /** Meta from comments above the test and its describe blocks (outer first, the test's own comment last). */
49
+ private commentMeta;
49
50
  private extractMeta;
50
51
  /** A local image file (path relative to the config) is embedded as a data URI so the report stays self-contained. URLs and data URIs pass through. */
51
52
  private resolveLogo;