reporting-labs 0.6.17 → 0.6.20
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 +68 -3
- package/dist/bdd.d.ts +32 -0
- package/dist/bdd.js +274 -0
- package/dist/cypress/index.d.ts +29 -0
- package/dist/cypress/index.js +129 -10
- package/dist/cypress/support.d.ts +2 -0
- package/dist/cypress/support.js +147 -21
- package/dist/explain.js +14 -0
- package/dist/mask.js +26 -4
- package/dist/reporter.d.ts +1 -0
- package/dist/reporter.js +37 -7
- package/dist/template.html +1 -1
- package/dist/template.js +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -259,7 +259,39 @@ 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
|
|
262
|
+
For Cucumber feature files on Playwright, [`examples-playwright-bdd/`](https://github.com/naveenautomationlabs/reporting-labs/tree/main/examples-playwright-bdd) runs [playwright-bdd](https://github.com/vitalets/playwright-bdd) against a tiny offline shop app: `cd examples-playwright-bdd && npm install && npm test`.
|
|
263
|
+
|
|
264
|
+
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.
|
|
265
|
+
|
|
266
|
+
### Playwright with Cucumber (playwright-bdd)
|
|
267
|
+
|
|
268
|
+
[playwright-bdd](https://github.com/vitalets/playwright-bdd) runs `.feature` files on the Playwright test runner, so
|
|
269
|
+
`playwright.config.ts`, fixtures, projects, retries and sharding all stay. Add the reporter as usual; nothing else to
|
|
270
|
+
set up:
|
|
271
|
+
|
|
272
|
+
```ts
|
|
273
|
+
// playwright.config.ts
|
|
274
|
+
import 'reporting-labs/auto';
|
|
275
|
+
import { defineConfig } from '@playwright/test';
|
|
276
|
+
import { defineBddConfig } from 'playwright-bdd';
|
|
277
|
+
|
|
278
|
+
const testDir = defineBddConfig({ features: 'features/**/*.feature', steps: 'steps/**/*.ts' });
|
|
279
|
+
|
|
280
|
+
export default defineConfig({
|
|
281
|
+
testDir,
|
|
282
|
+
reporter: [['list'], ['reporting-labs', { title: 'Checkout regression' }]],
|
|
283
|
+
});
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Run `npx bddgen && npx playwright test`. Each scenario is a report row:
|
|
287
|
+
- **At its line in the `.feature` file**, under its Feature and Rule, with a Scenario badge (not the generated `.features-gen` spec).
|
|
288
|
+
- **Given / When / Then steps** with the Playwright calls each one made; Background steps next to the scenario's own; the steps a failure left unrun greyed out.
|
|
289
|
+
- **Scenario Outline rows** named after their values, with the row as an Examples table; data tables and doc strings as test data. A password column is masked.
|
|
290
|
+
- **Tags:** `@P0`–`@P4` set the priority, `@blocker` / `@critical` / `@major` / `@minor` / `@trivial` the severity, `@owner:asha` / `@story:SHOP-12` / `@feature:…` any meta; anything else is a tag.
|
|
291
|
+
- **Errors:** the step definition line, or the step in the feature file; "Step not defined" for `Missing step`, "Step defined twice".
|
|
292
|
+
|
|
293
|
+
playwright-bdd 8 and 9 give all of it. With playwright-bdd 7 the scenario's location, Feature / Rule and Outline rows
|
|
294
|
+
are right; data tables and the steps left unrun need 8+.
|
|
263
295
|
|
|
264
296
|
## A tour of the report
|
|
265
297
|
|
|
@@ -347,7 +379,7 @@ Every outcome Playwright can produce, not just pass and fail:
|
|
|
347
379
|
| 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> | ✅ |
|
|
348
380
|
| Nothing extra to install | ✅ | ❌<br><sub>Allure CLI; Allure 2 needs Java</sub> | ✅<br><sub>one package</sub> |
|
|
349
381
|
| Setup | ✅<br><sub>built in</sub> | 🟡<br><sub>reporter + generate step</sub> | ✅<br><sub>one line</sub> |
|
|
350
|
-
| Frameworks | ❌<br><sub>Playwright only</sub> | ✅<br><sub>many languages</sub> | ✅<br><sub>Playwright, Cypress, WebdriverIO, pytest, pytest-bdd, Robot, JUnit 5, TestNG, Cucumber</sub> |
|
|
382
|
+
| Frameworks | ❌<br><sub>Playwright only</sub> | ✅<br><sub>many languages</sub> | ✅<br><sub>Playwright (+ BDD), Cypress (+ Cucumber), WebdriverIO, pytest, pytest-bdd, Robot, JUnit 5, TestNG, Cucumber</sub> |
|
|
351
383
|
| **Each test** | | | |
|
|
352
384
|
| Steps, screenshots, videos, traces | ✅ | ✅ | ✅ |
|
|
353
385
|
| Logs and test data | 🟡<br><sub>as attachments</sub> | 🟡<br><sub>attachments, parameters</sub> | ✅<br><sub>`log()`, `testData()`</sub> |
|
|
@@ -786,10 +818,43 @@ Good to know:
|
|
|
786
818
|
- **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
819
|
- **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
820
|
|
|
821
|
+
### Cypress with Cucumber
|
|
822
|
+
|
|
823
|
+
With [@badeball/cypress-cucumber-preprocessor](https://github.com/badeball/cypress-cucumber-preprocessor) (Cypress 13 to 16), each scenario is a report row:
|
|
824
|
+
- **Under its Feature and Rule**, at its line in the `.feature` file, with a Scenario badge.
|
|
825
|
+
- **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.
|
|
826
|
+
- **Scenario Outline rows** named after their values, with the row as an Examples table. Data tables and doc strings as test data.
|
|
827
|
+
- **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.
|
|
828
|
+
- **Errors:** the step definition line (or the step in the feature file), "Step not defined" / "Step defined twice", and a step returning `"pending"`.
|
|
829
|
+
|
|
830
|
+
Same two steps as above. Call `reportingLabs()` **after** `addCucumberPreprocessorPlugin()`:
|
|
831
|
+
|
|
832
|
+
```js
|
|
833
|
+
// cypress.config.js
|
|
834
|
+
const { defineConfig } = require('cypress');
|
|
835
|
+
const createBundler = require('@bahmutov/cypress-esbuild-preprocessor');
|
|
836
|
+
const { addCucumberPreprocessorPlugin } = require('@badeball/cypress-cucumber-preprocessor');
|
|
837
|
+
const { createEsbuildPlugin } = require('@badeball/cypress-cucumber-preprocessor/esbuild');
|
|
838
|
+
const { reportingLabs } = require('reporting-labs/cypress');
|
|
839
|
+
|
|
840
|
+
module.exports = defineConfig({
|
|
841
|
+
e2e: {
|
|
842
|
+
specPattern: 'cypress/e2e/**/*.feature',
|
|
843
|
+
async setupNodeEvents(on, config) {
|
|
844
|
+
await addCucumberPreprocessorPlugin(on, config);
|
|
845
|
+
on('file:preprocessor', createBundler({ plugins: [createEsbuildPlugin(config)] }));
|
|
846
|
+
reportingLabs(on, config, { title: 'Checkout regression' }); // last: it also runs the preprocessor's handlers
|
|
847
|
+
return config;
|
|
848
|
+
},
|
|
849
|
+
},
|
|
850
|
+
});
|
|
851
|
+
```
|
|
852
|
+
|
|
853
|
+
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).
|
|
854
|
+
|
|
789
855
|
## Roadmap
|
|
790
856
|
|
|
791
857
|
- Jest/Vitest and JUnit XML adapters
|
|
792
|
-
- Cucumber for Cypress (`@badeball/cypress-cucumber-preprocessor`): Gherkin steps as steps
|
|
793
858
|
- AI summary of failures (bring your own API key)
|
|
794
859
|
- Hosted history dashboard across branches and projects
|
|
795
860
|
|
package/dist/bdd.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { TestData } from './types';
|
|
2
|
+
interface BddStep {
|
|
3
|
+
pwStepLine: number;
|
|
4
|
+
gherkinStepLine: number;
|
|
5
|
+
textWithKeyword: string;
|
|
6
|
+
isBg?: boolean;
|
|
7
|
+
}
|
|
8
|
+
interface BddTest {
|
|
9
|
+
pwTestLine: number;
|
|
10
|
+
pickleLine: number;
|
|
11
|
+
tags?: string[];
|
|
12
|
+
steps: BddStep[];
|
|
13
|
+
}
|
|
14
|
+
interface BddSpec {
|
|
15
|
+
uri: string;
|
|
16
|
+
feature: string;
|
|
17
|
+
tests: BddTest[]; /** playwright-bdd 7: by "describe|…|test" title */
|
|
18
|
+
byTitle?: Map<string, BddTest>;
|
|
19
|
+
}
|
|
20
|
+
type Masker = {
|
|
21
|
+
maskStr(s: string): string;
|
|
22
|
+
isSensitive(k: string): boolean;
|
|
23
|
+
learn(v: string): void;
|
|
24
|
+
};
|
|
25
|
+
/** The bdd data of a generated spec file, or null when it is not one. */
|
|
26
|
+
export declare function bddSpec(specFile: string, roots: string[]): BddSpec | null;
|
|
27
|
+
/**
|
|
28
|
+
* Turns a playwright-bdd test into a scenario row. `specFile` is the generated spec (absolute), `rel` makes a path
|
|
29
|
+
* relative the way the rest of the report does, `masker` is the report's masker.
|
|
30
|
+
*/
|
|
31
|
+
export declare function applyBdd(t: TestData, specFile: string, roots: string[], rel: (f: string) => string, masker: Masker): boolean;
|
|
32
|
+
export {};
|
package/dist/bdd.js
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
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.bddSpec = bddSpec;
|
|
37
|
+
exports.applyBdd = applyBdd;
|
|
38
|
+
/**
|
|
39
|
+
* playwright-bdd (github.com/vitalets/playwright-bdd): its tests run on the Playwright runner, so they reach the
|
|
40
|
+
* reporter as ordinary tests in generated spec files (.features-gen/…/x.feature.spec.js). Each generated file carries
|
|
41
|
+
* the feature file it came from (`$uri`) and a `bddFileData` block: for every test its line in the feature file, its
|
|
42
|
+
* tags, and every step with its line in the feature file.
|
|
43
|
+
*
|
|
44
|
+
* With that and the feature file itself, a scenario becomes a report row like the Cucumber ones elsewhere: at its
|
|
45
|
+
* line in the .feature file, under its Feature and Rule, Outline rows named after their values with the row as an
|
|
46
|
+
* Examples table, data tables and doc strings as test data, Background steps next to the scenario's own, the steps a
|
|
47
|
+
* failure left unrun greyed out, and an error in the generated file pointed at the step in the feature file.
|
|
48
|
+
*
|
|
49
|
+
* Read only, and never fatal: a file that is not a playwright-bdd spec (or a format this does not know) is left as
|
|
50
|
+
* it is.
|
|
51
|
+
*/
|
|
52
|
+
const fs = __importStar(require("fs"));
|
|
53
|
+
const path = __importStar(require("path"));
|
|
54
|
+
const specCache = new Map();
|
|
55
|
+
const linesCache = new Map();
|
|
56
|
+
function lines(file) {
|
|
57
|
+
let l = linesCache.get(file);
|
|
58
|
+
if (!l) {
|
|
59
|
+
try {
|
|
60
|
+
l = fs.readFileSync(file, 'utf8').split(/\r?\n/);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
l = [];
|
|
64
|
+
}
|
|
65
|
+
linesCache.set(file, l);
|
|
66
|
+
}
|
|
67
|
+
return l;
|
|
68
|
+
}
|
|
69
|
+
/** The bdd data of a generated spec file, or null when it is not one. */
|
|
70
|
+
function bddSpec(specFile, roots) {
|
|
71
|
+
if (specCache.has(specFile))
|
|
72
|
+
return specCache.get(specFile);
|
|
73
|
+
let out = null;
|
|
74
|
+
try {
|
|
75
|
+
const src = fs.readFileSync(specFile, 'utf8');
|
|
76
|
+
const uri = /\$uri:\s*\[?\(\{\}, use\) => use\((['"])(.+?)\1\)/.exec(src)?.[2] ?? /^\/\/ Generated from: (.+)$/m.exec(src)?.[1]?.trim();
|
|
77
|
+
// $uri is relative to the config folder; try the usual roots
|
|
78
|
+
const feature = uri ? [...roots, path.dirname(specFile)].map(r => path.resolve(r, uri)).find(f => fs.existsSync(f)) : undefined;
|
|
79
|
+
const block = /bdd-data-start\s*\n([\s\S]*?)\n\s*\]; \/\/ bdd-data-end/.exec(src); // playwright-bdd 8+
|
|
80
|
+
const meta = /const bddFileMeta = (\{[\s\S]*?\n\});/.exec(src); // playwright-bdd 7
|
|
81
|
+
if (uri && feature && block) {
|
|
82
|
+
const tests = JSON.parse('[' + block[1].trim().replace(/,\s*$/, '') + ']');
|
|
83
|
+
if (Array.isArray(tests))
|
|
84
|
+
out = { uri, feature, tests };
|
|
85
|
+
}
|
|
86
|
+
else if (uri && feature && meta) {
|
|
87
|
+
const byTitle = new Map();
|
|
88
|
+
for (const [k, v] of Object.entries(JSON.parse(meta[1].replace(/,(\s*\})$/, '$1')))) {
|
|
89
|
+
const line = parseInt(String(v?.pickleLocation ?? ''), 10);
|
|
90
|
+
if (line > 0)
|
|
91
|
+
byTitle.set(k, { pwTestLine: 0, pickleLine: line, tags: v.tags, steps: [] });
|
|
92
|
+
}
|
|
93
|
+
out = { uri, feature, tests: [], byTitle };
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
out = null;
|
|
98
|
+
}
|
|
99
|
+
specCache.set(specFile, out);
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
const cells = (row) => row.trim().replace(/^\|/, '').replace(/\|$/, '').split('|').map(c => c.trim().replace(/\\\|/g, '|'));
|
|
103
|
+
const isRow = (l) => !!l && /^\s*\|/.test(l);
|
|
104
|
+
/** The Examples header and the row at `line` (1-based), when that line is an Examples row. */
|
|
105
|
+
function exampleAt(src, line) {
|
|
106
|
+
if (!isRow(src[line - 1]))
|
|
107
|
+
return undefined;
|
|
108
|
+
let top = line;
|
|
109
|
+
while (top > 1 && isRow(src[top - 2]))
|
|
110
|
+
top--;
|
|
111
|
+
if (top === line)
|
|
112
|
+
return undefined; // the header row itself
|
|
113
|
+
let outline;
|
|
114
|
+
for (let i = top - 2; i >= 0; i--) {
|
|
115
|
+
const m = /^\s*(?:Scenario Outline|Scenario Template|Scenario|Example):\s*(.*)$/.exec(src[i]);
|
|
116
|
+
if (m) {
|
|
117
|
+
outline = m[1].trim();
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return { header: cells(src[top - 1]), values: cells(src[line - 1]), outline };
|
|
122
|
+
}
|
|
123
|
+
/** The data table or doc string right under the step at `line`. */
|
|
124
|
+
function argumentAt(src, line) {
|
|
125
|
+
let i = line; // the line after the step (0-based index = line)
|
|
126
|
+
while (i < src.length && !src[i].trim())
|
|
127
|
+
i++;
|
|
128
|
+
if (isRow(src[i])) {
|
|
129
|
+
const rows = [];
|
|
130
|
+
while (isRow(src[i]))
|
|
131
|
+
rows.push(cells(src[i++]));
|
|
132
|
+
return { table: rows };
|
|
133
|
+
}
|
|
134
|
+
const open = /^(\s*)("""|```)/.exec(src[i] ?? '');
|
|
135
|
+
if (open) {
|
|
136
|
+
const indent = open[1].length, fence = open[2], body = [];
|
|
137
|
+
for (i++; i < src.length && !src[i].trim().startsWith(fence); i++)
|
|
138
|
+
body.push(src[i].slice(Math.min(indent, src[i].search(/\S|$/))));
|
|
139
|
+
return { docString: body.join('\n') };
|
|
140
|
+
}
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
function frame(src, line) {
|
|
144
|
+
if (line < 1 || line > src.length)
|
|
145
|
+
return undefined;
|
|
146
|
+
const lo = Math.max(1, line - 2), hi = Math.min(src.length, line + 2), w = String(hi).length;
|
|
147
|
+
const rows = [];
|
|
148
|
+
for (let n = lo; n <= hi; n++)
|
|
149
|
+
rows.push(`${n === line ? '>' : ' '} ${String(n).padStart(w)} | ${src[n - 1]}`);
|
|
150
|
+
return rows.join('\n');
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Turns a playwright-bdd test into a scenario row. `specFile` is the generated spec (absolute), `rel` makes a path
|
|
154
|
+
* relative the way the rest of the report does, `masker` is the report's masker.
|
|
155
|
+
*/
|
|
156
|
+
function applyBdd(t, specFile, roots, rel, masker) {
|
|
157
|
+
const spec = bddSpec(specFile, roots);
|
|
158
|
+
if (!spec)
|
|
159
|
+
return false;
|
|
160
|
+
const bt = spec.tests.find(x => x.pwTestLine === t.line) ?? spec.byTitle?.get([...t.path.slice(1), t.title].join('|'));
|
|
161
|
+
if (!bt)
|
|
162
|
+
return false;
|
|
163
|
+
const src = lines(spec.feature);
|
|
164
|
+
const generated = rel(specFile);
|
|
165
|
+
// a tag that became meta (@P1, @critical, @owner:asha) is not also a tag chip, as in the other Cucumber reports
|
|
166
|
+
t.tags = t.tags.filter(g => {
|
|
167
|
+
const tag = g.replace(/^@/, '');
|
|
168
|
+
const kv = /^([a-z_-]+)[:=](.+)$/i.exec(tag);
|
|
169
|
+
if (kv)
|
|
170
|
+
return !(kv[1].toLowerCase() in t.meta);
|
|
171
|
+
if (/^P[0-4]$/i.test(tag))
|
|
172
|
+
return !t.meta.priority;
|
|
173
|
+
if (/^(blocker|critical|major|minor|trivial)$/i.test(tag))
|
|
174
|
+
return !t.meta.severity;
|
|
175
|
+
return true;
|
|
176
|
+
});
|
|
177
|
+
t.file = rel(spec.feature);
|
|
178
|
+
t.line = bt.pickleLine;
|
|
179
|
+
t.column = undefined;
|
|
180
|
+
// Rule: blocks keep their label in the breadcrumb; an Outline's own describe is folded into the title
|
|
181
|
+
const rules = new Set(src.map(l => /^\s*Rule:\s*(.*)$/.exec(l)?.[1]?.trim()).filter(Boolean));
|
|
182
|
+
const ex = exampleAt(src, bt.pickleLine);
|
|
183
|
+
t.path = t.path.filter(p => !(ex?.outline && (p === ex.outline || p === masker.maskStr(ex.outline)))).map(p => rules.has(p) ? 'Rule: ' + p : p);
|
|
184
|
+
const data = [];
|
|
185
|
+
const table = (name, header, rows) => {
|
|
186
|
+
const sens = header.map(h => masker.isSensitive(h));
|
|
187
|
+
const masked = rows.map(r => r.map((c, i) => { if (sens[i]) {
|
|
188
|
+
masker.learn(c);
|
|
189
|
+
return '****';
|
|
190
|
+
} return masker.maskStr(c); }));
|
|
191
|
+
data.push({ name: masker.maskStr(name), kind: 'table', columns: header.map(h => masker.maskStr(h)), rows: masked });
|
|
192
|
+
};
|
|
193
|
+
if (ex) {
|
|
194
|
+
table('Examples', ex.header, [ex.values]);
|
|
195
|
+
const vals = ex.values.join(', ');
|
|
196
|
+
const base = /^Example #\d+$/.test(t.title) && ex.outline ? ex.outline : t.title;
|
|
197
|
+
t.title = masker.maskStr(`${base} (${vals.length > 60 ? vals.slice(0, 60) + '…' : vals})`);
|
|
198
|
+
}
|
|
199
|
+
for (const st of bt.steps) {
|
|
200
|
+
const arg = argumentAt(src, st.gherkinStepLine);
|
|
201
|
+
if (arg?.table && arg.table.length) {
|
|
202
|
+
const [head, ...rest] = arg.table;
|
|
203
|
+
if (rest.length)
|
|
204
|
+
table(st.textWithKeyword, head, rest);
|
|
205
|
+
else
|
|
206
|
+
data.push({ name: masker.maskStr(st.textWithKeyword), kind: 'table', columns: head.map(c => masker.maskStr(c)), rows: [] });
|
|
207
|
+
}
|
|
208
|
+
else if (typeof arg?.docString === 'string') {
|
|
209
|
+
data.push({ name: masker.maskStr(st.textWithKeyword), kind: 'text', text: masker.maskStr(arg.docString) });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
for (const r of t.results) {
|
|
213
|
+
if (data.length)
|
|
214
|
+
r.data.push(...data.map(d => ({ ...d })));
|
|
215
|
+
r.steps = scenarioSteps(r, bt, masker);
|
|
216
|
+
for (const e of r.errors)
|
|
217
|
+
pointAtFeature(e, generated, bt, t.file, src, masker);
|
|
218
|
+
// a step with no definition never starts: it is the failing step, not one left unrun
|
|
219
|
+
const missing = r.errors.map(e => /Missing step:\s*(.+)$/m.exec(e.message)?.[1]?.trim()).find(Boolean);
|
|
220
|
+
if (missing) {
|
|
221
|
+
const st = r.steps.find(x => x.status === 'skipped' && x.title === masker.maskStr(missing));
|
|
222
|
+
if (st) {
|
|
223
|
+
delete st.status;
|
|
224
|
+
st.error = masker.maskStr(`Missing step: ${missing}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
/** Background steps (run in a beforeEach hook) next to the scenario's own, then the steps that did not run.
|
|
231
|
+
* Gherkin steps are known by their text (keyword included, in whatever language the feature file is written). */
|
|
232
|
+
function scenarioSteps(r, bt, masker) {
|
|
233
|
+
const texts = new Set(bt.steps.map(s => masker.maskStr(s.textWithKeyword)));
|
|
234
|
+
const isGherkin = (s) => s.category === 'test.step' && texts.has(s.title);
|
|
235
|
+
const out = [...r.steps];
|
|
236
|
+
const before = out.findIndex(s => s.category === 'hook' && /^Before Hooks$/.test(s.title));
|
|
237
|
+
const bg = [];
|
|
238
|
+
if (before >= 0) {
|
|
239
|
+
const hooks = out[before];
|
|
240
|
+
const pull = (list) => list.filter(s => {
|
|
241
|
+
if (s.category === 'hook' && s.title === 'Background') {
|
|
242
|
+
s.steps = s.steps.filter(c => { if (isGherkin(c)) {
|
|
243
|
+
bg.push(c);
|
|
244
|
+
return false;
|
|
245
|
+
} return true; });
|
|
246
|
+
}
|
|
247
|
+
else
|
|
248
|
+
s.steps = pull(s.steps);
|
|
249
|
+
return true;
|
|
250
|
+
});
|
|
251
|
+
hooks.steps = pull(hooks.steps);
|
|
252
|
+
if (bg.length)
|
|
253
|
+
out.splice(before + 1, 0, ...bg);
|
|
254
|
+
}
|
|
255
|
+
const ran = out.filter(isGherkin).length;
|
|
256
|
+
const missing = bt.steps.slice(ran);
|
|
257
|
+
if (missing.length && r.status !== 'passed') {
|
|
258
|
+
const after = out.findIndex(s => s.category === 'hook' && /^After Hooks$/.test(s.title));
|
|
259
|
+
const skipped = missing.map(m => ({ title: masker.maskStr(m.textWithKeyword), category: 'test.step', duration: 0, status: 'skipped', steps: [] }));
|
|
260
|
+
out.splice(after >= 0 ? after : out.length, 0, ...skipped);
|
|
261
|
+
}
|
|
262
|
+
return out;
|
|
263
|
+
}
|
|
264
|
+
/** An error located in the generated spec (a missing step, a step that threw there) points at the feature file. */
|
|
265
|
+
function pointAtFeature(e, generated, bt, featureRel, src, masker) {
|
|
266
|
+
if (!e.location || e.location.file !== generated)
|
|
267
|
+
return;
|
|
268
|
+
const st = bt.steps.find(s => s.pwStepLine === e.location.line);
|
|
269
|
+
const line = st?.gherkinStepLine ?? bt.pickleLine;
|
|
270
|
+
e.location = { file: featureRel, line, column: 0 };
|
|
271
|
+
const snip = frame(src, line);
|
|
272
|
+
if (snip)
|
|
273
|
+
e.snippet = masker.maskStr(snip);
|
|
274
|
+
}
|
package/dist/cypress/index.d.ts
CHANGED
|
@@ -87,6 +87,30 @@ export interface AttemptPayload {
|
|
|
87
87
|
steps?: StepData[];
|
|
88
88
|
api?: ApiCall[];
|
|
89
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
|
+
};
|
|
90
114
|
}
|
|
91
115
|
export interface ReportingLabsCypressHandlers {
|
|
92
116
|
beforeRun: (details: CyBeforeRun) => void;
|
|
@@ -110,6 +134,8 @@ export declare class CypressCollector {
|
|
|
110
134
|
private assetsReady;
|
|
111
135
|
private base;
|
|
112
136
|
private attempts;
|
|
137
|
+
private ranBeforeRun;
|
|
138
|
+
private warnedReplaced;
|
|
113
139
|
constructor(options: ReportingLabsCypressOptions, config?: Record<string, unknown>);
|
|
114
140
|
addAttempt(p: AttemptPayload): void;
|
|
115
141
|
beforeRun(d?: CyBeforeRun): void;
|
|
@@ -121,6 +147,9 @@ export declare class CypressCollector {
|
|
|
121
147
|
toTest(ct: CyTest, abs: string, file: string, startTime: number): TestData;
|
|
122
148
|
/** What the support file sent for this test: real per-attempt times, steps, API calls, each attempt's error, meta(). */
|
|
123
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;
|
|
124
153
|
private maskStep;
|
|
125
154
|
/** displayError is the message plus a stack (" at …"); the first frame in the spec file gives the location. */
|
|
126
155
|
toError(display: string, abs: string): ErrorData;
|
package/dist/cypress/index.js
CHANGED
|
@@ -57,6 +57,11 @@ exports.reportingLabs = reportingLabs;
|
|
|
57
57
|
* come from the spec file itself. Cypress allows one handler per event, so if your config already listens to
|
|
58
58
|
* before:run / after:spec / after:run, call the handlers this returns from your own (see README).
|
|
59
59
|
*
|
|
60
|
+
* Cucumber (@badeball/cypress-cucumber-preprocessor): call reportingLabs() after addCucumberPreprocessorPlugin(). The
|
|
61
|
+
* scenarios become report rows with their Gherkin steps, tags as tags and meta, Outline rows and data tables, and the
|
|
62
|
+
* preprocessor's own before:run / after:spec / after:run handlers (its messages, JSON and HTML reports) still run:
|
|
63
|
+
* ours call them, since Cypress keeps only the handler registered last.
|
|
64
|
+
*
|
|
60
65
|
* Nothing here touches the Playwright or WebdriverIO reporters; it only reuses the shared helpers.
|
|
61
66
|
*/
|
|
62
67
|
const fs = __importStar(require("fs"));
|
|
@@ -100,12 +105,47 @@ function reportingLabs(on, config = {}, options = {}) {
|
|
|
100
105
|
if (typeof on === 'function') {
|
|
101
106
|
// what the support file collects in the browser; Cypress merges this with the project's own tasks
|
|
102
107
|
on('task', { [ATTEMPT_TASK]: (payload) => { safe(() => collector.addAttempt(payload)); return null; } });
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
on('
|
|
108
|
+
// Cypress keeps the handler registered last: if the Cucumber preprocessor registered its own before ours, ours run
|
|
109
|
+
// its handlers too, so its reports keep working
|
|
110
|
+
on('before:run', async (d) => { handlers.beforeRun(d); await cucumberHandler(config, 'beforeRunHandler'); });
|
|
111
|
+
on('after:spec', async (spec, results) => { handlers.afterSpec(spec, results); await cucumberHandler(config, 'afterSpecHandler', spec, results); });
|
|
112
|
+
on('after:run', async (results) => { const out = await handlers.afterRun(results); await cucumberHandler(config, 'afterRunHandler', results); return out; });
|
|
106
113
|
}
|
|
107
114
|
return handlers;
|
|
108
115
|
}
|
|
116
|
+
const CUCUMBER = '@badeball/cypress-cucumber-preprocessor';
|
|
117
|
+
const CUCUMBER_FLAG = '__cypress_cucumber_preprocessor_dont_use_this_suite';
|
|
118
|
+
/** Runs one of the Cucumber preprocessor's run handlers, when addCucumberPreprocessorPlugin() was called for this config. */
|
|
119
|
+
async function cucumberHandler(config, name, ...args) {
|
|
120
|
+
const attached = (k) => { try {
|
|
121
|
+
return !!config?.[k]?.[CUCUMBER_FLAG]?.isEventHandlersAttached;
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
return false;
|
|
125
|
+
} };
|
|
126
|
+
if (!attached('expose') && !attached('env'))
|
|
127
|
+
return;
|
|
128
|
+
let fn;
|
|
129
|
+
try {
|
|
130
|
+
// the copy the project's cypress.config loaded, so the handlers share its state
|
|
131
|
+
const root = typeof config?.projectRoot === 'string' && config.projectRoot ? config.projectRoot : process.cwd();
|
|
132
|
+
fn = require(require.resolve(CUCUMBER, { paths: [root] }))[name];
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
if (typeof fn !== 'function')
|
|
138
|
+
return;
|
|
139
|
+
try {
|
|
140
|
+
await fn(config, ...args);
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
// its handlers already run on their own (cypress-on-fix, or called from the project's handler): nothing to do
|
|
144
|
+
if (/^Unexpected state in \w+Handler/.test(String(e?.message ?? '')))
|
|
145
|
+
return;
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
109
149
|
exports.default = reportingLabs;
|
|
110
150
|
function safe(fn) { try {
|
|
111
151
|
fn();
|
|
@@ -144,6 +184,8 @@ class CypressCollector {
|
|
|
144
184
|
this.assetCounter = 0;
|
|
145
185
|
this.assetsReady = false;
|
|
146
186
|
this.attempts = new Map();
|
|
187
|
+
this.ranBeforeRun = false;
|
|
188
|
+
this.warnedReplaced = false;
|
|
147
189
|
this.masker = (0, mask_1.makeMasker)(options.maskKeys ?? [], { knownValues: options.maskValues ?? [], fromEnv: options.maskFromEnv !== false });
|
|
148
190
|
this.base = typeof config.projectRoot === 'string' && config.projectRoot ? config.projectRoot : process.cwd();
|
|
149
191
|
this.outDir = path.resolve(this.base, options.outputFolder || 'reporting-labs');
|
|
@@ -152,12 +194,20 @@ class CypressCollector {
|
|
|
152
194
|
addAttempt(p) {
|
|
153
195
|
if (!p || !Array.isArray(p.titlePath))
|
|
154
196
|
return;
|
|
197
|
+
// cypress run fires before:run first: without it, a later on('before:run') replaced ours (and so after:run too)
|
|
198
|
+
if (!this.ranBeforeRun && !this.warnedReplaced && this.config.isTextTerminal === true) {
|
|
199
|
+
this.warnedReplaced = true;
|
|
200
|
+
console.warn('\n reporting-labs: our before:run handler was replaced, so no report will be written. Cypress keeps one handler\n' +
|
|
201
|
+
' per event: call reportingLabs() last in setupNodeEvents (after addCucumberPreprocessorPlugin() and other plugins),\n' +
|
|
202
|
+
' or call its handlers from yours (see the README).\n');
|
|
203
|
+
}
|
|
155
204
|
const key = attemptKey(p.spec, p.titlePath);
|
|
156
205
|
const list = this.attempts.get(key) ?? [];
|
|
157
206
|
list[Math.max(0, Number(p.retry) || 0)] = p;
|
|
158
207
|
this.attempts.set(key, list);
|
|
159
208
|
}
|
|
160
209
|
beforeRun(d = {}) {
|
|
210
|
+
this.ranBeforeRun = true;
|
|
161
211
|
this.startTime = Date.now();
|
|
162
212
|
this.browser = browserLabel(d.browser);
|
|
163
213
|
this.cypressVersion = d.cypressVersion || '';
|
|
@@ -302,6 +352,9 @@ class CypressCollector {
|
|
|
302
352
|
enrich(t, attempts, abs) {
|
|
303
353
|
if (!attempts || !attempts.length)
|
|
304
354
|
return;
|
|
355
|
+
const g = [...attempts].reverse().find(a => a?.gherkin)?.gherkin;
|
|
356
|
+
if (g)
|
|
357
|
+
this.applyGherkin(t, g, attempts, abs);
|
|
305
358
|
t.results.forEach((r, i) => {
|
|
306
359
|
const a = attempts[i];
|
|
307
360
|
if (!a)
|
|
@@ -318,11 +371,21 @@ class CypressCollector {
|
|
|
318
371
|
r.errors.push(this.toError([a.err.message, a.err.stack ? a.err.stack.replace(/^[^\n]*\n?/, '') : ''].filter(Boolean).join('\n'), abs));
|
|
319
372
|
const cf = a.err?.codeFrame;
|
|
320
373
|
const e = r.errors[0];
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
374
|
+
// the file Cypress points at: the spec, or a support / step definition file it calls into (not a library's code)
|
|
375
|
+
const src = cf?.relativeFile ? (/(^|[\\/])node_modules[\\/]/.test(cf.relativeFile) ? '' : path.resolve(this.base, cf.relativeFile)) : abs;
|
|
376
|
+
if (e && cf?.line && !e.location && src && fs.existsSync(src)) {
|
|
377
|
+
e.location = { file: this.rel(src), line: cf.line, column: cf.column ?? 0 };
|
|
378
|
+
const snip = codeFrame(src, cf.line, cf.column ?? 0);
|
|
324
379
|
if (snip)
|
|
325
|
-
e.snippet = snip;
|
|
380
|
+
e.snippet = this.masker.maskStr(snip);
|
|
381
|
+
}
|
|
382
|
+
// Cucumber without a code frame: the step in the feature file
|
|
383
|
+
const at = a.gherkin?.stoppedAt;
|
|
384
|
+
if (e && !e.location && at?.line && abs) {
|
|
385
|
+
e.location = { file: this.rel(abs), line: at.line, column: 0 };
|
|
386
|
+
const snip = codeFrame(abs, at.line, 0);
|
|
387
|
+
if (snip)
|
|
388
|
+
e.snippet = this.masker.maskStr(snip);
|
|
326
389
|
}
|
|
327
390
|
});
|
|
328
391
|
t.duration = t.results.reduce((n, r) => n + r.duration, 0);
|
|
@@ -334,9 +397,64 @@ class CypressCollector {
|
|
|
334
397
|
t.meta[k.toLowerCase()] = this.masker.maskStr(Array.isArray(v) ? v.join(', ') : String(v));
|
|
335
398
|
}
|
|
336
399
|
}
|
|
400
|
+
/** A Cucumber scenario: its feature file line, Rule, tags as tags and meta, Outline row and data tables. Runs before the
|
|
401
|
+
* steps are masked: a password column in Examples or a data table teaches the masker its values. */
|
|
402
|
+
applyGherkin(t, g, attempts, abs) {
|
|
403
|
+
const data = [];
|
|
404
|
+
const table = (name, header, rows) => {
|
|
405
|
+
const sens = header.map(h => this.masker.isSensitive(h));
|
|
406
|
+
const masked = rows.map(r => r.map((c, i) => { if (sens[i]) {
|
|
407
|
+
this.masker.learn(c);
|
|
408
|
+
return '****';
|
|
409
|
+
} return c; }));
|
|
410
|
+
data.push({ name, kind: 'table', columns: header.map(h => this.masker.maskStr(h)), rows: masked.map(r => r.map(c => c === '****' ? c : this.masker.maskStr(c))) });
|
|
411
|
+
};
|
|
412
|
+
const ex = g.example;
|
|
413
|
+
if (ex && Array.isArray(ex.header) && Array.isArray(ex.values))
|
|
414
|
+
table('Examples', ex.header.map(String), [ex.values.map(String)]);
|
|
415
|
+
for (const a of g.args ?? []) {
|
|
416
|
+
const name = this.masker.maskStr(String(a.step ?? 'Step'));
|
|
417
|
+
if (Array.isArray(a.table) && a.table.length) {
|
|
418
|
+
const [head, ...rest] = a.table.map(r => (r ?? []).map(String));
|
|
419
|
+
if (rest.length)
|
|
420
|
+
table(name, head, rest);
|
|
421
|
+
else
|
|
422
|
+
data.push({ name, kind: 'table', columns: head.map(c => this.masker.maskStr(c)), rows: [] });
|
|
423
|
+
}
|
|
424
|
+
else if (typeof a.docString === 'string')
|
|
425
|
+
data.push({ name, kind: 'text', text: this.masker.maskStr(a.docString) });
|
|
426
|
+
}
|
|
427
|
+
if (data.length)
|
|
428
|
+
for (const r of t.results)
|
|
429
|
+
r.data.push(...data.map(d => ({ ...d })));
|
|
430
|
+
if (typeof g.line === 'number' && g.line > 0)
|
|
431
|
+
t.line = g.line;
|
|
432
|
+
if (g.feature)
|
|
433
|
+
t.path = [this.masker.maskStr(String(g.feature)), ...(g.rule ? ['Rule: ' + this.masker.maskStr(String(g.rule))] : [])];
|
|
434
|
+
if (ex && Array.isArray(ex.values) && ex.values.length) {
|
|
435
|
+
// like the Cucumber JVM plugin: the example's values instead of Cypress's "(example #2)"
|
|
436
|
+
const vals = ex.values.map(String).join(', ');
|
|
437
|
+
const base = t.title.replace(/\s*\(example #\d+\)$/, '');
|
|
438
|
+
t.title = this.masker.maskStr(`${base} (${vals.length > 60 ? vals.slice(0, 60) + '…' : vals})`);
|
|
439
|
+
}
|
|
440
|
+
const { meta, clean } = (0, reporter_1.metaFromTags)((g.tags ?? []).map(String), reporter_1.META_KEYS);
|
|
441
|
+
for (const [k, v] of Object.entries(meta))
|
|
442
|
+
if (!(k in t.meta))
|
|
443
|
+
t.meta[k] = this.masker.maskStr(v);
|
|
444
|
+
for (const tag of clean)
|
|
445
|
+
if (!t.tags.includes(tag))
|
|
446
|
+
t.tags.push(tag);
|
|
447
|
+
const last = attempts[attempts.length - 1]?.gherkin?.stoppedAt;
|
|
448
|
+
if (t.outcome === 'skipped' && last?.state === 'pending' && last.step) {
|
|
449
|
+
t.note = `The step "${this.masker.maskStr(last.step)}" is pending: its step definition returned "pending".`;
|
|
450
|
+
t.annotations = t.annotations.filter(x => x.type !== 'skip');
|
|
451
|
+
}
|
|
452
|
+
void abs;
|
|
453
|
+
}
|
|
337
454
|
maskStep(st) {
|
|
338
455
|
return { title: this.masker.maskStr(String(st.title ?? '')), category: String(st.category ?? 'cy'), duration: Math.max(0, Math.round(Number(st.duration) || 0)),
|
|
339
|
-
...(st.error ? { error: this.masker.maskStr(stripAnsi(String(st.error))) } : {}),
|
|
456
|
+
...(st.error ? { error: this.masker.maskStr(stripAnsi(String(st.error))) } : {}), ...(st.status === 'skipped' ? { status: 'skipped' } : {}),
|
|
457
|
+
steps: (st.steps ?? []).map(c => this.maskStep(c)) };
|
|
340
458
|
}
|
|
341
459
|
/** displayError is the message plus a stack (" at …"); the first frame in the spec file gives the location. */
|
|
342
460
|
toError(display, abs) {
|
|
@@ -350,7 +468,8 @@ class CypressCollector {
|
|
|
350
468
|
const ex = (0, explain_1.explainError)(message);
|
|
351
469
|
if (ex)
|
|
352
470
|
d.explain = ex;
|
|
353
|
-
|
|
471
|
+
// a feature file runs as a bundle: its line numbers in the stack are the bundle's (the step comes from the support file)
|
|
472
|
+
if (abs && !/\.feature$/i.test(abs)) {
|
|
354
473
|
const base = path.basename(abs).replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
355
474
|
const m = new RegExp(`${base}:(\\d+):(\\d+)`).exec(stack ?? clean);
|
|
356
475
|
if (m) {
|
|
@@ -358,7 +477,7 @@ class CypressCollector {
|
|
|
358
477
|
d.location = { file: this.rel(abs), line, column };
|
|
359
478
|
const snip = codeFrame(abs, line, column);
|
|
360
479
|
if (snip)
|
|
361
|
-
d.snippet = snip;
|
|
480
|
+
d.snippet = this.masker.maskStr(snip);
|
|
362
481
|
}
|
|
363
482
|
}
|
|
364
483
|
return d;
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* - cy.request calls with their request and response, and the app's own fetch / XHR calls, for the API tab
|
|
11
11
|
* - the error of every attempt with Cypress's code frame (the Node side only gets the last one)
|
|
12
12
|
* - meta({ owner, priority, … }) called in the test
|
|
13
|
+
* - with @badeball/cypress-cucumber-preprocessor: the Gherkin steps (Given / When / Then) with the commands each ran,
|
|
14
|
+
* Before / After hooks, the steps a failure left unrun, and the scenario's line, tags, example row, data tables
|
|
13
15
|
* A value typed into a password field is masked here; everything else is masked by the plugin with the report's
|
|
14
16
|
* masking rules. Nothing in this file may ever fail a test: every handler is guarded.
|
|
15
17
|
*
|
package/dist/cypress/support.js
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
* - cy.request calls with their request and response, and the app's own fetch / XHR calls, for the API tab
|
|
12
12
|
* - the error of every attempt with Cypress's code frame (the Node side only gets the last one)
|
|
13
13
|
* - meta({ owner, priority, … }) called in the test
|
|
14
|
+
* - with @badeball/cypress-cucumber-preprocessor: the Gherkin steps (Given / When / Then) with the commands each ran,
|
|
15
|
+
* Before / After hooks, the steps a failure left unrun, and the scenario's line, tags, example row, data tables
|
|
14
16
|
* A value typed into a password field is masked here; everything else is masked by the plugin with the report's
|
|
15
17
|
* masking rules. Nothing in this file may ever fail a test: every handler is guarded.
|
|
16
18
|
*
|
|
@@ -77,15 +79,19 @@ function build(t) {
|
|
|
77
79
|
spec: Cypress.spec && (Cypress.spec.relative || Cypress.spec.name),
|
|
78
80
|
titlePath: typeof t.titlePath === 'function' ? t.titlePath() : [t.title],
|
|
79
81
|
retry, state: t.state, start, duration, err,
|
|
80
|
-
steps: steps(start + duration, err?.message),
|
|
82
|
+
steps: steps(start + duration, err?.message, t),
|
|
81
83
|
api: api(),
|
|
82
84
|
meta: currentMeta,
|
|
85
|
+
gherkin: gherkin(t),
|
|
83
86
|
};
|
|
84
87
|
}
|
|
85
88
|
const clean = (s) => String(s ?? '').replace(/\*\*/g, '').replace(/\s+/g, ' ').trim();
|
|
86
89
|
const SKIP = new Set(['new url', 'page load', 'route', 'xhr', 'fetch', 'task', 'log']);
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
const HOOKS = /^(Before|After|BeforeStep|AfterStep|BeforeAll|AfterAll)$/;
|
|
91
|
+
/** Commands as steps: hooks grouped, chained commands under their parent, assertions under what they check, commands
|
|
92
|
+
* inside a log group (a Gherkin step, cy.within, a custom command that opens a group) under that group. */
|
|
93
|
+
function steps(end, errMsg, t) {
|
|
94
|
+
const g = scenario(t);
|
|
89
95
|
const items = logs.filter(c => {
|
|
90
96
|
const name = c.log.get('name');
|
|
91
97
|
if (SKIP.has(name) && name !== 'route')
|
|
@@ -94,11 +100,26 @@ function steps(end, errMsg) {
|
|
|
94
100
|
return false; // page loads, url changes, the app's own fetch / XHR (those go to the API tab)
|
|
95
101
|
if (c.log.get('hidden'))
|
|
96
102
|
return false;
|
|
103
|
+
if (g && name === 'DataTable')
|
|
104
|
+
return false; // sent with the scenario (see gherkin())
|
|
97
105
|
return true;
|
|
98
106
|
});
|
|
99
107
|
const out = [];
|
|
100
108
|
const parents = new Map(); // chainerId → parent step
|
|
109
|
+
const groups = new Map(); // log id of a group → its step
|
|
110
|
+
const up = new Map(); // step → the step it is under
|
|
111
|
+
// a step's time and failure count for every step it is under
|
|
112
|
+
const add = (parent, step) => {
|
|
113
|
+
parent.steps.push(step);
|
|
114
|
+
up.set(step, parent);
|
|
115
|
+
for (let p = parent; p; p = up.get(p)) {
|
|
116
|
+
p.duration += step.duration;
|
|
117
|
+
if (step.error)
|
|
118
|
+
p.error = step.error;
|
|
119
|
+
}
|
|
120
|
+
};
|
|
101
121
|
let hookStep, hookName;
|
|
122
|
+
let ran = 0; // Gherkin steps that started (the rest of the scenario's steps did not run)
|
|
102
123
|
items.forEach((c, i) => {
|
|
103
124
|
const next = items[i + 1];
|
|
104
125
|
const name = String(c.log.get('name') || '');
|
|
@@ -108,26 +129,31 @@ function steps(end, errMsg) {
|
|
|
108
129
|
if (name === 'request' && !message)
|
|
109
130
|
message = clean(display(c.log)); // "POST 200 /api/users"
|
|
110
131
|
const isAssert = name === 'assert';
|
|
132
|
+
const group = !!c.log.get('groupStart');
|
|
133
|
+
const inGroup = groups.get(String(c.log.get('group') ?? ''));
|
|
134
|
+
const gherkinHook = !!g && group && HOOKS.test(name.trim());
|
|
135
|
+
const gherkinStep = !!g && group && !gherkinHook && /^\*\*[\s\S]*\*\*$/.test(String(c.log.get('message') ?? '').trim());
|
|
111
136
|
const step = {
|
|
112
|
-
title:
|
|
113
|
-
|
|
137
|
+
title: gherkinHook ? `${name.trim()} hook${message ? ': ' + message : ''}`
|
|
138
|
+
: gherkinStep ? `${name.trim()} ${message}`
|
|
139
|
+
: name === 'route' ? clean(routeTitle(c.log)) : isAssert ? message : `${name}${message ? ' ' + message : ''}`,
|
|
140
|
+
category: gherkinHook ? 'hook' : gherkinStep ? 'test.step' : isAssert ? 'assert' : 'cy',
|
|
114
141
|
duration: Math.max(0, (next ? next.start : end) - c.start),
|
|
115
142
|
steps: [],
|
|
116
143
|
};
|
|
144
|
+
if (gherkinStep && !inGroup)
|
|
145
|
+
ran++;
|
|
117
146
|
if (c.log.get('state') === 'failed')
|
|
118
147
|
step.error = clean(errMsg || c.log.get('err')?.message || 'failed');
|
|
119
148
|
// the hook it ran in: one step per hook, the commands inside
|
|
120
|
-
let container
|
|
149
|
+
let container;
|
|
121
150
|
if (c.hook) {
|
|
122
151
|
if (!hookStep || hookName !== c.hook) {
|
|
123
152
|
hookName = c.hook;
|
|
124
153
|
hookStep = { title: `${camel(c.hook)} hook`, category: 'hook', duration: 0, steps: [] };
|
|
125
154
|
out.push(hookStep);
|
|
126
155
|
}
|
|
127
|
-
|
|
128
|
-
if (step.error)
|
|
129
|
-
hookStep.error = step.error;
|
|
130
|
-
container = hookStep.steps;
|
|
156
|
+
container = hookStep;
|
|
131
157
|
}
|
|
132
158
|
else {
|
|
133
159
|
hookStep = undefined;
|
|
@@ -135,18 +161,26 @@ function steps(end, errMsg) {
|
|
|
135
161
|
}
|
|
136
162
|
const chainer = String(c.log.get('chainerId') || '');
|
|
137
163
|
const parent = c.log.get('type') === 'child' ? parents.get(chainer) : undefined;
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
parents.set(chainer, step);
|
|
148
|
-
}
|
|
164
|
+
const under = parent ?? inGroup ?? container;
|
|
165
|
+
if (under)
|
|
166
|
+
add(under, step);
|
|
167
|
+
else
|
|
168
|
+
out.push(step);
|
|
169
|
+
if (!parent && chainer)
|
|
170
|
+
parents.set(chainer, step);
|
|
171
|
+
if (group)
|
|
172
|
+
groups.set(String(c.log.get('id') ?? ''), step);
|
|
149
173
|
});
|
|
174
|
+
// Cucumber stops a scenario at the first failing step: the steps after it are listed, greyed out. A step whose
|
|
175
|
+
// definition returned "pending" is greyed out too.
|
|
176
|
+
if (g && t && t.state === 'pending') {
|
|
177
|
+
const last = [...out].reverse().find(x => x.category === 'test.step');
|
|
178
|
+
if (last && !last.error)
|
|
179
|
+
last.status = 'skipped';
|
|
180
|
+
}
|
|
181
|
+
if (g)
|
|
182
|
+
for (const ps of g.pickle.steps.slice(ran))
|
|
183
|
+
out.push({ title: `${keywordOf(g, ps)} ${ps.text}`, category: 'test.step', duration: 0, status: 'skipped', steps: [] });
|
|
150
184
|
return out;
|
|
151
185
|
}
|
|
152
186
|
function camel(hookName) {
|
|
@@ -229,3 +263,95 @@ function parse(v) {
|
|
|
229
263
|
return v;
|
|
230
264
|
}
|
|
231
265
|
}
|
|
266
|
+
const astCache = new WeakMap();
|
|
267
|
+
/** The scenario this test runs, or undefined (not a feature file, or the state belongs to another test). */
|
|
268
|
+
function scenario(t) {
|
|
269
|
+
try {
|
|
270
|
+
const ts = globalThis.testState;
|
|
271
|
+
const pickle = ts && ts.pickle;
|
|
272
|
+
if (!pickle || !ts.gherkinDocument || !Array.isArray(pickle.steps))
|
|
273
|
+
return undefined;
|
|
274
|
+
const title = String((t && t.title) || '');
|
|
275
|
+
const name = String(pickle.name || '');
|
|
276
|
+
if (title && name && title !== name && !title.startsWith(name + ' (example #'))
|
|
277
|
+
return undefined;
|
|
278
|
+
let ast = astCache.get(ts.gherkinDocument);
|
|
279
|
+
if (!ast) {
|
|
280
|
+
ast = index(ts.gherkinDocument);
|
|
281
|
+
astCache.set(ts.gherkinDocument, ast);
|
|
282
|
+
}
|
|
283
|
+
return { doc: ts.gherkinDocument, pickle, step: ts.pickleStep, ast };
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
return undefined;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/** Every Background / Scenario step, Scenario and Examples row of the feature by its id. */
|
|
290
|
+
function index(doc) {
|
|
291
|
+
const m = new Map();
|
|
292
|
+
const visit = (children, rule) => {
|
|
293
|
+
for (const ch of children || []) {
|
|
294
|
+
const bg = ch.background;
|
|
295
|
+
if (bg)
|
|
296
|
+
for (const st of bg.steps || [])
|
|
297
|
+
m.set(st.id, { step: st });
|
|
298
|
+
const sc = ch.scenario;
|
|
299
|
+
if (sc) {
|
|
300
|
+
m.set(sc.id, { scenario: sc, rule });
|
|
301
|
+
for (const st of sc.steps || [])
|
|
302
|
+
m.set(st.id, { step: st });
|
|
303
|
+
for (const ex of sc.examples || [])
|
|
304
|
+
for (const row of ex.tableBody || [])
|
|
305
|
+
m.set(row.id, { row, examples: ex });
|
|
306
|
+
}
|
|
307
|
+
if (ch.rule)
|
|
308
|
+
visit(ch.rule.children, ch.rule);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
visit(doc.feature && doc.feature.children);
|
|
312
|
+
return m;
|
|
313
|
+
}
|
|
314
|
+
function keywordOf(g, ps) {
|
|
315
|
+
const node = g.ast.get(ps && ps.astNodeIds && ps.astNodeIds[0]);
|
|
316
|
+
return String((node && node.step && node.step.keyword) || '').trim() || '*';
|
|
317
|
+
}
|
|
318
|
+
function lineOf(g, ps) {
|
|
319
|
+
const node = g.ast.get(ps && ps.astNodeIds && ps.astNodeIds[0]);
|
|
320
|
+
return node && node.step && node.step.location ? node.step.location.line : undefined;
|
|
321
|
+
}
|
|
322
|
+
/** What the report needs about the scenario: where it is, its tags, its example row, data tables and doc strings. */
|
|
323
|
+
function gherkin(t) {
|
|
324
|
+
const g = scenario(t);
|
|
325
|
+
if (!g)
|
|
326
|
+
return undefined;
|
|
327
|
+
const ids = g.pickle.astNodeIds || [];
|
|
328
|
+
const sc = g.ast.get(ids[0]) || {};
|
|
329
|
+
const row = ids.length > 1 ? g.ast.get(ids[ids.length - 1]) : undefined;
|
|
330
|
+
const f = g.doc.feature || {};
|
|
331
|
+
const out = {
|
|
332
|
+
feature: f.name, rule: sc.rule && sc.rule.name,
|
|
333
|
+
keyword: sc.scenario && sc.scenario.keyword,
|
|
334
|
+
line: (row && row.row && row.row.location && row.row.location.line) || (sc.scenario && sc.scenario.location && sc.scenario.location.line),
|
|
335
|
+
tags: (g.pickle.tags || []).map((x) => String(x.name)),
|
|
336
|
+
};
|
|
337
|
+
if (row && row.row && row.examples) {
|
|
338
|
+
out.example = { header: (row.examples.tableHeader && row.examples.tableHeader.cells || []).map((c) => String(c.value)), values: (row.row.cells || []).map((c) => String(c.value)) };
|
|
339
|
+
}
|
|
340
|
+
const args = [];
|
|
341
|
+
for (const ps of g.pickle.steps) {
|
|
342
|
+
const a = ps.argument;
|
|
343
|
+
if (!a)
|
|
344
|
+
continue;
|
|
345
|
+
const step = `${keywordOf(g, ps)} ${ps.text}`;
|
|
346
|
+
if (a.dataTable)
|
|
347
|
+
args.push({ step, table: (a.dataTable.rows || []).map((r) => (r.cells || []).map((c) => String(c.value))) });
|
|
348
|
+
else if (a.docString)
|
|
349
|
+
args.push({ step, docString: String(a.docString.content ?? '') });
|
|
350
|
+
}
|
|
351
|
+
if (args.length)
|
|
352
|
+
out.args = args;
|
|
353
|
+
// the step that was running when the test stopped: failed, or returned "pending"
|
|
354
|
+
if (g.step && (t.state === 'failed' || t.state === 'pending'))
|
|
355
|
+
out.stoppedAt = { step: `${keywordOf(g, g.step)} ${g.step.text}`, line: lineOf(g, g.step), state: t.state };
|
|
356
|
+
return out;
|
|
357
|
+
}
|
package/dist/explain.js
CHANGED
|
@@ -40,6 +40,13 @@ function explainError(raw) {
|
|
|
40
40
|
const timeoutMs = Number(pick(msg, /(?:Timeout|timeout of|Timed out)\s+(\d+)ms/i) ?? 0) || undefined;
|
|
41
41
|
const action = pick(first, /^(?:Error: |TimeoutError: )?([a-zA-Z]+\.[a-zA-Z]+):/);
|
|
42
42
|
const url = pick(msg, /(?:navigating to|at)\s+"?(https?:\/\/[^\s"]+)/);
|
|
43
|
+
// ── playwright-bdd: a step with no step definition, or with several ──────
|
|
44
|
+
const bddMissing = msg.match(/^(?:Error:\s*)?Missing step:\s*(.+)$/m);
|
|
45
|
+
if (bddMissing)
|
|
46
|
+
return out('script', `The step "${short(bddMissing[1].trim(), 90)}" has no step definition.`, 'Add a Given / When / Then for it in your steps files (npx bddgen prints a snippet for it), or check the steps paths in defineBddConfig().', { label: 'Step not defined' });
|
|
47
|
+
const bddTwice = msg.match(/Multiple definitions matched scenario step\.\s*\n\s*Step:\s*(.+?)(?:\s+#\s|\n|$)/);
|
|
48
|
+
if (bddTwice)
|
|
49
|
+
return out('script', `More than one step definition matches "${short(bddTwice[1].trim(), 90)}".`, 'Make the step texts or their expressions differ, so exactly one step definition matches.', { label: 'Step defined twice' });
|
|
43
50
|
// ── Whole-test and hook timeouts ─────────────────────────────────────────
|
|
44
51
|
let m = msg.match(/"(beforeAll|beforeEach|afterAll|afterEach)" hook timeout of (\d+)ms exceeded/);
|
|
45
52
|
if (m)
|
|
@@ -177,6 +184,13 @@ function explainCypress(msg, out) {
|
|
|
177
184
|
const cmd = pick(text, /`?(cy\.\w+)\(\)`?\s+(?:failed|timed out|could not)/);
|
|
178
185
|
const isCy = !!retry || !!cmd || /CypressError|originated from your application code|for your remote page to load|error preparing this test file|^`?cy\.\w+\(\)/.test(msg);
|
|
179
186
|
const chai = text.match(/^expected ([\s\S]+?) (?:not to|to(?: (not))?) (deeply equal|have length|have text|have value|equal|eql|be|have|include|contain|match|exist)\b\s*([\s\S]*)$/);
|
|
187
|
+
// ── Cucumber (@badeball/cypress-cucumber-preprocessor): a step with no step definition, or with several ──
|
|
188
|
+
let g = text.match(/Step implementation missing for:? "?([^\n]+?)"?\.?\s*(?:\n|$)/);
|
|
189
|
+
if (g)
|
|
190
|
+
return out('script', `The step "${short(g[1], 90)}" has no step definition.`, 'Add a Given / When / Then for it in your step definitions (the error shows a snippet), or check the stepDefinitions paths in the preprocessor config.', { label: 'Step not defined' });
|
|
191
|
+
g = text.match(/Multiple matching step definitions for:? "?([^\n]+?)"?\s*(?:\n|$)/);
|
|
192
|
+
if (g)
|
|
193
|
+
return out('script', `More than one step definition matches "${short(g[1], 90)}".`, 'Make the step texts or their expressions differ, so exactly one step definition matches.', { label: 'Step defined twice' });
|
|
180
194
|
if (!isCy && !chai)
|
|
181
195
|
return undefined;
|
|
182
196
|
// ── the spec file itself could not be bundled / loaded: no test in it ran ──
|
package/dist/mask.js
CHANGED
|
@@ -41,6 +41,7 @@ const NOT_A_SECRET = new Set(['valid', 'invalid', 'visible', 'hidden', 'required
|
|
|
41
41
|
'correct', 'incorrect', 'wrong', 'right', 'expired', 'set', 'unset', 'not', 'present', 'absent', 'ok', 'true', 'false', 'masked', 'blank',
|
|
42
42
|
'too', 'the', 'a', 'an', 'same', 'different', 'changed', 'unchanged', 'shown', 'displayed', 'accepted', 'rejected', 'weak', 'strong']);
|
|
43
43
|
const esc = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
44
|
+
const NOT_SECRET_ENV = new Set(['PWD', 'OLDPWD']);
|
|
44
45
|
function makeMasker(extraKeys = [], opts = {}) {
|
|
45
46
|
const keys = [...DEFAULT_KEYS, ...extraKeys.map(k => k.toLowerCase())];
|
|
46
47
|
const isSensitive = (k) => { const l = k.toLowerCase(); return keys.some(s => l === s || l.includes(s)); };
|
|
@@ -81,9 +82,11 @@ function makeMasker(extraKeys = [], opts = {}) {
|
|
|
81
82
|
if (opts.fromEnv !== false) {
|
|
82
83
|
// PASSWORD=…, API_TOKEN=…, OAUTH_CLIENT_SECRET=… in the environment: the values a CI job injects are the
|
|
83
84
|
// ones that end up in log lines. Short values are skipped so a plain word is not blanked everywhere.
|
|
85
|
+
// PWD / OLDPWD are the shell's current folder ("pwd" is also a password key): learning them would blank the
|
|
86
|
+
// project path in every stack trace and editor link
|
|
84
87
|
try {
|
|
85
88
|
for (const [k, v] of Object.entries(process.env))
|
|
86
|
-
if (isSensitive(k))
|
|
89
|
+
if (isSensitive(k) && !NOT_SECRET_ENV.has(k.toUpperCase()))
|
|
87
90
|
learn(v, 6);
|
|
88
91
|
}
|
|
89
92
|
catch { /* no env access */ }
|
|
@@ -110,6 +113,20 @@ function makeMasker(extraKeys = [], opts = {}) {
|
|
|
110
113
|
// expect(token, 'token should match').toBe('x') -> Expected: "x" / Received: "tok_9f8e..."
|
|
111
114
|
const MENTIONS_SECRET = new RegExp(`\\b(?:${SPOKEN_KEYS.join('|')})s?\\b`, 'i');
|
|
112
115
|
const COMPARED = /\b(Expected|Received|Actual|expected|received|actual|got)(\s*[:=]\s*)(["'\u201c]?)([^"'\u201d\s]+)/g;
|
|
116
|
+
// In source code (error snippets) a key is followed by code, not by its value: `const token = await login()`,
|
|
117
|
+
// `password: user.password`, `apiKey = process.env.API_KEY`, `authorization: \`Bearer ${token}\``. Masking these
|
|
118
|
+
// would also teach the masker "await" and blank every `await` in the report.
|
|
119
|
+
const CODE_WORDS = new Set(['await', 'async', 'new', 'this', 'self', 'null', 'undefined', 'none', 'nil', 'true', 'false', 'function', 'return', 'typeof', 'require', 'import', 'yield', 'const', 'let', 'var',
|
|
120
|
+
// type names: `password: string`, `token: str`, `pin: int`
|
|
121
|
+
'string', 'number', 'boolean', 'bigint', 'any', 'unknown', 'object', 'void', 'never', 'symbol', 'str', 'int', 'float', 'bool', 'bytes', 'dict', 'list']);
|
|
122
|
+
const isCodeRef = (raw) => {
|
|
123
|
+
const v = raw.replace(/[)\]},;:.]+$/, '');
|
|
124
|
+
return CODE_WORDS.has(v.toLowerCase())
|
|
125
|
+
|| /^`?\$\{/.test(v)
|
|
126
|
+
|| /^\{\w+\}$/.test(v) // a Cucumber expression parameter: password {string}
|
|
127
|
+
|| /^`?(Bearer|Basic|Digest|Token)$/i.test(v)
|
|
128
|
+
|| /^(process\.env|import\.meta\.env|os\.environ|os\.getenv|System\.getenv|ENV)\b/.test(v);
|
|
129
|
+
};
|
|
113
130
|
const maskStr = (input) => {
|
|
114
131
|
let s = input;
|
|
115
132
|
s = s.replace(CARD_NUMBER, m => luhn(m) ? '****' : m);
|
|
@@ -126,10 +143,15 @@ function makeMasker(extraKeys = [], opts = {}) {
|
|
|
126
143
|
s = s.replace(URL_USERINFO, (_m, a, value, b) => { learn(value); return `${a}****${b}`; });
|
|
127
144
|
s = s.replace(CLI_USER, (_m, a, value) => { learn(value); return `${a}****`; });
|
|
128
145
|
s = s.replace(CREDS_PAIR, (_m, a, b, value) => { learn(value); return `${a}${b}****`; });
|
|
129
|
-
s = s.replace(KV, (
|
|
146
|
+
s = s.replace(KV, (m, q1, key, q2, sep, q3, value) => {
|
|
147
|
+
if (isCodeRef(value))
|
|
148
|
+
return m; // `token = await login()`: code, not a secret (and never learn "await")
|
|
149
|
+
learn(value);
|
|
150
|
+
return `${q1}${key}${q2}${sep}${q3}****`;
|
|
151
|
+
});
|
|
130
152
|
s = s.replace(SPOKEN, (m, key, between, value) => {
|
|
131
153
|
const word = value.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
132
|
-
if (NOT_A_SECRET.has(word) || value.includes('*'))
|
|
154
|
+
if (NOT_A_SECRET.has(word) || value.includes('*') || isCodeRef(value))
|
|
133
155
|
return m;
|
|
134
156
|
const explicit = /\b(is|was|of|as)\b|['"]$|[:=]\s*$/.test(between);
|
|
135
157
|
if (explicit || looksSecret(value)) {
|
|
@@ -140,7 +162,7 @@ function makeMasker(extraKeys = [], opts = {}) {
|
|
|
140
162
|
});
|
|
141
163
|
s = s.replace(VALUE_THEN_KEY, (m, value, rest) => {
|
|
142
164
|
const word = value.toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
143
|
-
if (NOT_A_SECRET.has(word) || value.includes('*') || !looksSecret(value))
|
|
165
|
+
if (NOT_A_SECRET.has(word) || value.includes('*') || isCodeRef(value) || !looksSecret(value))
|
|
144
166
|
return m;
|
|
145
167
|
learn(value);
|
|
146
168
|
return `****${rest}`;
|
package/dist/reporter.d.ts
CHANGED
|
@@ -50,6 +50,7 @@ export default class ReportingLabsReporter implements Reporter {
|
|
|
50
50
|
private extractMeta;
|
|
51
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. */
|
|
52
52
|
private resolveLogo;
|
|
53
|
+
private bddRoots;
|
|
53
54
|
private rel;
|
|
54
55
|
private serializeError;
|
|
55
56
|
private outcome;
|
package/dist/reporter.js
CHANGED
|
@@ -45,12 +45,32 @@ const template_1 = require("./template");
|
|
|
45
45
|
const mask_1 = require("./mask");
|
|
46
46
|
const explain_1 = require("./explain");
|
|
47
47
|
const pdf_1 = require("./pdf");
|
|
48
|
+
const bdd_1 = require("./bdd");
|
|
48
49
|
const comments_1 = require("./comments");
|
|
49
50
|
const DEFAULT_EMBED_LIMIT = 2 * 1024 * 1024;
|
|
50
51
|
/** Attach steps created by log() and the automatic API capture; the data shows in its own section, so hide the step. */
|
|
51
52
|
function isInternalAttach(s) {
|
|
52
53
|
return s.category === 'test.attach' && /^Attach "(rl:log|(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS) )/.test(s.title);
|
|
53
54
|
}
|
|
55
|
+
/** Playwright 1.63+ moved the target out of the title: title `Click`, subtitle `getByRole('button')`; title `Navigate`,
|
|
56
|
+
* subtitle `/login`. Put it back next to the title, as the report showed before. A test.step's own subtitle and
|
|
57
|
+
* params are shown too: `Open product · SKU 42 (id: 42, currency: USD)`. Older Playwright has no subtitle: unchanged. */
|
|
58
|
+
function stepTitle(s) {
|
|
59
|
+
const x = s;
|
|
60
|
+
let title = s.title;
|
|
61
|
+
const sub = typeof x.subtitle === 'string' ? x.subtitle.trim() : '';
|
|
62
|
+
if (s.category === 'test.step') {
|
|
63
|
+
if (sub)
|
|
64
|
+
title += ` · ${sub}`;
|
|
65
|
+
const p = x.params && typeof x.params === 'object' ? Object.entries(x.params) : [];
|
|
66
|
+
if (p.length)
|
|
67
|
+
title += ` (${p.map(([k, v]) => `${k}: ${typeof v === 'string' ? v : JSON.stringify(v)}`).join(', ')})`;
|
|
68
|
+
}
|
|
69
|
+
else if (sub && !title.includes(sub)) {
|
|
70
|
+
title += ` ${sub}`;
|
|
71
|
+
}
|
|
72
|
+
return title;
|
|
73
|
+
}
|
|
54
74
|
/** Meta keys shown on every test and turned into links, without being breakdown dimensions. */
|
|
55
75
|
const META_KEYS = ['priority', 'severity', 'feature', 'owner', 'epic', 'story', 'issue', 'bug', 'component', 'module', 'team', 'sprint', 'testcase', 'tms', 'requirement'];
|
|
56
76
|
class ReportingLabsReporter {
|
|
@@ -140,7 +160,7 @@ class ReportingLabsReporter {
|
|
|
140
160
|
const annotations = [...test.annotations, ...resultAnn.filter(a => !test.annotations.some(b => b.type === a.type && b.description === a.description))];
|
|
141
161
|
const fromComments = this.commentMeta(test);
|
|
142
162
|
const extracted = this.extractMeta(test, fromComments);
|
|
143
|
-
|
|
163
|
+
const t = {
|
|
144
164
|
id: test.id,
|
|
145
165
|
key: `${project}::${file}::${[...titlePath, test.title].join(' › ')}${test.repeatEachIndex ? ' #' + (test.repeatEachIndex + 1) : ''}`,
|
|
146
166
|
title: test.title,
|
|
@@ -161,7 +181,12 @@ class ReportingLabsReporter {
|
|
|
161
181
|
retries: test.retries,
|
|
162
182
|
duration: results.reduce((a, r) => a + r.duration, 0),
|
|
163
183
|
results,
|
|
164
|
-
}
|
|
184
|
+
};
|
|
185
|
+
// playwright-bdd: the scenario at its .feature file and line, Gherkin details from the generated spec
|
|
186
|
+
if ((0, bdd_1.applyBdd)(t, test.location.file, this.bddRoots(), f => this.rel(f), this.masker)) {
|
|
187
|
+
t.key = `${project}::${t.file}::${[...t.path, t.title].join(' › ')}${test.repeatEachIndex ? ' #' + (test.repeatEachIndex + 1) : ''}`;
|
|
188
|
+
}
|
|
189
|
+
tests.push(t);
|
|
165
190
|
}
|
|
166
191
|
const stats = { passed: 0, failed: 0, skipped: 0, flaky: 0, timedOut: 0, interrupted: 0, total: tests.length };
|
|
167
192
|
for (const t of tests)
|
|
@@ -198,7 +223,7 @@ class ReportingLabsReporter {
|
|
|
198
223
|
history,
|
|
199
224
|
bdd,
|
|
200
225
|
rootDir: base,
|
|
201
|
-
env: this.collectEnv(base),
|
|
226
|
+
env: this.collectEnv(base, projects),
|
|
202
227
|
runStatus: result.status,
|
|
203
228
|
globalErrors: this.globalErrors,
|
|
204
229
|
globalOutput: this.globalOutput,
|
|
@@ -332,7 +357,7 @@ class ReportingLabsReporter {
|
|
|
332
357
|
await Promise.all([...paths].map(wait));
|
|
333
358
|
}
|
|
334
359
|
/** Runtime facts for the Environment card: Playwright, Node, OS, browsers, CI job, git commit. */
|
|
335
|
-
collectEnv(base) {
|
|
360
|
+
collectEnv(base, ran = new Set()) {
|
|
336
361
|
const rows = [];
|
|
337
362
|
const env = process.env;
|
|
338
363
|
let pw = '';
|
|
@@ -344,7 +369,9 @@ class ReportingLabsReporter {
|
|
|
344
369
|
rows.push({ k: 'Playwright', v: pw });
|
|
345
370
|
rows.push({ k: 'Node', v: process.version });
|
|
346
371
|
rows.push({ k: 'OS', v: `${os.type()} ${os.release()} (${os.arch()})` });
|
|
347
|
-
|
|
372
|
+
// the projects that ran: not one left out by --project or by `default: false` (Playwright 1.64)
|
|
373
|
+
const ranProjects = this.config.projects.filter(p => !ran.size || ran.has(p.name));
|
|
374
|
+
const browsers = [...new Set(ranProjects.map(p => { const u = p.use ?? {}; return [u.browserName, u.channel].filter(Boolean).join('/') || (u.defaultBrowserType ?? ''); }).filter(Boolean))];
|
|
348
375
|
if (browsers.length)
|
|
349
376
|
rows.push({ k: 'Browsers', v: browsers.join(', ') });
|
|
350
377
|
if (this.config.shard)
|
|
@@ -510,6 +537,9 @@ class ReportingLabsReporter {
|
|
|
510
537
|
}
|
|
511
538
|
return `data:${type};base64,${fs.readFileSync(file).toString('base64')}`;
|
|
512
539
|
}
|
|
540
|
+
bddRoots() {
|
|
541
|
+
return [...new Set([this.config.configFile ? path.dirname(this.config.configFile) : '', this.config.rootDir, process.cwd()].filter(Boolean))];
|
|
542
|
+
}
|
|
513
543
|
rel(file) {
|
|
514
544
|
const base = this.config.configFile ? path.dirname(this.config.configFile) : this.config.rootDir;
|
|
515
545
|
return path.relative(base, file).split(path.sep).join('/');
|
|
@@ -617,7 +647,7 @@ class ReportingLabsReporter {
|
|
|
617
647
|
}
|
|
618
648
|
serializeStep(s) {
|
|
619
649
|
return {
|
|
620
|
-
title: this.masker.maskStr(s
|
|
650
|
+
title: this.masker.maskStr(stepTitle(s)),
|
|
621
651
|
category: s.category,
|
|
622
652
|
duration: s.duration,
|
|
623
653
|
error: s.error?.message ? this.masker.maskStr(stripAnsi(s.error.message)) : undefined,
|
|
@@ -753,7 +783,7 @@ function gitInfo(cwd, env) {
|
|
|
753
783
|
return out;
|
|
754
784
|
}
|
|
755
785
|
function extFor(ct) {
|
|
756
|
-
const m = { 'image/png': '.png', 'image/jpeg': '.jpg', 'video/webm': '.webm', 'video/mp4': '.mp4', 'application/zip': '.zip', 'application/pdf': '.pdf' };
|
|
786
|
+
const m = { 'image/png': '.png', 'image/jpeg': '.jpg', 'image/webp': '.webp', 'image/gif': '.gif', 'video/webm': '.webm', 'video/mp4': '.mp4', 'application/zip': '.zip', 'application/pdf': '.pdf' };
|
|
757
787
|
return m[ct] ?? '';
|
|
758
788
|
}
|
|
759
789
|
function fmt(v) {
|
package/dist/template.html
CHANGED
|
@@ -1712,7 +1712,7 @@ function select(id, quiet){
|
|
|
1712
1712
|
function renderDetail(t, d, retryIdx){
|
|
1713
1713
|
d=d||$('#detail'); d.innerHTML='';
|
|
1714
1714
|
const retry = retryIdx==null ? state.retry : retryIdx;
|
|
1715
|
-
d.append(h('div',{class:'crumb'}, [t.file, ...t.path.map(p=>data.bdd&&!/^Feature:/i.test(p)?'Feature: '+p:p)].map(p=>h('span',{},p))),
|
|
1715
|
+
d.append(h('div',{class:'crumb'}, [t.file, ...t.path.map(p=>data.bdd&&!/^(Feature|Rule):/i.test(p)?'Feature: '+p:p)].map(p=>h('span',{},p))),
|
|
1716
1716
|
h('div',{class:'titlebar'}, h('h3',{},t.title), h('div',{class:'actions'},
|
|
1717
1717
|
h('button',{class:'btn',onclick:e=>copyText(location.href.split('#')[0]+'#t='+t.id,e.currentTarget,'Link copied')},'Copy link'),
|
|
1718
1718
|
(()=>{ const r=t.results[t.results.length-1]; const e=r&&r.errors[0]; return e? [h('button',{class:'btn',onclick:ev=>copyText(t.title+'\n'+t.file+':'+t.line+'\n\n'+e.message,ev.currentTarget,'Error copied')},'Copy error'), h('button',{class:'btn primary',onclick:()=>openBugReport(t)},'Bug report')] : null; })(),
|
package/dist/template.js
CHANGED
|
@@ -1778,7 +1778,7 @@ function select(id, quiet){
|
|
|
1778
1778
|
function renderDetail(t, d, retryIdx){
|
|
1779
1779
|
d=d||$('#detail'); d.innerHTML='';
|
|
1780
1780
|
const retry = retryIdx==null ? state.retry : retryIdx;
|
|
1781
|
-
d.append(h('div',{class:'crumb'}, [t.file, ...t.path.map(p=>data.bdd&&!/^Feature:/i.test(p)?'Feature: '+p:p)].map(p=>h('span',{},p))),
|
|
1781
|
+
d.append(h('div',{class:'crumb'}, [t.file, ...t.path.map(p=>data.bdd&&!/^(Feature|Rule):/i.test(p)?'Feature: '+p:p)].map(p=>h('span',{},p))),
|
|
1782
1782
|
h('div',{class:'titlebar'}, h('h3',{},t.title), h('div',{class:'actions'},
|
|
1783
1783
|
h('button',{class:'btn',onclick:e=>copyText(location.href.split('#')[0]+'#t='+t.id,e.currentTarget,'Link copied')},'Copy link'),
|
|
1784
1784
|
(()=>{ const r=t.results[t.results.length-1]; const e=r&&r.errors[0]; return e? [h('button',{class:'btn',onclick:ev=>copyText(t.title+'\n'+t.file+':'+t.line+'\n\n'+e.message,ev.currentTarget,'Error copied')},'Copy error'), h('button',{class:'btn primary',onclick:()=>openBugReport(t)},'Bug report')] : null; })(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "reporting-labs",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.20",
|
|
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",
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
"playwright",
|
|
13
13
|
"cypress",
|
|
14
14
|
"webdriverio",
|
|
15
|
+
"cucumber",
|
|
16
|
+
"bdd",
|
|
15
17
|
"dashboard"
|
|
16
18
|
],
|
|
17
19
|
"author": "Naveen Khunteta <naveen@naveenautomationlabs.com>",
|