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.
package/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
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.
14
14
 
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).
15
+ Today it ships with a **Playwright** reporter, a **WebdriverIO** reporter and a **Cypress** plugin. Jest/Vitest is 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
16
 
17
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.
18
18
 
@@ -152,7 +152,7 @@ test('completes purchase', async ({ page }) => {
152
152
  - **For a whole group:** a comment above `test.describe` applies to every test inside it.
153
153
  - **Tags:** a line with only `@words` (`@smoke @regression`) becomes tags. `@P0` sets the priority, `@critical` the severity.
154
154
  - **Your old comments are safe.** A comment with an empty line before the test, a name in a sentence ("reported by @naveen"), unknown keys and JSDoc tags like `@param` are all ignored.
155
- - **WebdriverIO** reads them too, above `it()` and `describe()`.
155
+ - **WebdriverIO** and **Cypress** read them too, above `it()` and `describe()`.
156
156
  - Turn it off with `commentMeta: false`.
157
157
 
158
158
  **Don't type it by hand: install the snippets.** In VS Code:
@@ -259,6 +259,8 @@ open reporting-labs/index.html
259
259
 
260
260
  Run it two or three times to see the history features (new vs known failures, flaky dots, got slower, trend).
261
261
 
262
+ For Cypress, [`examples-cypress/`](https://github.com/naveenautomationlabs/reporting-labs/tree/main/examples-cypress) is a tiny offline shop app with a few specs (steps, API calls, a flaky test, a failing hook): `cd examples-cypress && npm install && npx cypress run`. With Cucumber: [`examples-cypress-cucumber/`](https://github.com/naveenautomationlabs/reporting-labs/tree/main/examples-cypress-cucumber), the same app with feature files.
263
+
262
264
  ## A tour of the report
263
265
 
264
266
  ### Overview: the whole run on one screen
@@ -345,7 +347,7 @@ Every outcome Playwright can produce, not just pass and fail:
345
347
  | Single HTML file, opens without a server | ❌<br><sub>a folder, served by `show-report`</sub> | 🟡<br><sub>single-file mode (2.24+, Allure 3)</sub> | ✅ |
346
348
  | Nothing extra to install | ✅ | ❌<br><sub>Allure CLI; Allure 2 needs Java</sub> | ✅<br><sub>one package</sub> |
347
349
  | Setup | ✅<br><sub>built in</sub> | 🟡<br><sub>reporter + generate step</sub> | ✅<br><sub>one line</sub> |
348
- | Frameworks | ❌<br><sub>Playwright only</sub> | ✅<br><sub>many languages</sub> | ✅<br><sub>Playwright, WebdriverIO, pytest, pytest-bdd, Robot, JUnit 5, TestNG, Cucumber</sub> |
350
+ | Frameworks | ❌<br><sub>Playwright only</sub> | ✅<br><sub>many languages</sub> | ✅<br><sub>Playwright, Cypress (+ Cucumber), WebdriverIO, pytest, pytest-bdd, Robot, JUnit 5, TestNG, Cucumber</sub> |
349
351
  | **Each test** | | | |
350
352
  | Steps, screenshots, videos, traces | ✅ | ✅ | ✅ |
351
353
  | Logs and test data | 🟡<br><sub>as attachments</sub> | 🟡<br><sub>attachments, parameters</sub> | ✅<br><sub>`log()`, `testData()`</sub> |
@@ -721,9 +723,106 @@ export const config = {
721
723
 
722
724
  Guide: [reportinglabs.dev/get-started/webdriverio](https://reportinglabs.dev/get-started/webdriverio).
723
725
 
726
+ ## Cypress
727
+
728
+ The same report from `cypress run` (Cypress 13 to 16):
729
+ - **Tests:** each test under its describe block, every retry as its own attempt (flaky tests are found), passed / failed / skipped, and a spec that could not load.
730
+ - **Steps:** Cypress commands as steps, hooks grouped, the failing command marked.
731
+ - **API tab:** `cy.request` calls with request and response, and the app's own fetch / XHR calls.
732
+ - **Proof:** failure screenshots on the right attempt and the spec video.
733
+ - **Errors explained in plain words:** element not found, covered or hidden element, `cy.request` / `cy.visit` / `cy.wait` failures, errors thrown by the app.
734
+ - **Same as Playwright:** history, PDF, masking, merge.
735
+
736
+ **1. Register the plugin**
737
+
738
+ ```js
739
+ // cypress.config.js
740
+ const { defineConfig } = require('cypress');
741
+ const { reportingLabs } = require('reporting-labs/cypress');
742
+
743
+ module.exports = defineConfig({
744
+ e2e: {
745
+ setupNodeEvents(on, config) {
746
+ reportingLabs(on, config, { title: 'Checkout regression' }); // any option from "All options"
747
+ return config; // needed: it tells the support file the plugin is on
748
+ },
749
+ },
750
+ });
751
+ ```
752
+
753
+ **2. Import the support file** (steps, API calls, `meta()`):
754
+
755
+ ```js
756
+ // cypress/support/e2e.js
757
+ import 'reporting-labs/cypress/support';
758
+ ```
759
+
760
+ Run `npx cypress run`. The report is in `reporting-labs/index.html`.
761
+ A runnable example: [`examples-cypress/`](https://github.com/naveenautomationlabs/reporting-labs/tree/main/examples-cypress).
762
+
763
+ **Meta** (priority, owner, story...) with `meta()` in the test, or a comment above `it()` / `describe()`:
764
+
765
+ ```js
766
+ import { meta } from 'reporting-labs/cypress/support';
767
+
768
+ /** @feature checkout @owner asha */
769
+ describe('Checkout', () => {
770
+ it('places an order', () => {
771
+ meta({ priority: 'P0', severity: 'critical', story: 'SHOP-12' });
772
+ cy.visit('/cart');
773
+ });
774
+ });
775
+ ```
776
+
777
+ Good to know:
778
+ - **Your config already has `before:run`, `after:spec` or `after:run`?** Cypress keeps one handler per event, so the one registered last wins. Call ours from yours:
779
+ ```js
780
+ const rl = reportingLabs(on, config, { title: 'Checkout regression' });
781
+ on('after:spec', (spec, results) => { rl.afterSpec(spec, results); /* your code */ });
782
+ ```
783
+ (`rl.beforeRun` and `rl.afterRun` work the same way.) If the report is missing, the run says so.
784
+ - **`cypress open`:** Cypress sends these events in `cypress run`. In `cypress open` it sends them only with `experimentalInteractiveRunEvents: true`.
785
+ - **Video:** set `video: true` in the Cypress config. The spec video is attached to failed and flaky tests (`video: 'all'` in our options for every test).
786
+ - **PDF:** printed by an installed Chrome or Edge (Cypress's own Electron cannot print it). If none is found, set `pdf: { chromePath }` or `CHROME_PATH`.
787
+ - **Split across machines** (Cypress Cloud parallel, cypress-split): each machine writes its `reporting-labs` folder. Combine them with `npx reporting-labs merge`, as in [Split your run across shards](#split-your-run-across-shards-then-merge-into-one-report).
788
+
789
+ ### Cypress with Cucumber
790
+
791
+ With [@badeball/cypress-cucumber-preprocessor](https://github.com/badeball/cypress-cucumber-preprocessor) (Cypress 13 to 16), each scenario is a report row:
792
+ - **Under its Feature and Rule**, at its line in the `.feature` file, with a Scenario badge.
793
+ - **Given / When / Then steps** with the Cypress commands each one ran, Before / After hooks, the failing step marked and the steps it left unrun greyed out.
794
+ - **Scenario Outline rows** named after their values, with the row as an Examples table. Data tables and doc strings as test data.
795
+ - **Tags:** `@P0`–`@P4` set the priority, `@blocker` / `@critical` / `@major` / `@minor` / `@trivial` the severity, `@owner:asha` (or `@story:SHOP-12`, `@feature:…`…) any meta, anything else is a tag. Feature and Rule tags apply to their scenarios. `meta()` works in step definitions.
796
+ - **Errors:** the step definition line (or the step in the feature file), "Step not defined" / "Step defined twice", and a step returning `"pending"`.
797
+
798
+ Same two steps as above. Call `reportingLabs()` **after** `addCucumberPreprocessorPlugin()`:
799
+
800
+ ```js
801
+ // cypress.config.js
802
+ const { defineConfig } = require('cypress');
803
+ const createBundler = require('@bahmutov/cypress-esbuild-preprocessor');
804
+ const { addCucumberPreprocessorPlugin } = require('@badeball/cypress-cucumber-preprocessor');
805
+ const { createEsbuildPlugin } = require('@badeball/cypress-cucumber-preprocessor/esbuild');
806
+ const { reportingLabs } = require('reporting-labs/cypress');
807
+
808
+ module.exports = defineConfig({
809
+ e2e: {
810
+ specPattern: 'cypress/e2e/**/*.feature',
811
+ async setupNodeEvents(on, config) {
812
+ await addCucumberPreprocessorPlugin(on, config);
813
+ on('file:preprocessor', createBundler({ plugins: [createEsbuildPlugin(config)] }));
814
+ reportingLabs(on, config, { title: 'Checkout regression' }); // last: it also runs the preprocessor's handlers
815
+ return config;
816
+ },
817
+ },
818
+ });
819
+ ```
820
+
821
+ Cypress keeps the last `before:run` / `after:spec` / `after:run` handler. Ours call the preprocessor's, so its own messages, JSON and HTML reports keep working. If `reportingLabs()` comes first, the run says the report could not be written. Works the same with the webpack bundler. A runnable example: [`examples-cypress-cucumber/`](https://github.com/naveenautomationlabs/reporting-labs/tree/main/examples-cypress-cucumber).
822
+
724
823
  ## Roadmap
725
824
 
726
- - Cypress, Jest/Vitest and JUnit XML adapters
825
+ - Jest/Vitest and JUnit XML adapters
727
826
  - AI summary of failures (bring your own API key)
728
827
  - Hosted history dashboard across branches and projects
729
828
 
@@ -733,7 +832,7 @@ reportingLabs is a library that runs inside your own test run. There is no repor
733
832
 
734
833
  - **Nothing is sent anywhere.** The reporter makes no network requests of its own; its only traffic is the traffic your tests already make. An opened report makes no external requests either: fonts, scripts and the logo are embedded, so it works offline and behind a firewall. The only exceptions are opt-in (`embedFonts: false`, a logo given as an `https://` URL) or need a click (CI, commit and issue links).
735
834
  - **Everything stays on your machine:** the report folder (`reporting-labs/` by default) holds `index.html`, `report.json`, `report.pdf` and `assets/`, plus the run history `reporting-labs.history.json` next to your project. Nothing is written anywhere else. Whoever can read your test artifacts can read the report; deleting them deletes the data.
736
- - **Secrets are masked before anything is written:** passwords, tokens, cookies, auth headers, API keys, JWTs and card numbers in logs, API bodies and headers, test data, errors and step titles. With Playwright, a value passed to `fill()` shows in the step title unless it is a known secret, so read test passwords from environment variables (masked by default) or list them in `maskValues`. The WebdriverIO reporter masks values typed into password fields.
835
+ - **Secrets are masked before anything is written:** passwords, tokens, cookies, auth headers, API keys, JWTs and card numbers in logs, API bodies and headers, test data, errors and step titles. With Playwright, a value passed to `fill()` shows in the step title unless it is a known secret, so read test passwords from environment variables (masked by default) or list them in `maskValues`. The WebdriverIO reporter and the Cypress support file mask values typed into password fields.
737
836
  - **Screenshots, videos and traces are not masked.** They are images and recordings of the application, so run tests against test data, or turn them off for suites that show real personal data.
738
837
  - **No runtime dependencies;** `@playwright/test` is an optional peer, the one your project already has. No install or post-install scripts. MIT licensed.
739
838
 
@@ -0,0 +1,163 @@
1
+ import { type WriteReportOptions } from '../write-report';
2
+ import type { TestData, ErrorData, StepData, ApiCall } from '../types';
3
+ export interface ReportingLabsCypressOptions extends WriteReportOptions {
4
+ /** Read meta from a comment right above it() / describe(): `/** @owner naveen @priority P0 *\/`. Default: true */
5
+ commentMeta?: boolean;
6
+ /** Screenshots inside the HTML as data URIs (default true); bigger than embedLimit or false: copied to assets/. */
7
+ embedAttachments?: boolean;
8
+ /** Bytes; attachments above it are copied to assets/ instead of embedded. Default 2 MB. */
9
+ embedLimit?: number;
10
+ /** Put the spec video inside the HTML too (default false: copied to assets/). */
11
+ embedVideos?: boolean;
12
+ /** Which tests get the spec's video (Cypress records one video per spec): 'failed' (failed and flaky, default) or 'all'. */
13
+ video?: 'failed' | 'all';
14
+ /** Variable that holds the environment name, when it is not ENV, TEST_ENV, APP_ENV or *_ENV. */
15
+ envVar?: string;
16
+ }
17
+ interface CyBrowser {
18
+ name?: string;
19
+ displayName?: string;
20
+ version?: string;
21
+ majorVersion?: string | number;
22
+ }
23
+ interface CyBeforeRun {
24
+ browser?: CyBrowser;
25
+ cypressVersion?: string;
26
+ config?: Record<string, unknown>;
27
+ }
28
+ interface CySpec {
29
+ name?: string;
30
+ relative?: string;
31
+ absolute?: string;
32
+ }
33
+ interface CyTest {
34
+ title?: string[];
35
+ state?: string;
36
+ duration?: number;
37
+ displayError?: string | null;
38
+ attempts?: {
39
+ state?: string;
40
+ }[];
41
+ }
42
+ interface CyScreenshot {
43
+ name?: string;
44
+ path?: string;
45
+ takenAt?: string;
46
+ }
47
+ interface CyRunResult {
48
+ error?: string | null;
49
+ stats?: {
50
+ startedAt?: string;
51
+ endedAt?: string;
52
+ duration?: number;
53
+ };
54
+ spec?: CySpec;
55
+ tests?: CyTest[] | null;
56
+ screenshots?: CyScreenshot[];
57
+ video?: string | null;
58
+ }
59
+ interface CyAfterRun {
60
+ status?: string;
61
+ browserName?: string;
62
+ browserVersion?: string;
63
+ cypressVersion?: string;
64
+ startedTestsAt?: string;
65
+ endedTestsAt?: string;
66
+ totalFailed?: number;
67
+ totalTests?: number;
68
+ }
69
+ type On = (...args: any[]) => void;
70
+ /** One attempt as the support file sends it (see support.ts). */
71
+ export interface AttemptPayload {
72
+ spec?: string;
73
+ titlePath?: string[];
74
+ retry?: number;
75
+ state?: string;
76
+ start?: number;
77
+ duration?: number;
78
+ err?: {
79
+ message?: string;
80
+ stack?: string;
81
+ codeFrame?: {
82
+ line?: number;
83
+ column?: number;
84
+ relativeFile?: string;
85
+ };
86
+ };
87
+ steps?: StepData[];
88
+ api?: ApiCall[];
89
+ meta?: Record<string, unknown>;
90
+ /** Set for a Cucumber scenario (see gherkin() in support.ts). */
91
+ gherkin?: GherkinPayload;
92
+ }
93
+ export interface GherkinPayload {
94
+ feature?: string;
95
+ rule?: string;
96
+ keyword?: string;
97
+ line?: number;
98
+ tags?: string[];
99
+ example?: {
100
+ header?: string[];
101
+ values?: string[];
102
+ };
103
+ args?: {
104
+ step?: string;
105
+ table?: string[][];
106
+ docString?: string;
107
+ }[];
108
+ /** The step that was running when the scenario stopped: it failed, or its definition returned "pending". */
109
+ stoppedAt?: {
110
+ step?: string;
111
+ line?: number;
112
+ state?: string;
113
+ };
114
+ }
115
+ export interface ReportingLabsCypressHandlers {
116
+ beforeRun: (details: CyBeforeRun) => void;
117
+ afterSpec: (spec: CySpec, results: CyRunResult) => void;
118
+ afterRun: (results: CyAfterRun) => Promise<string | undefined>;
119
+ }
120
+ export declare function reportingLabs(on: On, config?: any, options?: ReportingLabsCypressOptions): ReportingLabsCypressHandlers;
121
+ export default reportingLabs;
122
+ export declare class CypressCollector {
123
+ private options;
124
+ private config;
125
+ private masker;
126
+ private tests;
127
+ private startTime;
128
+ private endTime;
129
+ private browser;
130
+ private cypressVersion;
131
+ private outDir;
132
+ private assetsDir;
133
+ private assetCounter;
134
+ private assetsReady;
135
+ private base;
136
+ private attempts;
137
+ private ranBeforeRun;
138
+ private warnedReplaced;
139
+ constructor(options: ReportingLabsCypressOptions, config?: Record<string, unknown>);
140
+ addAttempt(p: AttemptPayload): void;
141
+ beforeRun(d?: CyBeforeRun): void;
142
+ /** assets/ holds this run's copied files only: emptied once per run, before the first file lands. */
143
+ private prepareAssets;
144
+ afterSpec(spec?: CySpec, results?: CyRunResult): void;
145
+ afterRun(results?: CyAfterRun): Promise<string | undefined>;
146
+ /** One Cypress test → one report row. Cypress gives the attempts' states but one duration and one error (the last). */
147
+ toTest(ct: CyTest, abs: string, file: string, startTime: number): TestData;
148
+ /** What the support file sent for this test: real per-attempt times, steps, API calls, each attempt's error, meta(). */
149
+ enrich(t: TestData, attempts: AttemptPayload[] | undefined, abs: string): void;
150
+ /** A Cucumber scenario: its feature file line, Rule, tags as tags and meta, Outline row and data tables. Runs before the
151
+ * steps are masked: a password column in Examples or a data table teaches the masker its values. */
152
+ private applyGherkin;
153
+ private maskStep;
154
+ /** displayError is the message plus a stack (" at …"); the first frame in the spec file gives the location. */
155
+ toError(display: string, abs: string): ErrorData;
156
+ /** Cypress names a failure screenshot "<describe> -- <it> (failed) (attempt 2).png"; a custom cy.screenshot('name')
157
+ * is matched to the test that was running when it was taken. */
158
+ private attachScreenshots;
159
+ private attachVideo;
160
+ private attachment;
161
+ private resolveLogo;
162
+ private rel;
163
+ }